CT107D可调时钟带闹铃主控STC89C52RC.docx
- 文档编号:30586573
- 上传时间:2023-08-18
- 格式:DOCX
- 页数:34
- 大小:598.90KB
CT107D可调时钟带闹铃主控STC89C52RC.docx
《CT107D可调时钟带闹铃主控STC89C52RC.docx》由会员分享,可在线阅读,更多相关《CT107D可调时钟带闹铃主控STC89C52RC.docx(34页珍藏版)》请在冰豆网上搜索。
CT107D可调时钟带闹铃主控STC89C52RC
CT107D可调时钟(带闹铃_主控STC89C52RC)
电路原理图:
PCB电路图:
电路板3D效果图:
正面(直插LCD1602,键盘,LED灯)
背面(主控芯片,lcd对比度调节,蜂鸣器)
主程序:
#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;
unsignedcharwelcome1[]=">>>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)//误差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_Byte_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);
}
voiddisplay()
{
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_Single_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);
write_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_command(0x80+0x40+11);
write_data(min/10%10+48);
write_data(min%10+48);
write_command(0x80+0x40+14);
write_data(sec/10%10+48);
write_data(sec%10+48);
if((n==year)&&(y==month)&&(r==day)&&(z==week)&&(s==hour)&&(f==min)&&(m==sec))
{
dd=200;
}
if(dd>0)
{
if(sec%2==0)
{
P2=0xa0;
buzz=1;
relay=1;
P2=0x1f;
dd--;
}
if(ok==0)
{
delay5ms();
if(ok==0)
{
while(!
ok);
delay5ms();
if(ok==1)
{
dd=0;
}
}
}
}
if((sec%2)!
=0)
{
P2=0xa0;
buzz=0;
relay=0;
P2=0x1f;
}
}
}
voidkeyscan()
{
while((adjust>0)&&(flag==0))
{
if(adjust==1)
{
write_command(0x80+0x40+14);
write_command(0x0f);
if(add==0)
{
delay5ms();
if(add==0)
{
while(!
add);
delay5ms();
if(add==1)
{
miao++;
if(miao==60)
{
miao=0;
}
write_command(0x80+0x40+14);
write_data(miao/10%10+48);
write_data(miao%10+48);
write_command(0x80+0x40+14);
write_command(0x0f);
flag1=1;
}
}
}
if(sub==0)
{
delay5ms();
if(sub==0)
{
while(!
sub);
delay5ms();
if(sub==1)
{
miao--;
if(miao==-1)
{
miao=59;
}
write_command(0x80+0x40+14);
write_data(miao/10%10+48);
write_data(miao%10+48);
write_command(0x80+0x40+14);
write_command(0x0f);
flag1=1;
}
}
}
}
if(adjust==2)
{
write_command(0x80+0x40+11);
write_command(0x0f);
if(add==0)
{
delay5ms();
if(add==0)
{
while(!
add);
delay5ms();
if(add==1)
{
fen++;
if(fen==60)
{
fen=0;
}
write_command(0x80+0x40+11);
write_data(fen/10%10+48);
write_data(fen%10+48);
write_command(0x80+0x40+11);
write_command(0x0f);
flag1=1;
}
}
}
if(sub==0)
{
delay5ms();
if(sub==0)
{
while(!
sub);
delay5ms();
if(sub==1)
{
fen--;
if(fen==-1)
{
fen=59;
}
write_command(0x80+0x40+11);
write_data(fen/10%10+48);
write_data(fen%10+48);
write_command(0x80+0x40+11);
write_command(0x0f);
flag1=1;
}
}
}
}
if(adjust==3)
{
write_command(0x80+0x40+8);
write_command(0x0f);
if(add==0)
{
delay5ms();
if(add==0)
{
while(!
add);
delay5ms();
if(add==1)
{
shi++;
if(shi==24)
{
shi=0;
}
write_command(0x80+0x40+8);
write_data(shi/10%10+48);
write_data(shi%10+48);
write_command(0x80+0x40+8);
write_command(0x0f);
flag1=1;
}
}
}
if(sub==0)
{
delay5ms();
if(sub==0)
{
while(!
sub);
delay5ms();
if(sub==1)
{
shi--;
if(shi==-1)
{
shi=23;
}
write_command(0x80+0x40+8);
write_data(shi/10%10+48);
write_data(shi%10+48);
write_command(0x80+0x40+8);
write_command(0x0f);
flag1=1;
}
}
}
}
if(adjust==4)
{
write_command(0x80+14);
write_command(0x0f);
if(add==0)
{
delay5ms();
if(add==0)
{
while(!
add);
delay5ms();
if(add==1)
{
zhou++;
if(zhou==8)
{
zhou=1;
}
write_command(0x80+13);
write_data(zhou/10%10+48);
write_data(zhou%10+48);
write_command(0x80+14);
write_command(0x0f);
flag1=1;
}
}
}
if(sub==0)
{
delay5ms();
if(sub==0)
{
while(!
sub);
delay5ms();
if(sub==1)
{
zhou--;
if(zhou==-1)
{
zhou=7;
}
write_command(0x80+14);
write_data(zhou/10%10+48);
write_data(zhou%10+48);
write_command(0x80+14);
write_command(0x0f);
flag1=1;
}
}
}
}
if(adjust==5)
{
write_command(0x80+8);
write_command(0x0f);
if(add==0)
{
delay5ms();
if(add==0)
{
while(!
add);
delay5ms();
if(add==1)
{
ri++;
switch(yue)
{
case2:
if(((nian%4==0)&&(nian%100!
=0))||((nian%100==0)&&(nian%400==0)))
{
if(ri==29)
{
ri=1;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
}
else
{
if(ri==30)
{
ri=1;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
}
case1:
case3:
case5:
case7:
case8:
case10:
case12:
if(ri==32)
{
ri=1;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
case4:
case6:
case9:
case11:
if(ri==32)
{
ri=1;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
}
}
}
}
if(sub==0)
{
delay5ms();
if(sub==0)
{
while(!
sub);
delay5ms();
if(sub==1)
{
ri--;
switch(yue)
{
case2:
if(((nian%4==0)&&(nian%100!
=0))||((nian%100==0)&&(nian%400==0)))
{
if(ri==-1)
{
ri=28;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
}
else
{
if(ri==-1)
{
ri=29;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
}
case1:
case3:
case5:
case7:
case8:
case10:
case12:
if(ri==-1)
{
ri=31;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
case4:
case6:
case9:
case11:
if(ri==-1)
{
ri=30;
}
write_command(0x80+8);
write_data(ri/10%10+48);
write_data(ri%10+48);
write_command(0x80+8);
write_command(0x0f);
flag1=1;
}
}
}
}
}
if(adjust==6)
{
write_command(0x80+5);
write_co
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CT107D 可调 时钟 闹铃 主控 STC89C52RC