嵌入式电子闹钟()时钟课程设计(15页).doc
《嵌入式电子闹钟()时钟课程设计(15页).doc》由会员分享,可在线阅读,更多相关《嵌入式电子闹钟()时钟课程设计(15页).doc(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-#include /头文件#include#define uchar unsigned char /宏定义#define uint unsigned int/位定义sbit rs=P25; /液晶位定义 sbit lcden=P27;sbit s1=P20; /时间功能切换按键sbit s2=P21; /按键加sbit s3=P23; /按键减sbit s4=P24; /闹钟功能切换键sbit rst=P15; /ds1302引脚定义sbit io=P16;sbit sclk=P17;sbit beep=P30; /蜂鸣器uchar num,count,shi,fen,miao,s1num,
2、s2num,year,month,day,week,flag,flag1,year1,month1,day1,week1,shi1,fen1,miao1,year2,month2,day2,week2,shi2,fen2,miao2,year5,month5,day5,week5,shi5,fen5,miao5,wk,ashi,afen; /参数定义uchar code table=20 - - ; /液晶固定显示uchar code table1= : : 00:00;/*uchar time_dat7=12,1,6,6,12,59,59; /年周月日时分秒uchar write_add7=
3、0x8c,0x8a,0x88,0x86,0x84,0x82,0x80;uchar read_add7=0x8d,0x8b,0x89,0x87,0x85,0x83,0x81;*/void write_com(uchar com); /液晶写指令函数void write_data(uchar date); /液晶写数据函数void write_ds1302(uchar add,uchar dat); /ds1302芯片写指令函数void set_rtc(); /ds1302时间设置函数void time_pros(); /ds1302进制转换函数void read_rtc(); /ds1302读时
4、间函数void alarm(); /闹钟函数void delay(uint z) /延时函数 uint x,y; for(x=z;x0;x-) for(y=110;y0;y-);void init() /初始化 lcden=0; flag=0; flag1=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80); /液晶固定显示,第一行 for(num=0;num14;num+) write_data(tablenum); delay(5); write_com(0x80+0x
5、40); /液晶显示第二行 for(num=0;num20;num+) write_data(table1num); delay(5); void write_com(uchar com)/1602液晶写指令 rs=0; P0=com; delay(5); lcden=1; delay(5); lcden=0;void write_data(uchar date)/1602液晶写写数据 rs=1; P0=date; delay(5); lcden=1; delay(5); lcden=0;void write_sfm(uchar add,uchar date)/时分秒 uchar shi3,g
6、e; shi3=date/10; ge=date%10; write_com(0x80+0x40+add); write_data(0x30+shi3); write_data(0x30+ge);void write_nyr(uchar ad,uchar date)/年月日 uchar shi4,ge2; shi4=date/10; ge2=date%10; write_com(0x80+ad); write_data(0x30+shi4); write_data(0x30+ge2);void write_week(uchar wk) /星期按西方星期设置 星期天为第一天 write_com(
7、0x80+11); switch(wk) case 1: write_data(S); delay(5); write_data(U); delay(5); write_data(N); break; case 2: write_data(M); delay(5); write_data(O); delay(5); write_data(N); break; case 3: write_data(T); delay(5); write_data(U); delay(5); write_data(E); break; case 4: write_data(W); delay(5); write_
8、data(E); delay(5); write_data(D); break; case 5: write_data(T); delay(5); write_data(H); delay(5); write_data(U); break; case 6: write_data(F); delay(5); write_data(R); delay(5); write_data(T); break; case 7: write_data(S); delay(5); write_data(A); delay(5); write_data(T); break; void keyscan() /按键函
9、数 if(s1=0) delay(5); if(s1=0) write_com(0x0f); s1num+; /记录按键次数 flag=1; flag1=1; while(!s1); switch(s1num)/光标闪烁点定位 case 1:write_com(0x80+0x40+6); /秒 break; case 2:write_com(0x80+0x40+3); /分 break; case 3:write_com(0x80+0x40+0); /时 break; case 4:write_com(0x80+11); /星期 break; case 5:write_com(0x80+8);
10、 /日 break; case 6:write_com(0x80+5); /月 break; case 7:write_com(0x80+2); /年 break; case 8:s1num=0; write_com(0x0c);/设置开显示光标不显示 关闭时间设置 set_rtc(); flag=0; break; if(s1num!=0) /按键加减 if(s2=0) /加按键函数 delay(10); if(s2=0) while(!s2); switch(s1num) /根据功能键相应次数做出调节 case 1: miao+; /秒加 if(miao=60) miao=0; write
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 嵌入式 电子 闹钟 时钟 课程设计 15
限制150内