单片机lcd12864(hdg12864l-6) proteus的仿真程序 不知道错在哪里啊
请大侠帮忙测试一下啊#include<reg51.h>sbitLCD_PS=P1^0;sbitC86=P1^1;sbitLCD_RD=P1^2;sbitLCD_WR=P1...
请大侠帮忙测试一下啊
#include <reg51.h>
sbit LCD_PS=P1^0;sbit C86=P1^1;
sbit LCD_RD=P1^2;
sbit LCD_WR=P1^3;
sbit A0=P1^4;
sbit CS=P1^5;
const unsigned char code dis_lcd[]={字模省略了
};
延时这里也只能省略了 字符限制了
void lcd_write_data(unsigned char dat)
{
A0=1;
LCD_WR=0;
LCD_RD=1;
CS=0;
P2=dat;
LCD_WR=1;
}
void lcd_write_cmd(unsigned char command)
{
A0=0;
LCD_RD=1;
LCD_WR=0;
CS=0;
P2=command;
LCD_WR=1;
}
unsigned char lcd_read_cmd(void)
{
unsigned char dat;
A0=0;
LCD_WR=1;
LCD_RD=0;
CS=0;
dat=P2;
dat=dat&0x80;
LCD_RD=1;
return dat;
}
void clr_screen(void)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xb0|i);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0x00);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0x10);
for(j=0;j<128;j++)
{
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_data(0x00);
}
}
}void lcd_hang(unsigned char addr)
{
unsigned char tmp;
tmp=addr&0x3f;
tmp=tmp|0x40;
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(tmp);
}
void lcd_page(unsigned char addr)
{
unsigned char tmp;
tmp=addr&0x07;
tmp=tmp|0xb0;
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(tmp);
}
void lcd_lie(unsigned char addr)
{
unsigned char htmp,ltmp;
addr=addr&0x7f;
htmp=addr&0xf0;
htmp=htmp>>4;
ltmp=addr&0x0f;
htmp=htmp|0x10;
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(ltmp);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(htmp);
}
void init_lcd(void)
{
P2=0x00; while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xe2);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xaf);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa0);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa6);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa4);
lcd_page(0x00); lcd_lie(0x00);
lcd_hang(0x00);
}
void dis_pic(unsigned char page,unsigned char lie)
{
unsigned char i,j;
unsigned int temp=0;
for(i=0;i<8;i++)
{
lcd_page(page+i);
lcd_lie(lie);
for(j=0;i<128;i++)
{
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_data(dis_lcd[temp]);
temp++;
}
}
}
void main(void)
{
LCD_PS=1;
C86=0;
CS=0;
init_lcd();
while(1)
{
clr_screen();
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa6);
while((lcd_read_cmd()&&0x80)!=0);
dis_pic(0x00,0x00);
delay_ms(3000);
while((lcd_read_cmd()&&0x80)!=0);
clr_screen();
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa7);
while((lcd_read_cmd()&&0x80)!=0);
dis_pic(0x00,0x00);
}
} 展开
#include <reg51.h>
sbit LCD_PS=P1^0;sbit C86=P1^1;
sbit LCD_RD=P1^2;
sbit LCD_WR=P1^3;
sbit A0=P1^4;
sbit CS=P1^5;
const unsigned char code dis_lcd[]={字模省略了
};
延时这里也只能省略了 字符限制了
void lcd_write_data(unsigned char dat)
{
A0=1;
LCD_WR=0;
LCD_RD=1;
CS=0;
P2=dat;
LCD_WR=1;
}
void lcd_write_cmd(unsigned char command)
{
A0=0;
LCD_RD=1;
LCD_WR=0;
CS=0;
P2=command;
LCD_WR=1;
}
unsigned char lcd_read_cmd(void)
{
unsigned char dat;
A0=0;
LCD_WR=1;
LCD_RD=0;
CS=0;
dat=P2;
dat=dat&0x80;
LCD_RD=1;
return dat;
}
void clr_screen(void)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xb0|i);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0x00);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0x10);
for(j=0;j<128;j++)
{
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_data(0x00);
}
}
}void lcd_hang(unsigned char addr)
{
unsigned char tmp;
tmp=addr&0x3f;
tmp=tmp|0x40;
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(tmp);
}
void lcd_page(unsigned char addr)
{
unsigned char tmp;
tmp=addr&0x07;
tmp=tmp|0xb0;
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(tmp);
}
void lcd_lie(unsigned char addr)
{
unsigned char htmp,ltmp;
addr=addr&0x7f;
htmp=addr&0xf0;
htmp=htmp>>4;
ltmp=addr&0x0f;
htmp=htmp|0x10;
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(ltmp);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(htmp);
}
void init_lcd(void)
{
P2=0x00; while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xe2);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xaf);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa0);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa6);
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa4);
lcd_page(0x00); lcd_lie(0x00);
lcd_hang(0x00);
}
void dis_pic(unsigned char page,unsigned char lie)
{
unsigned char i,j;
unsigned int temp=0;
for(i=0;i<8;i++)
{
lcd_page(page+i);
lcd_lie(lie);
for(j=0;i<128;i++)
{
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_data(dis_lcd[temp]);
temp++;
}
}
}
void main(void)
{
LCD_PS=1;
C86=0;
CS=0;
init_lcd();
while(1)
{
clr_screen();
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa6);
while((lcd_read_cmd()&&0x80)!=0);
dis_pic(0x00,0x00);
delay_ms(3000);
while((lcd_read_cmd()&&0x80)!=0);
clr_screen();
while((lcd_read_cmd()&&0x80)!=0);
lcd_write_cmd(0xa7);
while((lcd_read_cmd()&&0x80)!=0);
dis_pic(0x00,0x00);
}
} 展开
展开全部
不知道,你现在的问题是什么,如果是无法正常读取忙信号,建议
1在lcd_read_cmd()中的dat=P2前加入P2=0xff
2将判断忙(lcd_read_cmd()&&0x80)!=0改成lcd_read_cmd==0
1在lcd_read_cmd()中的dat=P2前加入P2=0xff
2将判断忙(lcd_read_cmd()&&0x80)!=0改成lcd_read_cmd==0
追问
忙信号 好像没什么问题吧 因为书上写的程序 是说LCD-12864的速度比单片机快 所以可以利用时间上的差距 不用读忙信号 但是我把忙信号 注释掉了 和书上的代码差不多 也不能正常显示 但是 如果忙信号注释掉 而且 不管写字节还是读字节的时候都把 WR和RD 都拉低 完事再都拉高 就能显示一小部分图片 不知道是为什么 正常些的时候RD应该拉高才对啊 但是书上是 每次写和读字节的时候都拉低的 不知道为什么啊
追答
具体的控制要看LCD厂家的手册,不同厂家的可能会有点区别的。但是理论上LCD的处理速度应该比单片机慢,如果不读忙信号的话,应该在每次写入后延时几毫秒才对。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询