新聞中心

c51鬧鐘程序

作者: 時間:2016-11-24 來源:網(wǎng)絡(luò) 收藏
左圖正面凹陷下去的是三個菜單按鈕,右圖邊上的usb接口是供程序下載的,內(nèi)部為四節(jié)鎳鎘電池供電電壓4.8v



#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar hou=0,min=0,sec=0,houc=0,minc=0,secc=0;
uint m=0;
bit yy=0;
sbit khou=P1^1;
sbit kmin=P1^0;
sbit timesea=P1^2;
sbit clock=P3^7;
sbit clear=P3^6;
sbit input=P3^5;
sbit mod=P0^0;
sbit mac=P2^3;
uchar code wela[]={0x7f,0xbf,0xef,0xdf};
uchar code dula[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xD8,0x80,0x90};
uchar data shu[4];
uchar data cldat[4];
void display();
void clsan();
void display1();
void keycan();
void disan();
void keyc();
void send(uchar dat);
void send1(uchar dat1);
void clocking();
void playing();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=12;y>0;y--);
}
void main()
{
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%6;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(!timesea)playing();
else clocking();
if((hou==houc)&(min==minc)&!timesea){mac=0;delay(1000);mac=1;mod=~mod;}
else {mac=1;mod=1;}
}
}

本文引用地址:http://m.butianyuan.cn/article/201611/320964.htm

void time0()interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%6;
m++;
if(m==200)
{m=0;sec++;}
if(sec==60)
{sec=0;min++;}
if(min==60)
{min=0;hou++;}
if(hou==24)
{hou=0;min=0;sec=0;}
}
void playing()
{
display();
keycan();
disan();
}
void display()
{
uchar a=4,k;
while(a--)
{
P2=0xff;
if((m<100)&(a==1))k=0x80;
else k=0x00;
send(dula[shu[a]]-k);
P2=wela[a];
delay(2);
clear=0;
P2=0xff;
clear=1;
}

}
void disan()
{
shu[0]=hou/10;
shu[1]=hou;
shu[2]=min/10;
shu[3]=min;

}
void send(uchar dat)
{
uchar a=8;
while(a--)
{
clock=0;
input=0x80&dat;
clock=1;
dat<<=1;
}
}

void keycan()
{
if(kmin==0)
{
mod=0;
delay(10);
while(kmin==0)display();
mod=1;
if(min>59)min=0;
else min++;
}

if(khou==0)
{
mod=0;
delay(50);
while(khou==0)display();
mod=1;
if(hou>23)hou=0;
else hou++;
}

}
void clocking()
{
keyc();
clsan();
clsan();
display1();
}
void display1()
{
uchar d=4,k;
while(d--)
{
P2=0xff;
if(d==1)k=0x80;
else k=0x00;
send1(dula[cldat[d]]-k);
P2=wela[d];
delay(2);
clear=0;
P2=0xff;
clear=1;
}
}
void keyc()
{
if(khou==0)
{
mac=0;
delay(50);
mac=1;
while(khou==0)display1();
if(houc>23)houc=0;
else houc++;
}

if(kmin==0)
{
mac=0;
delay(50);
mac=1;
while(kmin==0)display1();
if(minc>23)minc=0;
else minc++;
}

}
void send1(uchar dat1)
{

uchar a=8;
while(a--)
{
clock=0;
input=0x80&dat1;
clock=1;
dat1<<=1;
}
}
void clsan()
{
cldat[0]=houc/10;
cldat[1]=houc;
cldat[2]=minc/10;
cldat[3]=minc;
}



關(guān)鍵詞: c51鬧鐘程

評論


技術(shù)專區(qū)

關(guān)閉