自己最近小搞了下单片机,现在仍是菜鸟,以下是单片机程序,基本功能都可以完成,但程序有点小问题(反响不灵敏),还请高手点拨下,感激不尽哦!!!
#include#define uchar unsigned char#define uint unsigned intuchar code table[]=" 2011-3-11 ";uchar code table1[]=" 14:59:55 ";uchar count, hour, minute, second, press;sbit rs=P2^4;sbit rw=P2^5;sbit en=P2^6;sbit key1=P3^0;sbit key2=P3^1;sbit key3=P3^2;void delay (){ ; ;}void write_cmd(uchar cmd) //1602写指令{rs=0;delay();rw=0;delay();en=0;delay();P0=cmd;en=1;delay();en=0;delay();}void write_byte(uchar date) //1602写数据{rs=1;delay();rw=0;delay();en=0;delay();P0=date;en=1;delay();en=0; } void delay1(uint z){uint x, y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void display(uchar addr, uchar date) //显现在液晶屏上{uchar ge, shi;ge=date%10;shi=date/10;write_cmd(0x80+0x40+addr);write_byte(shi+0x30);write_byte(ge+0x30);}void keyscan() //键盘扫描,key1功能键,key2添加,key3削减{if(key1==0){delay1(5);if(key1==0){while(!key1);press++;if(press==1){TR0=0;write_cmd(0x80+0x40+0x09);write_cmd(0x0f);}if(press==2){write_cmd(0x80+0x40+0x06);write_cmd(0x0f);}if(press==3){write_cmd(0x80+0x40+0x03);write_cmd(0x0f);}if(press==4){press=0;write_cmd(0x0c);TR0=1;}}}if(key2==0){delay1(5);if(key2==0){while(!key2);if(press==1){second++;if(second==60){second=0;}display(8,second);}if(press==2){minute++;if(minute==60){minute=0;}display(5,minute);}if(press==3){hour++;if(hour==24){hour=0;}display(2,hour);}}}if(key3==0){delay1(5);if(key3==0){while(!key3);if(press==1){second--;if(second==-1){second=59;}display(8,second);}if(press==2){minute--;if(minute==-1){minute=59;}display(5,minute);}if(press==3){hour--;if(hour==0){hour=23;}display(2,hour);}}}}