资源描述:
《ct107d可调时钟(带闹铃_主控stc89c52rc)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、l电路原理图:lPCB电路图:l电路板3D效果图:LED灯退出确定减加闹钟调时DS1302LCD1602插槽STC89C52RCLED对比度调节蜂鸣器正面(直插LCD1602,键盘,LED灯)背面(主控芯片,lcd对比度调节,蜂鸣器)l主程序:#include#include"lcd1602.h"#include"ds1302.h"sbitadd=P3^0;sbitsub=P3^1;sbitchooset=P3^2;sbitchoosec=P3^3;sbitok=P3^4;sbitout=P3^5;sbitbuzz=P2^2;sbitrelay=P2^4;uns
2、ignedcharwelcome1[]=">>>Welcome<<<";unsignedcharwelcome2[]="____";unsignedintdd=0,c,t,flag1=0,flag,adjust,i,sec,min,hour,day,month,week,year,shi,fen,miao,nian,yue,ri,zhou,n,y,r,z,s,f,m;voiddelay5ms(void)//误差0us{unsignedchara,b;for(b=19;b>0;b--)for(a=130;a>0;a--);}voiddelay1s(unsignedintd)//误差
3、0us{unsignedchara,b,c;while(d>0){for(c=167;c>0;c--)for(b=171;b>0;b--)for(a=16;a>0;a--);d--;}}voidDs1302_init(){Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_Byte_Write(0x80,55);Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_Byte_Write(0x82,59);Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_B
4、yte_Write(0x84,11);Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_Byte_Write(0x86,21);Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_Byte_Write(0x88,2);Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_Byte_Write(0x8a,7);Ds1302_Single_Byte_Write(0x8e,0);Ds1302_Single_Byte_Write(0x8C,16);}voiddis
5、play(){while(1){Ds1302_Single_Byte_Write(0x8f,0);sec=Ds1302_Single_Byte_Read(0x81);Ds1302_Single_Byte_Write(0x8f,0);min=Ds1302_Single_Byte_Read(0x83);Ds1302_Single_Byte_Write(0x8f,0);hour=Ds1302_Single_Byte_Read(0x85);Ds1302_Single_Byte_Write(0x8f,0);day=Ds1302_Single_Byte_Read(0x87);Ds1302_S
6、ingle_Byte_Write(0x8f,0);month=Ds1302_Single_Byte_Read(0x89);Ds1302_Single_Byte_Write(0x8f,0);week=Ds1302_Single_Byte_Read(0x8b);Ds1302_Single_Byte_Write(0x8f,0);year=Ds1302_Single_Byte_Read(0x8d);write_command(0x80+2);write_data(year/10%10+48);write_data(year%10+48);write_command(0x80+5);wri
7、te_data(month/10%10+48);write_data(month%10+48);write_command(0x80+8);write_data(day/10%10+48);write_data(day%10+48);write_command(0x80+14);write_data(week+48);write_command(0x80+0x40+8);write_data(hour/10%10+48);write_data(hour%10+48);write_