這是我花了2天寫出來的一份新手制作的百年歷,沒有包括2月的特殊月份,沒有閏年的區分
單純是按照每月30天計算的
初始值被我改動了設置的是12月29號23小時59分45秒,這個初始值可根據自己的需求而改變
電路圖是在Proteus 軟件上進行仿真的
整個程序有個小毛病就是當計時越久它的內部時間延時會越明顯,所以這個延時的時間需要看自己需求了,跟自己改
整個程序是用來給新手的速成小程序。以后會慢慢的發帖其他程序的。
當然文件夾中包括了所有文件,電路圖,源碼,(注意文件是百年歷才是對的)
因為一開始我也是改了幾下才完全正確
JF[4{CAWI$}D@BPAB(3}R}4.png (13.26 KB, 下載次數: 34)
下載附件
2018-12-7 18:53 上傳
FFT]AG}$%}C8]7[EFAH9P~3.png (4.86 KB, 下載次數: 46)
下載附件
百年歷
2018-12-7 18:49 上傳
- #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;
- }
- }
-
復制代碼
|