#include<reg51.h>
code unsigned char LEDMAP[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};
// 八段管显示码 0-F 8段数码管为共阴极接发
unsigned int i = 0 ;
void delay(time)
{
unsigned int j;
unsigned int k;
for(j=0;j<time;j++)
for(k=0;k<time;k++)
{;}
}
void main()
{
SCON = 0X50; //工作方式1 ,接收允许,八位数据
PCON = 0X00; //波特率加倍
TMOD = 0x20; //定时器T1 工作方式2 自动装填八位定时器
TH1 = 0XF4;
TL1 = 0XF4; // 波特率2400 设置初值
TR1 = 1; // 打开定时器T1
EA = 1; //开总中断
ES = 1; //开接收中断
P0 = 0xFC; //后两个数码管打开
while(1)
{
if(i<10)
{
SBUF = LEDMAP[ i]; //数据送入寄存器
while(TI==0) ; //等待数据发送完
TI = 0; //发完 TI清零
i++ ;
delay(500);
}
}
}
void receive() interrupt 4
{
int temp;
if(RI==1)
{
RI = 0;
temp = SBUF; //接收串口数据
P1 = temp;
delay(500);
}
if(TI)
{TI=0;}
}
|