|
再給大家分享一個(gè)同學(xué)做的萬(wàn)年歷,希望可以幫助到需要的同學(xué)哦。
數(shù)碼管萬(wàn)年歷仿真圖:
0.png (22.62 KB, 下載次數(shù): 73)
下載附件
2017-5-29 02:20 上傳
0.png (79.71 KB, 下載次數(shù): 72)
下載附件
2017-5-29 02:20 上傳
單片機(jī)源程序如下:
- #include<reg51.h>
- #include<absacc.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ture 1
- #define fault 0
- sbit SET=P1^7;
- void delay(uchar k) ;
- uchar monthday(uchar a,uchar b);
- void display() ;
- uchar code dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
- uchar code scan[]={0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
- 0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
- 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd};
- //掃描的譯碼信號(hào)
- uchar i;
- uchar code table[]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0xA7,0xFF,0xEF,0xC0};
- uchar buffer[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- uchar shuju=0;
- uchar state=0;
- uchar qxiang;
- typedef struct
- {
- uchar year[2];
- uchar month;
- uchar day;
- uchar week;
- }date;
- typedef struct
- {
- uchar hour;
- uchar minute;
- uchar second;
- }time;
- uchar count=0;
- date today={{9,20},4,20,1};
- time now={11,8,10};
- void main()
- {
- TMOD=0x01;
- TL0=(65536-1000)%256;
- TH0=(65536-1000)/256;
- IE=0x82; //EA=1;ET0=1總中斷允許和定時(shí)器中斷允許
- TCON=0x10; //定時(shí)器啟動(dòng)計(jì)數(shù)
- while(1)
- {
- P1=0xff;
- shuju=P1&0xff;
- qxiang=shuju&0x80;
- switch(qxiang)
- {
- case(0x80):switch(shuju)
- {
- case(0xfe) : //秒調(diào)整
- {
- EA=1;
- EX0=1; //IE=0x83; //EA=1;ET0=1;EX0=0總中斷允許,定時(shí)器中斷允許,外中斷允許
- IT0=1; //TCON=0x11; //TR0=1;IT0=1;定時(shí)器啟動(dòng),外中斷為負(fù)邊沿觸發(fā)
- }break;
- case(0xfd) : //分調(diào)整
- {
- EA=1;
- EX0=1; // IE=0x83;
- IT0=1; //TCON=0x11;
- }break;
- case(0xfb) : //時(shí)調(diào)整
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0xf7) : //星期調(diào)整
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0xef) : //日調(diào)整
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0xdf): //月調(diào)整
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0xbf): //年調(diào)整
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- default: //時(shí)鐘正常計(jì)時(shí)
- {
- EA=1;
- TR0=1;
- EX0=0;
-
- }break;
- }break;
- case(0x00) :switch(shuju)
- {
- case(0x7e):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0x7d):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0x7b):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0x77):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0x6f):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0x5f):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- case(0x3f):
- {
- EA=1;
- EX0=1;
- IT0=1;
-
- }break;
- default: //時(shí)鐘正常計(jì)時(shí)
- {
- EA=1;
- TR0=1;
- EX0=0;
-
- }break;
- }break;
- }
- }
- }
- void inter0() interrupt 0 using 0
- {
- uchar result,z;
- result=shuju;
- switch(qxiang)
- {
- case(0x80): switch(result)
- {
- case(0xfe) : // if(result==0xfe) //秒調(diào)整 +
- {
- now.second++;
- if(now.second>=60)
- {
- now.second=0;
- }
- display();
- }break;
-
- case(0xfd) : //if(result==0xfd) //分調(diào)整 +
- {
- now.minute++;
- if(now.minute>=60)
- {
- now.minute=0;
- }
- display();
- }break;
-
- case(0xfb) : //if(result==0xfb) //時(shí)調(diào)整 +
- {
- now.hour++;
- if(now.hour>=24)
- {
- now.hour=0;
- }
- display();
- }break;
-
- case(0xf7) : // if(result==0xf7) //星期調(diào)整 +
- {
- today.week++;
- if(today.week>=8)
- {
- today.week=1;
- }
- display();
- }break;
- case(0xef) : //if(result==0xef) //日期調(diào)整 +
- {
- today.day++;
- z = monthday( today.year[1] , today.year[0] );
- if((z==1)&&(today.month==2))
- {
- if(today.day>=30)
- today.day=1;
- }
- else if (today.day>dayofmonth[today.month-1])
- today.day=1;
- display();
- }break;
-
- case(0xdf) : //if(result==0xdf) //月調(diào)整 +
-
- {
- today.month++;
- if(today.month>=13)
- {
- today.month=1;
- }
- display();
- } break;
-
-
- case(0xbf) : //if(result==0xbf) //年調(diào)整 +
- {
- today.year[0]=today.year[0]+1;
- if(today.year[0]>=100)
- {
- today.year[0]=0;
- today.year[1]=today.year[1]+1;
- if(today.year[1]>=100)
- {
- today.year[1]=0;
- }
- }
- display();
- }break;
- default: //時(shí)鐘正常計(jì)時(shí)
- {
- EA=1;
- TR0=1;
- EX0=0;
-
- }break;
- }break;
-
- case(0x00): switch(result)
- {
- case(0x7e): //if(result==0x7f) //秒調(diào)整—
- {
- if(now.second>0)
- now.second=now.second-1;
- else now.second=59;
- display();
- }break;
-
- case(0x7d): //if(result==0x7d) //分調(diào)整—
- {
- if(now.minute>0)
- now.minute=now.minute-1;
- else now.minute=59;
- display();
- } break;
-
- case(0x7b) : //if(result==0x7b) // 時(shí)調(diào)整-
-
- {
- if(now.hour>0)
- now.hour=now.hour-1;
- else now.hour=23 ;
- display();
- }break;
-
- case(0x77) : //if(result==0x77) // 周調(diào)整—
- {
- if(today.week>1)
- today.week=today.week-1;
- else today.week=7;
- display();
- }break;
-
- case(0x6f): //if(result==0x6f) // 日期調(diào)整—
- {
- z = monthday( today.year[1] , today.year[0] );
- if((z==1)&&(today.month==2))
- {
- if(today.day>1)
- today.day=today.day-1;
- else today.day=29;
- }
- else {
- if(today.day>1)
- today.day=today.day-1;
- else today.day=dayofmonth[today.month-1];
- }
- display();
- }break;
- case(0x5f): //if(result==0x5f) // 月調(diào)整—
- {
- if(today.month>1)
- today.month=today.month-1;
- else today.month=12;
- display();
- }break;
- case(0x3f) : // 年調(diào)整——
- {
- if(today.year[0]>0)
- today.year[0]=today.year[0]-1;
- else
- {
- today.year[0]=99;
- today.year[1]=today.year[1]-1;
- }
- display();
- }break;
- default: //時(shí)鐘正常計(jì)時(shí)
- {
- EA=1;
- TR0=1;
- EX0=0;
- }break;
- }break;
- }
- }
-
- void timer0_int() interrupt 1 using 1
- {
- uchar c;
- TL0=(65536-1000)%256; //中斷時(shí)間是10ms
- TH0=(65536-1000)/256;
- TR0=1;
- count++;
- if(count==35)
- {
- count=0;
- now.second=now.second+1;
- if(now.second>=60)
- {
- now.second=0;
- now.minute++;
- if(now.minute>=60)
- {
- now.minute=0;
- now.hour++;
- if(now.hour>=24)
- {
- now.hour=0;
- today.week++;
- today.day++;
- if(today.week>=8)
- {
- today.week=1;
- }
- c=monthday( today.year[1], today.year[0]);
- if((c==1)&&(today.month==2))
- {
- if(today.day>=30)
- {
- today.day=1;
- today.month++;
- }
-
- }
- else if(today.day>=(dayofmonth[today.month-1]+1))
- {
- today.day=1;
- today.month++;
- if(today.month>=13)
- {
- today.month=1;
- today.year[0]=today.year[0]+1;
- if(today.year[0]>=100)
- {
- today.year[0]=0;
- today.year[1]=today.year[1]+1;
- if(today.year[1]>=100)
- {
- today.year[1]=0;
- }
- }
- }
- }
- }
- }
- }
- }
- display();
- }
- void delay(uchar k)
- {
- uchar m,n;
- for(m=0;m<=k;m++)
- for(n=0;n<=40;n++);
- }
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
萬(wàn)年歷.rar
(41.24 KB, 下載次數(shù): 37)
2017-5-28 22:17 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|