1、基于51数码管显示的万年历仿真+程序完整基于数码管显示的万年历(proteus仿真+C程序)Proteus仿真图C语言程序/*TITLE: 万年历设计FUNCTION: 显示:年-月-日-星期-时-分-秒WRITER: LINLIANHUOTIME: 2014-07-24REMARK: 译码扫描时间不能过长,否则无法实现调整*/#include#define uint unsigned int#define uchar unsigned char/*码表*/uchar code smg_table=0xBF,0x86,0xDB,0xCF,0xE6, 0xED,0xFD,0xA7,0xFF,0x
2、EF,0xC0;uchar code months_days=31,28,31,30,31,30,31,31,30,31,30,31;uchar code transcode=0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed, 0xee,0xef,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd;uchar buffer22=0; /*数据定义*/uchar add_sub;uchar key_detection=0;uchar count=0;typedef struct uchar yea
3、r2; uchar month; uchar day; uchar week;date;typedef struct uchar hour; uchar minute; uchar second;moment;date today=14,20,7,25,5;moment now=16,52,45;/*延时子程序*/void delay() uchar i,j; for(i=0;i=8;i+) for(j=0;j40;j+);/*数码管显示子程序*/void smg_display() uchar i; buffer0=now.second%10; buffer1=now.second/10;
4、buffer2=10; buffer3=now.minute%10; buffer4=now.minute/10; buffer5=10; buffer6=now.hour%10; buffer7=now.hour/10; buffer8=today.week%10; buffer9=today.week/10; buffer10=10; buffer11=today.day%10; buffer12=today.day/10; buffer13=10; buffer14=today.month%10; buffer15=today.month/10; buffer16=10; buffer1
5、7=today.year0%10; buffer18=today.year0/10; buffer19=today.year1%10; buffer20=today.year1/10; buffer21=10; for(i=0;i=60) now.second=0; now.minute+; if(now.minute=60) now.minute=0; now.hour+; if(now.hour=24) now.hour=0; today.day+; today.week+; if(today.week=8) today.week=1; l=leap_year(today.year1,to
6、day.year0); if(l=1)&(today.month=2) if(today.day=30) today.day=1; today.month+; else if(today.day=months_daystoday.month-1+1) today.day=1; today.month+; if(today.month=12) today.month=1; today.year0=today.year0+1; if(today.year0=100) today.year0=0; today.year1=today.year1+1; if(today.year1=100) toda
7、y.year1=0; smg_display();/*INT0中断服务子程序*/void int0_int() interrupt 0 using 1 uchar k; switch(add_sub) case 0x80:switch(key_detection) case 0xfe: now.second+; if(now.second=60) now.second=0; smg_display(); break; case 0xfd: now.minute+; if(now.minute=60) now.minute=0; smg_display(); break; case 0xfb:
8、now.hour+; if(now.hour=24) now.hour=0; smg_display(); break; case 0xf7: today.week+; if(today.week=8) today.week=1; smg_display(); break; case 0xef: today.day+; k=leap_year(today.year1,today.year0); if(k=1)&(today.month=2) if(today.day=30) today.day=1; else if(today.day=months_daystoday.month-1) tod
9、ay.day=1; smg_display(); break; case 0xdf: today.month+; if(today.month=13) today.month=1; smg_display(); break; case 0xbf: today.year0=today.year0+1; if(today.year0=100) today.year0=0; today.year1=today.year1+1; if(today.year1=100) today.year1=0; smg_display(); break; default:EA=1;EX0=0;TR0=1;break
10、; break; case 0x00:switch(key_detection) case 0x7e: /now.second+; if(now.second0) now.second-; else now.second=59; smg_display(); break; case 0x7d: /now.minute+; if(now.minute0) now.minute-; else now.minute=59; smg_display(); break; case 0x7b: /now.hour+; if(now.hour0) now.hour-; else now.hour=23; s
11、mg_display(); break; case 0x77: /today.week+; if(today.week1) today.week-; else today.week=1; smg_display(); break; case 0x6f: /today.day+; k=leap_year(today.year1,today.year0); if(k=1)&(today.month=2) if(today.day1) today.day-; else today.day=29; else if(today.day1) today.day-; else today.day=month
12、s_daystoday.month-1; smg_display(); break; case 0x5f: /today.month+; if(today.month1) today.month-; else today.month=12; smg_display(); break; case 0x3f: /today.year0=today.year0+1; if(today.year00) today.year0=today.year0-1; else today.year0=99; today.year1=today.year1-1; smg_display(); break; default:EA=1;EX0=0;TR0=1;break; break;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1