上原理图闹钟1
闹钟
时间
日期
程序。。
#include<reg52.h>
#define uint unsigned int #define uchar unsigned char uchar miao=0,fen=0,shi=0,ri=06,yue=07,nian=18;//年月日时分秒定义 uchar i1=0,i2=0; //判断按键变量 uchar miao1,fen1,shi1,miao2,fen2,shi2,naofen[]={0,0};//调闹钟变量 uchar d1,d2,d3,d4,d5; //显示变量 uchar t1=1,t2=1,t3=1; //显示延时变量 uint n13,n12,n11,n21,n22,n23,nz1,nz2; //闹钟变量 void xianshi(); void init1(); void delayms(uchar ms); void display(d1,d2,d3,d4,d5); void naozhong(); int key(); void tiaobiao(); sbit nao1=P1^0; //定义闹钟1端 sbit nao2=P1^1; //定义闹钟2端 sbit key1=P1^4; //定义按键1 sbit key2=P1^5; //定义按键2 sbit key3=P1^6; //定义按键3 sbit key4=P1^7; //定义按键4 uint num[]={0x3F,0x06,0x5B,0x4F, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x40,0x80}; //用于显示的数组 0,1,2,3,4,5,6,7,8,9,-,. void main() //主程序 { init1(); while(1) { key(); xianshi(); tiaobiao(); naozhong(); } } void xianshi() //显示切换 { if(i1==0)display(shi,11,fen,11,miao); if(i1==1)display(nian,10,yue,10,ri); if(i1==2)display(shi1,10,fen1,10,miao1); if(i1==3)display(shi2,10,fen2,10,miao2); } void delayms(uchar ms) //延时 { uint z; for(ms;ms>0;ms--) for(z=200;z>0;z--); } void init1() //定时器1初始化 装初值 { TMOD=0x10; ET1=1; TH1=(65535-50000)/256; TL1=(65535-50000)%256; TR1=1; EA=1; } void timer1() interrupt 3 using 1 //定时器1方式1中断 { uchar count; count++; if(count==20) { nz1++; nz2++; miao++; count=0; if(miao==60) { fen++; miao=0; if(fen==60) { shi++; fen=0; if(shi==24) { ri++; shi=0; if((yue==1||3||5||7||8||10||12)&&(ri==33)) { yue++; ri=1; } if((yue==4||6||9||11)&&(ri==32)) { yue++; ri=1; } if((nian%4==0)&&(yue==2)&&(ri==30)) { yue++; ri=1; } if((nian%4!=0)&&(yue==2)&&(ri==29)) { yue++; ri=1; } if(yue==13) { nian++; yue=1; if(nian==99)nian=0; } } } } } TH1=(65535-50000)/256; TL1=(65535-50000)%256; } void naozhong() //闹钟 { n13=miao1-miao; n12=fen1-fen; n11=shi1-shi; n21=miao2-miao; n22=fen2-fen; n23=shi2-shi; if(i1==2&&key()==3) //调 闹钟1 { if(i2==2) { miao1++; if(miao1==60)miao1=0; 篇幅所限,下载附件
总原理图。
万年历
闹钟
|