预计功能是 :开电源后,LCD显示时间 并开始走动 (初始显示 2012-05-01 TUE 00:00:00),
按键对显示控制,按下按键后LCD切换显示 ,再次按下按键恢复初始显示
用keil51编译没错误,但没实验板,也不会用protue仿真 所以请高手帮忙看看能不能行 - #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit RS=P3^1;
- sbit EN=P3^0; //RW接地
- sbit KEY=P3^3;
- uchar h,m,s,count,t;
- uchar code table[]=" 2012-05-01 TUE";
- uchar code table1[]=" 00:00:00";
- uchar code table2[]=" ZHOU DENG";
- uchar code table3[]=" 20091131173";
- //延时;
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- //LCD写指令;
- void write_com(uchar com)
- {
- RS=0;
- EN=0;
- P1=com;
- delay(5);
- EN=1;
- delay(5);
- EN=0;
- }
- //LCD写数据;
- void write_date(uchar date)
- {
- RS=1;
- EN=0;
- P1=date;
- delay(5);
- EN=1;
- delay(5);
- EN=0;
- }
- //时分秒走动;
- void write_sfm(uchar add,uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- write_com(0x80+0x40+add); //第二行时间位置
- write_date(0x30+shi);
- write_date(0x30+ge);
- }
- // 按键检测
- uchar keyscan()
- {
- if(KEY==0)
- {
- delay(5);
- if(KEY==0)
- return 0;
- else
- return 1;
- }
- else
- return 1;
- }
- // 切换内容
- void xianshi()
- {
- uchar a;
- write_com(0x01);//清屏;
- write_com(0x80);
- for(a=0;a<12;a++)
- {
- write_date(table2[a]);
- delay(5);
- }
- write_com(0x80+0x40);
- for(a=0;a<14;a++)
- {
- write_date(table3[a]);
- delay(5);
- }
- while(keyscan()) ; //保持显示
- }
-
- //LCD初始化;
- void init()
- {
- uchar b;
- write_com(0x38);
- delay(5);
- write_com(0x0c);
- delay(5);
- write_com(0x06);
- delay(5);
- write_com(0x01);
- delay(5);
- write_com(0x80);
- for(b=0;b<16;b++)
- {
- write_date(table[b]);
- delay(5);
- }
- write_com(0x80+0x40);
- for(b=0;b<12;b++)
- {
- write_date(table1[b]);
- delay(5);
- }
- }
- //主函数;
- void main()
- {
- while(1)
- {
- init();
- count=0;
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- if(count==20)
- {
- count=0;
- s++;
- if(s==60)
- {
- s=0;
- m++;
- if(m==60)
- {
- m=0;
- h++;
- if(h==24)
- {
- h=0;
- }
- write_sfm(4,h);
- }
- write_sfm(7,m);
- }
- write_sfm(10,m);
- }
- if(keyscan()==0)
- break;
- }
- xianshi();
- }
- }
- //中断;
- void timer0() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- count++;
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
呵呵,好的,互相交流学习
一周热门 更多>