# include<reg52.h>
# include<stdio.h>
# define uchar unsigned char
# define uint unsigned int
uchar flag,a,j,RX_num1,f;
uchar mark=0,M,y,aa,bb;
sbit D=P2^6; //继电器
sbit W=P2^7; //蜂鸣器
uchar code table[]="I get";
uchar code duan[]={ 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,
0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};
uchar USART1_RX_BUF[10]; //接收缓冲,最大6个字节.
void uart_init() //串口初始化
{
TMOD |=0x20; //设置定时器1为工作方式2
PCON = 0X00;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
ES=1;
RI=0;
EA=1;
}
void time_init()
{
TMOD=0X01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 2;
j = 3;
do
{
while (--j);
} while (--i);
}
void dis()
{
D=1;
P0=duan[aa];
D=0;
P0=0XFF;
W=1;
P0=0Xfb;
W=0;
Delay10ms();
D=1;
P0=duan[bb];
D=0;
P0=0XFF;
W=1;
P0=0XF7;
W=0;
Delay10ms();
}
void xianshi()
{
uchar shi,ge;
shi = y/10;
ge = y%10;
D=1;
P0=duan[shi];
D=0;
P0=0XFF;
W=1;
P0=0XFE;
W=0;
Delay10ms();
D=1;
P0=duan[ge];
D=0;
P0=0XFF;
W=1;
P0=0XFd;
W=0;
Delay10ms();
}
void main()
{
time_init();
uart_init();
while(1)
{
xianshi(); //时间显示
dis(); //接受的显示
}
}
void tim() interrupt 1
{
uint num;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num++;
if(num==20)
{
num=0;
y++;
if(y==59)
{
y=0;
}
}
}
void ser() interrupt 4
{
RI=0;
M=SBUF;
aa = M/16;
bb = M%16;
}