资源描述:
《c51单片机多功能数字钟c源程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/*led.h负责声明全局变量*/#include#defineucharunsignedchar#defineuintunsignedint/*各数据在LCD中显示的地址*/#defineYear0x80+0x00#defineMonth0x80+0x05#defineDay0x80+0x08#defineHour0x80+0x40#defineMunite0x80+0x43#defineSecond0x80+0x46#defineWeidu0x80+0x49/*各数据在LCD中显
2、示的地址*//*******各端口定义********/sbitlcden=P2^6;sbitlcdrs=P2^7;sbitbeep=P2^5;sbitkey1=P2^0;sbitkey2=P2^1;sbitkey3=P2^2;sbitkey4=P2^3;sbitkey5=P2^4;sbitdq=P3^7;/*******各端口定义********//*******全局变量声明******/externintkey_function;externintkey_alarm;externinth_alar
3、m,m_alarm;externintidatas,m,h,y,mo,d;externintidatasc,mc,hc,yc,moc,dc;externintwei;externintmusic;externintidatadate[2][13];externuchartimeh,timel;/*******全局变量声明******//*******public方法声明****/voidtime_cal();voidwrite_data(uchardate);voidwrite_com(ucharco
4、m);voidinit(void);voiddelay(uintz);voidputIntToString(int,int);voidscan_key_function();voidscan_key_alarm();voidputIntToLcd();voidputIntToLcd_Alarm(inth_a,intm_a);voidscan_key();voidadd(intvalue);voidmius(intvalue);voidshowGuangBiao(intvalue);voidsong()
5、;voiddelay_music(uintz);voidsacn_key_alarm();voidputStringtoLcd(charaddr,char*p);voidtempchange();uintget_temp();voidputTemp(uintvalue);voidtone(intvalue);/*******public方法声明****//*main.c主功能函数*/#include"led.h"intkey_function=0;//功能键标志intkey_alarm=0;//功能键
6、标志intnum=0;//计数变量intidatawendu;intiswarning;intistone;/*当数据段空间不够时,可用idata修饰全局变量*/intidatas,m,h,y=2013,mo=1,d=12;//显示在LED上的年月日时分秒变量intidatasc,mc,hc,yc=2013,moc=1,dc=12;//实际年月日时分秒变量intidatadate[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,3
7、0,31,30,31,31,30,31,30,31}};//平年与闰年每个月的天数/*当数据段空间不够时,可用idata修饰全局变量*/intwei;//光标显示位置变量inth_alarm=24,m_alarm;intmusic;uchartimeh,timel;/*方法将时间输入到LCD中*/voidputIntToLcd(){write_com(0x0c);//关光标显示write_com(Hour);putIntToString(2,h);write_data(':');write_com(M
8、unite);putIntToString(2,m);write_data(':');write_com(Second);putIntToString(2,s);write_com(Year);putIntToString(4,y);write_data('-');write_com(Month);putIntToString(2,mo);write_data('-');write_com(Day);putIntToString(2,d);}/*方法计算