各位大神,帮我看看LCD1602的初始化对不?好郁闷~~弄看好久。加了查忙程序就显示一行黑块,不加就显示2行黑块~~帮帮忙啦!!到底怎么回事啊!!求~~
#define lcd P0
sbit rs=P2^0;sbit rw=P2^1;sbit e=P2^2;
uchar code lcd_addr[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,
0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
};
void delay(uint j)
{
uchar i=120;
for(;j>0;j--)while(i--);
}
void check_busy(void)
{
uchar dt;
do{
rs=0;rw=1;e=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
dt=lcd;
delay(1);
e=0;
}
while(dt&0x80);
}
void write_command(uchar com)
{
check_busy();
rs=0;rw=0,e=0;
_nop_();_nop_();
lcd=com;
_nop_();_nop_();_nop_();_nop_();_nop_();
e=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
e=0;
delay(1);
}
void write_data(uchar dat)
{
check_busy();
rs=1;rw=0;e=0;lcd=dat;
_nop_();_nop_();_nop_();_nop_();_nop_();
e=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
e=0;
delay(1);
}
void LCD_ini
tial()
{
e=0;
rw=0;
write_command(0x38);
//write_command(0x38);
write_command(0x0C);
write_command(0x01);
write_command(0x06);
}
void lcd_disp(uchar addr,uchar *p,uchar len)
{
uchar i;
//uchar a=strlen(p);
for(i=0;i<len;i++)
{
write_command(lcd_addr[addr+i])
write_data(dispplay[i]);
}
}
- #include<reg52.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define lcd P0
- uchar display[] = {" ZhanXiang "};
- sbit rs=P2^6;sbit rw=P2^5;sbit e=P2^7;
- uchar code lcd_addr[]={
- 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
- 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
- 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,
- 0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
- };
- void delay(uint j)
- {
- uchar i=120;
- for(;j>0;j--)while(i--);
- }
- void check_busy(void)
- {
- uchar dt;
- do
- {
- rs=0;rw=1;e=1;
- _nop_();_nop_();_nop_();_nop_();_nop_();
- dt=lcd;
- delay(1);
- e=0;
- }
- while(dt&0x80);
- }
- void write_command(uchar com)
- {
- check_busy();
- rs=0;rw=0,e=0;
- _nop_();_nop_();
- lcd=com;
- _nop_();_nop_();_nop_();_nop_();_nop_();
- e=1;
- _nop_();_nop_();_nop_();_nop_();_nop_();
- e=0;
- delay(1);
- }
- void write_data(uchar dat)
- {
- check_busy();
- rs=1;rw=0;e=0;lcd=dat;
- _nop_();_nop_();_nop_();_nop_();_nop_();
- e=1;
- _nop_();_nop_();_nop_();_nop_();_nop_();
- e=0;
- delay(1);
- }
- void LCD_initial()
- {
- write_command(0x38);
- //write_command(0x38);
- write_command(0x0C);
- write_command(0x01);
- write_command(0x06);
- }
- void lcd_disp(uchar addr,uchar len)
- {
- uchar i;
- //uchar a=strlen(p);
- for(i=0;i<len;i++)
- {
- write_command(lcd_addr[addr+i]);
- write_data(display[i]);
- }
- }
- void main()
- {
- LCD_initial();
-
- while(1)
- {
- lcd_disp(0,16);
- }
- }
复制代码一周热门 更多>