讓1602lcd顯示一個字母,為什麼顯示的卻是另一個字母
#include
#define uchar unsigned char
#define uint unsigned int
#define GPIO P0
sbit LCDRS=P2^6;
sbit LCDRW=P2^5;
sbit LCDE=P2^7;
uchar num;
uchar a;
uchar table[]="I LOVE YOU";
uchar table1[]="MY NYMPH";
void delay(uint c) // 單位ms 誤差 0us
{
uchar a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}
void write_com(uchar com)
{
LCDRS=0;
LCDRW=0;
GPIO=com;
delay(10);
LCDE=1;
delay(10);
LCDE=0;
}
void write_data(uchar date)
{
LCDRS=1;
LCDRW=0;
delay(1);
GPIO=date;
delay(10);
LCDE=1;
delay(10);
LCDE=0;
}
void init()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
// write_com(0x18); // 左移
write_com(0x01);
}
void main()
{
init();
write_com(0x80);
// for(num=0;num<11;num++)
// {
// write_data(table[num]);
// delay(5);
// }
// write_com(0x80+0x40);
// for(num=0;num<8;num++)
// {
// write_data(table[num]);
// }
a='D';
write_data(a);
// delay(20);
while(1)
{}
}
我之前也遇到過類似的問題,這與1602的初始化等問題有關,建議用開發板的例子程序改寫~