下面是程序.请大家帮忙看看,不知道什么原因,我让LCD显示两行字符,结果只能显示1行,请大家帮忙看看!查查原因
unchar code Lcd_abc[]=("ABCDSFGHJKLWQTU I LIVK EEPW MCU51-DIY ");
unchar code Lcd_123[]=("123456789ABCDEF WWW.EEPW.COM.CN ");
void delay(unint z)
{
unint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--)
{}
}
void main()
{
Lcd_init();
while(1);
}
void Lcd_init()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
delay(100);
Lcd_disp(1,0);
for(nmb=0;nmb<40;nmb++)
{
write_date(Lcd_abc[nmb]);
delay(20);
}
//Lcd_disp(2,1);
write_com(0x80+0X40);
for(nmb=0;nmb<35;nmb++)
{
write_date(Lcd_123[nmb]);
delay(50);
}
}
//向1602液晶写命令
void write_com(unchar com)
{
RS=0;
RW=0;
EN=0;
LCD=com;
EN=1;
EN=0;
delay(2);
}
//向1602液晶写数据
void write_date(unchar date)
{
RS = 1;
RW=0;
EN = 0;
LCD=date;
EN = 1;
EN = 0;
delay(2);
}
void Lcd_disp(unchar x,y)
{
unchar addr;
if(x==1)
addr=0x80+y;
else
addr=0xC0+y;
write_com(addr);
//write_date(date);
视频地址:http://player.56.com/v_65261111.swf
#define unchar unsigned char
#define unint unsigned int
unchar code tabol[]={"0123456789"};
unchar nn;
unchar miao,miaodi,miaogao,fen,fendi,fengao,shi,shidi,shigao,ri,ridi,rigao,yue,yuedi,yuegao,xiqi,xiqidi,nian,niandi,niangao;
sbit IO=P3^4;
sbit CLK=P3^6;
sbit RST=P3^5;
sbit RS=P2^4;
sbit EN=P2^6;
sbit RW=P2^5;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
void init_lcd();
void write_date(unchar date);
void write_hang(unchar aa,bb);
void init_1302();
void delay(unint z);
void input1(unchar add)
{
unchar i;
ACC=add;
for(i=8;i>0;i--)
{
IO=ACC0;
CLK=1;
CLK=0;
ACC=ACC>>1;
}
}
unchar out1byte(void)
{
unchar i;
for(i=8;i>0;i--)
{
ACC=ACC>>1;
ACC7=IO;
CLK=1;
CLK=0;
}
return(ACC);
}
void wrrte1302(unchar add,date)
{
RST=0;
CLK=0;
RST=1;
input1(add);
input1(date);
RST=0;
}
char read_1302(unchar add)
{
unchar i;
RST=0;
CLK=0;
RST=1;
input1(add);
i=out1byte();
RST=0;
return(i);
}
void init_1302()
{
wrrte1302(0x8e,0x00); //11.06.12.10.16:41:35
//wrrte1302(0x90,0xaa);
wrrte1302(0x80,0x52);//miao
wrrte1302(0x82,0x41);//fen
wrrte1302(0x84,0x23);//shi
wrrte1302(0x86,0x11);//ri
wrrte1302(0x88,0x12);//yue
wrrte1302(0x8a,0x07);//xinqi
wrrte1302(0x8c,0x11);//nian
wrrte1302(0x8e,0x80);//baohu
}
void main()
{
init_lcd();
init_1302();
while(1)
{
miao=read_1302(0x81);
miaodi=miao&0x0f;
miaogao=miao>>4;
//delay(10);
fen=read_1302(0x83);
fendi=fen&0x0f;
fengao=fen>>4;
shi=read_1302(0x85);
shidi=shi&0x0f;
shigao=shi>>4;
//delay(10);
ri=read_1302(0x87);
ridi=ri&0x0f;
rigao=ri>>4;
yue=read_1302(0x89);
yuedi=yue&0x0f;
yuegao=yue>>4;
//delay(10);
xiqi=read_1302(0x8b);
xiqidi=xiqi&0x07;
nian=read_1302(0x8d);
niandi=nian&0x0f;
niangao=nian>>4;
//delay(10);
write_hang(1,8);
write_date(tabol[niandi]);
write_hang(1,7);
write_date(tabol[niangao]);
write_hang(1,9);
write_date('-');
//delay(20);
write_hang(1,11);
write_date(tabol[yuedi]);
write_hang(1,10);
write_date(tabol[yuegao]);
write_hang(1,12);
write_date('-');
write_hang(1,14);
write_date(tabol[ridi]);
write_hang(1,13);
write_date(tabol[rigao]);
write_hang(1,15);
write_date('-');
//delay(20);
write_hang(1,17);
write_date(tabol[shidi]);
write_hang(1,16);
write_date(tabol[shigao]);
write_hang(1,18);
write_date(':');
write_hang(1,20);
write_date(tabol[fendi]);
write_hang(1,19);
write_date(tabol[fengao]);
write_hang(1,21);
write_date(':');
//delay(20);
write_hang(1,23);
write_date(tabol[miaodi]);
write_hang(1,22);
write_date(tabol[miaogao]);
write_hang(1,24);
write_date('-');
write_hang(1,25);
write_date(tabol[xiqidi]);
//delay(20);
}
}
void delay(unint z)
{
unint x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void write_lcd(unchar add)
{
RS=0;
RW=0;
EN=0;
P0=add;
EN=1;
delay(2);
EN=0;
delay(2);
}
void write_date(unchar date)
{
RS=1;
RW=0;
EN=0;
P0=date;
EN=1;
delay(2);
EN=0;
delay(2);
}
void init_lcd()
{
write_lcd(0x38);
write_lcd(0x06);
write_lcd(0x0c);
write_lcd(0x01);
}
void write_hang(unchar aa,bb)
{
unchar u;
if(aa==1)
u=0x80+bb;
else
u=0xc0+bb;
write_lcd(u);
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |