#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS = P2^6;
sbit LCD_RW = P2^5;
sbit LCD_EN = P2^7;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=com;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN=1;
_nop_();
_nop_();
_nop_();
_nop_();
LCD_EN=0;
}
void write_data(uchar date)
{
LCD_RS=1;
P0=date;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void init()
{
//delay(15); //等待LCD电源稳定
write_com(0x38); //16*2显示,5*7点阵,8位数据
delay(5);
write_com(0x0f);
delay(5);
write_com(0x06);
delay(5);
write_com(0x01);
delay(5);
write_com(0x80);
delay(5);
}
void main()
{
init();
write_data('1');
while(1);
}
我也是老遇到这种问题,照着 书上的编程,可是就是显示不出来,端口定义对了的,下载原带来的程序就又可以显示,蛋疼啊·····
回复 板凳 茹zhiwei 的帖子
你仔细查查 我的问题已经得到了解决 LCD_RS=0在write_com()里面
回复 4楼 hanjiangxue1991 的帖子
#include
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P2^5;
sbit lcdrs=P1^0;
sbit wr=P1^1;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[10]="I LOVE RU!";
void delay(uchar m)
{
uint i,j;
for(i=m;i>0;i--)
for(j=0;j=20;j--);
}
void write_com(uchar com)
{
P0=com;
lcdrs=0;
lcden=0;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
P0=date;
lcdrs=1;
lcden=0;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
wr=0;
dula=0;
wela=0;
write_com(0x38);
delay(5);
write_com(0x0f);
delay(5);
write_com(0x06);
delay(5);
write_com(0x01);
delay(5);
}
void main()
{
uchar i;
init();
write_com(0x80);
for(i=0;i<10;i++)
{
write_data(table);
delay(5);
}
while(1);
}