/*此程序为红外遥控电子钟,晶振为12M,MCU型号为51系列,电路很简单四位共阳数码管,红外接收管sm0038接在P3.2*/
#include
#define uchar unsigned char
#define uint unsigned int
#define c(x) (x*120000/120000)
sbit IR=P3^2;
sbit ge=P2^3;//数码管四位选操控端
sbit shi=P2^2;
sbit bai=P2^1;
sbit qian=P2^0;
char miao,fen=59,shij=23;//时分秒3个变量
uchar num,ding; //两定时器计数变量
uint temp;//遥控解码变量
uchar i;
uchar j;
bit flag;//操控小数点亮与灭变量
bit power;//操控数码管亮与灭变量
bit flash;//进入时刻调整标志位变量
uchar IRBUF[4]; //用于保存解码成果
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个字节
{
for(j=0;j<8;j++) //每个字节8位
{
temp=Low();
if(temp
temp=High();
if(temp
IRBUF[i]>>=1;
if(temp>c(1120)) IRBUF[i]|=0x80;
}
}
return;
}
}