这是我花了2天写出来的一份新手制作的百年历,没有包括2月的特殊月份,没有闰年的区分
单纯是按照每月30天计算的
初始值被我改动了设置的是12月29号23小时59分45秒,这个初始值可根据自己的需求而改变
电路图是在Proteus 软件上进行仿真的
整个程序有个小毛病就是当计时越久它的内部时间延时会越明显,所以这个延时的时间需要看自己需求了,跟自己改
整个程序是用来给新手的速成小程序。以后会慢慢的发帖其他程序的。
当然文件夹中包括了所有文件,电路图,源码,(注意文件是百年历才是对的)
因为一开始我也是改了几下才完全正确
- #include<AT89X52.H>
- unsigned char code tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C};
- unsigned char dat[12];
- unsigned char j,k,tmp;
- unsigned char year=0;
- unsigned char month=12;
- unsigned char day=29;
- unsigned char hour=23;
- unsigned char minute=59;
- unsigned char second=45;
- unsigned char irq_count=0;
- void Delay()
- {
- unsigned char i;
- for(i=0;i<20;i++);
- }
- void main(void)
- {
- EA=1;ET0=1;
- TMOD=0x01;
- TH0=0x3c;
- TL0=0xB0;
- TR0=1;
- while(1)
- {
- tmp=0x01;
- for(j=0;j<8;j++)
- {
- P0=tab[dat[j]];
-
- P1=~tmp;
- tmp=tmp<<1;
- Delay();
- P1=0xff;
- }
- tmp=0x01;
- for(j=8;j<12;j++)
- {
- P0=tab[dat[j]]; //年月日
- P2=~tmp;
- tmp=tmp<<1;
- Delay();
- P2=0xff;
- }
- }
- }
- void timer0(void) interrupt 1 using 1
- {
- TH0=0x3C;
- TL0=0xB0;
- irq_count++;
- if(irq_count>=20)
- {
- irq_count=0;
- second++;
- if(second>=60)
- {
- second=0;
- minute++;
- if(minute>=60)
- {
- minute=0;
- hour++;
- if(hour>=24)
- {
- hour=0;
- day++;
- if(day>=30)
- {
- day=0;
- month++;
- if(month>12)
- {
- month=1;
- year++;
- if(year>=99)
- year=0;
- }
- }
- }
- }
- }
- dat[11]=year%10;
- dat[10]=year/10;
- dat[9]=month%10;
- dat[8]=month/10;
- dat[7]=day/10;
- dat[6]=day%10;
- dat[5]=hour/10;
- dat[4]=hour%10;
- dat[3]=minute/10;
- dat[2]=minute%10;
- dat[1]=second/10;
- dat[0]=second%10;
- }
- }
-
复制代码
|