世上最簡(jiǎn)單的遙控(數(shù)碼管顯示)電子鐘(C語(yǔ)言編寫)
#include
#define uchar unsigned char
#define uint unsigned int
#define c(x) (x*120000/120000)
sbit IR=P3^2;
sbit ge=P2^3;//數(shù)碼管四位選控制端
sbit shi=P2^2;
sbit bai=P2^1;
sbit qian=P2^0;
char miao,fen=59,shij=23;//時(shí)分秒3個(gè)變量
uchar num,ding; //兩定時(shí)器計(jì)數(shù)變量
uint temp;//遙控解碼變量
uchar i;
uchar j;
bit flag;//控制小數(shù)點(diǎn)亮與滅變量
bit power;//控制數(shù)碼管亮與滅變量
bit flash;//進(jìn)入時(shí)間調(diào)整標(biāo)志位變量
uchar IRBUF[4]; //用于保存解碼結(jié)果
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e
};
uint Low()
{
TL0=0;
TH0=0;
TR0=1;
while(!IR&&(TH0&0x80)==0);
TR0=0;
return TH0*256+TL0;
}
//=============================================================
uint High()
{
TL0=0;
TH0=0;
TR0=1;
while(IR&&(TH0&0x80)==0);
TR0=0;
return TH0*256+TL0;
}
void xian(uchar shik,uchar fen)
{
P0=table[shik/10];
if(power==0)
qian=0;
else
qian=1;
// delay(2);
qian=1;
if(flag==0)
P0=table[shik%10]&0x7f;
else
P0=table[shik%10]|0x80;
if(power==0)
bai=0;
else
bai=1;
//delay(2);
bai=1;
P0=table[fen/10];
if(power==0)
shi=0;
else
shi=1;
//delay(2);
shi=1;
P0=table[fen%10];
if(power==0)
ge=0;
else
ge=1;
//delay(2);
ge=1;
}
void yin()
{
while(1)
{
restart:
while(IR)
{
xian(shij,fen);
if(flash==1)
{
if(ding>5)
{
ding=0;
power=~power;
//xian(shij,fen);
}
}
}
temp=Low();
if(temp
temp=High();
if(temp
for(i=0;i<4;i++) //4個(gè)字節(jié)
{
for(j=0;j<8;j++) //每個(gè)字節(jié)8位
{
temp=Low();
if(temp
temp=High();
if(temp
IRBUF[i]>>=1;
if(temp>c(1120)) IRBUF[i]|=0x80;
}
}
return;
}
}
評(píng)論