在用LCD12864的串行控制,程序如下:
//写指令
void LCD12864_write_com(unsigned char com)
{
unsigned char dattemp,i;
LCD12864_cs = 1;
dattemp = 0xf8;
for (i = 0; i < 8; i++)
{
dattemp <<= 1;
LCD12864_sclk = 0;
delay9us(1);
LCD12864_sid = CY;
delay9us(1);
LCD12864_sclk = 1;
}
dattemp = com & 0xf0;
for (i = 0; i < 8; i++)
{
dattemp <<= 1;
LCD12864_sclk = 0;
delay9us(1);
LCD12864_sid = CY;
delay9us(1);
LCD12864_sclk = 1;
}
dattemp = (com << 4) & 0xf0;
for (i = 0; i < 8; i++)
{
dattemp <<= 1;
LCD12864_sclk = 0;
delay9us(1);
LCD12864_sid = CY;
delay9us(1);
LCD12864_sclk = 1;
}
LCD12864_sclk = 0;
LCD12864_sid = 1;
LCD12864_cs = 0;
}
//写数据
void LCD12864_write_dat(unsigned char dat)
{
unsigned char dattemp,i;
LCD12864_cs = 1;
dattemp = 0xfa;
for (i = 0; i < 8; i++)
{
dattemp <<= 1;
LCD12864_sclk = 0;
delay9us(1);
LCD12864_sid = CY;
delay9us(1);
LCD12864_sclk = 1;
}
dattemp = dat & 0xf0;
for (i = 0; i < 8; i++)
{
dattemp <<= 1;
LCD12864_sclk = 0;
delay9us(1);
LCD12864_sid = CY;
delay9us(1);
LCD12864_sclk = 1;
}
dattemp = (dat << 4) & 0xf0;
for (i = 0; i < 8; i++)
{
dattemp <<= 1;
LCD12864_sclk = 0;
delay9us(1);
LCD12864_sid = CY;
delay9us(1);
LCD12864_sclk = 1;
}
LCD12864_sclk = 0;
LCD12864_sid = 1;
LCD12864_cs = 0;
}
主函数如下:
void main()
{
LCD12864_init();
LCD12864_write_com(0x80);
LCD12864_write_dat('0');
LCD12864_write_dat('1');
while(1);
}
这样写就不会显示01,但如果把写指令函数中的LCD12864_cs = 0;删掉,就只会显示一个0,如果再把写数据函数中的LCD12864_cs = 0;删掉就能显示01了。这样感觉就是LCD12864_write_com(0x80);中的LCD12864_cs = 0;是的后面的显示数据都失效了,而LCD12864_write_dat('0');中的LCD12864_cs = 0;也会让后面的LCD12864_write_dat('1');失效。但我两个函数一开始就又把LCD12864_cs置一了。实在想不通为什么。后面我又试了,把那三句顺序改变,改为
LCD12864_cs = 0;
LCD12864_sclk = 0;
LCD12864_sid = 1;
也可以正常显示。这是CS的时序问题吗,还请各位指点一下。
|