资源描述:
《嵌入式电子闹钟()时钟课程设计》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include//头文件#include#defineucharunsignedchar//宏定义#defineuintunsignedint//位定义sbitrs=P2^5;//液晶位定义sbitlcden=P2^7;sbits1=P2^0;//时间功能切换按键sbits2=P2^1;//按键加sbits3=P2^3;//按键减sbits4=P2^4;//闹钟功能切换键sbitrst=P1^5;//ds1302引脚定义sbitio=P1^6;sbitsclk=P1^7;sbitbeep=P3^0;//蜂鸣器ucharnum,count,shi
2、,fen,miao,s1num,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;//参数定义ucharcodetable[]="20--";//液晶固定显示ucharcodetable1[]="::00:00";/*uchartime_dat[7]={12,1,6,6,12,59,59};//年周月
3、日时分秒ucharwrite_add[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};ucharread_add[7]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};*/voidwrite_com(ucharcom);//液晶写指令函数voidwrite_data(uchardate);//液晶写数据函数voidwrite_ds1302(ucharadd,uchardat);//ds1302芯片写指令函数voidset_rtc();//ds1302时间设置函数voidtime_pros();//ds1302进制转换函数void
4、read_rtc();//ds1302读时间函数voidalarm();//闹钟函数voiddelay(uintz)//延时函数{uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voidinit()//初始化{lcden=0;flag=0;flag1=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);//液晶固定显示,第一行for(num=0;num<14;num++){write_data(table[num]);delay(5);
5、}write_com(0x80+0x40);//液晶显示第二行for(num=0;num<20;num++){write_data(table1[num]);delay(5);}}voidwrite_com(ucharcom)//1602液晶写指令{rs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_data(uchardate)//1602液晶写写数据{rs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_sfm(ucharadd,uchardate)//时分秒
6、{ucharshi3,ge;shi3=date/10;ge=date%10;write_com(0x80+0x40+add);write_data(0x30+shi3);write_data(0x30+ge);}voidwrite_nyr(ucharad,uchardate)//年月日{ucharshi4,ge2;shi4=date/10;ge2=date%10;write_com(0x80+ad);write_data(0x30+shi4);write_data(0x30+ge2);}voidwrite_week(ucharwk)//星期按西方星期设置星期天为第一天{write_co
7、m(0x80+11);switch(wk){case1:write_data('S');delay(5);write_data('U');delay(5);write_data('N');break;case2:write_data('M');delay(5);write_data('O');delay(5);write_data('N');break;case3:write_data('T');delay(5);write_data('U')