level 2
水果茶捞
楼主
救救孩子吧![[泪]](/static/emoticons/u6cea.png)
![[泪]](/static/emoticons/u6cea.png)
,为啥lcd不亮啊
代码:#include<reg51.h>
unsigned char code table[]="GOOD LUCK";
unsigned char code tablel[]="1234567";
unsigned char num ;
sbit e =P3^2;// input enable
sbit rw =P3^1;// H - read : L - write
sbit rs =P3^0;// H = data : L = command
void delay (unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for (y =110;y>0;y--);
}
void LCD_check_busy()
{
do
{
rs=0;
rw=1;
P1=0xff;
e=1;
delay(1);
e=0;
}
while(P1^7==1);
}
void wr_lcd_comm(char content)
{
LCD_check_busy();
rs=0;
rw=0;
P1=content;
e=1;
delay(1);
e=0;
}
void wr_lcd_dat(char content)
{
LCD_check_busy();
rs=1;
rw=0;
P1=content;
e=1;
delay(1);
e=0;
}
void LocateXY(char posx,char posy)
{
unsigned char temp;
temp=posx & 0xf;
posy & =0x1;
if(posy)temp|=0x40;
temp|=0x80;
wr_lcd_comm(temp);
}
void DispOneChar(char x,char y,char Wdata)
{
LocateXY(x,y);
wr_lcd_dat(Wdata);
}
void init_lcd(void)
{
e=0;
wr_lcd_comm(0x01);
wr_lcd_comm(0x06);
wr_lcd_comm(0x0c);
wr_lcd_comm(0x38);
}
void main()
{
delay(50);//启动时必须延时,等待 LCD 进入工作状态
init_lcd();
while (1)
{
wr_lcd_comm(0x80);//光标位置定在第一行第一列
for(num =0;num<9;num++)
{ wr_lcd_dat(table[num]);
delay(5);
}
wr_lcd_comm(0x80+0x40);//光标位置定在第二行第一列
for(num =0;num<7;num++)
{
wr_lcd_dat(tablel[num]);
delay(5);
}
}
}
图:

2023年05月26日 17点05分
1
代码:#include<reg51.h>
unsigned char code table[]="GOOD LUCK";
unsigned char code tablel[]="1234567";
unsigned char num ;
sbit e =P3^2;// input enable
sbit rw =P3^1;// H - read : L - write
sbit rs =P3^0;// H = data : L = command
void delay (unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for (y =110;y>0;y--);
}
void LCD_check_busy()
{
do
{
rs=0;
rw=1;
P1=0xff;
e=1;
delay(1);
e=0;
}
while(P1^7==1);
}
void wr_lcd_comm(char content)
{
LCD_check_busy();
rs=0;
rw=0;
P1=content;
e=1;
delay(1);
e=0;
}
void wr_lcd_dat(char content)
{
LCD_check_busy();
rs=1;
rw=0;
P1=content;
e=1;
delay(1);
e=0;
}
void LocateXY(char posx,char posy)
{
unsigned char temp;
temp=posx & 0xf;
posy & =0x1;
if(posy)temp|=0x40;
temp|=0x80;
wr_lcd_comm(temp);
}
void DispOneChar(char x,char y,char Wdata)
{
LocateXY(x,y);
wr_lcd_dat(Wdata);
}
void init_lcd(void)
{
e=0;
wr_lcd_comm(0x01);
wr_lcd_comm(0x06);
wr_lcd_comm(0x0c);
wr_lcd_comm(0x38);
}
void main()
{
delay(50);//启动时必须延时,等待 LCD 进入工作状态
init_lcd();
while (1)
{
wr_lcd_comm(0x80);//光标位置定在第一行第一列
for(num =0;num<9;num++)
{ wr_lcd_dat(table[num]);
delay(5);
}
wr_lcd_comm(0x80+0x40);//光标位置定在第二行第一列
for(num =0;num<7;num++)
{
wr_lcd_dat(tablel[num]);
delay(5);
}
}
}
图:

