学习单片机半个月了,学得也差不多了,今日写一个写程序操练操练哈哈
跟电子表的功用如出一辙,能够进行设置,准确度十分高哈哈,用的是1602类型的液晶显示器,我们只需要简略的修正一下端口就能使用到你自己的规划上去了.
下面是源代码:
#include#define uchar unsigned char#define uint unsigned int uchar code year_table[]=" 2010-04-11 SUN";uchar code time_table[]=" 00:00:00";uchar time_count,key_count;char hour,minute,second,mouth,day,week;uint year;sbit rs=P3^5;sbit lcden=P3^4;sbit dula=P2^6;sbit wela=P2^7;sbit key_set=P3^0;sbit key_inc=P3^1;sbit key_dec=P3^2;sbit rd=P3^7;void delay(uint delay_time){uint x,y;for(x=delay_time;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com){rs=0;lcden=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void write_date(uchar date){rs=1;lcden=0;P0=date;delay(5);lcden=1;delay(5);lcden=0;}void timer_Init(){TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;}write_time(uchar addr,uchar time){uchar shi,ge;shi=time/10;ge=time%10;write_com(0x80+0x40+addr);write_date(0x30+shi);write_date(0x30+ge);}write_day(uchar addr,uchar day){uchar shi,ge;shi=day/10;ge=day%10;write_com(0x80+addr);write_date(0x30+shi);write_date(0x30+ge);}write_year(uchar addr,uint year){uchar shi,ge,qian,bei;qian=year/1000;bei=year%1000/100;shi=year%100%100/10;ge=year%10;write_com(0x80+addr);write_date(0x30+qian);write_date(0x30+bei);write_date(0x30+shi);write_date(0x30+ge);}write_week(uchar addr,uchar week){write_com(0x80+addr);switch(week){case 1:write_date(M);write_date(O);write_date(N);break;case 2:write_date(T);write_date(U);write_date(E);break;case 3:write_date(W);write_date(E);write_date(D);break;case 4:write_date(T);write_date(H);write_date(U);break;case 5:write_date(F);write_date(R);write_date(I);break;case 6:write_date(S);write_date(A);write_date(T);break;case 7:write_date(S);write_date(U);write_date(N);break;}}