#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar Rbuf = 0;
uchar code dis_7[] = {
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, //共阴段码
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00};
//段码表 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, off
//-------------------------------
void delay(uint k)
{
uint i, j;
for(i = 0; i < k; i++) for(j = 0; j < 200; j++);
}
//-------------------------------
void Display(uchar x)
{
P2 = 0xFF;
P0 = dis_7[x / 16]; //输出高四位
P2 = 0xFE; delay(2);
P2 = 0xFF;
P0 = dis_7[x % 16]; //输出低四位
P2 = 0xFD; delay(2);
}
//-------------------------------
void UART()interrupt 4
{
if(RI) {
RI = 0; //清除中断标志
Rbuf = SBUF;
}
if(TI) {
TI = 0; //清除中断标志
}
}
//-------------------------------
void main()
{
uchar t1, i;
SCON = 0x50; //串口工作在方式1
PCON &= 0x7F; //SMOD=0
TMOD = 0x20; //定时器1当做波特率发生器
TH1 = 0xFD; //初值, 9600 @ 11.0592MHz
TL1 = 0xFD;
TR1 = 1;
ES = 1;
EA = 1;
while (1) {
for (i = 0; i < 100; i++)//多次循环,便于观察与发送
Display(Rbuf); //显示收到的数据
SBUF = t1; //发送数据
P1 = ~t1; //本机显示
t1++;
// t1--;
}
}
这几个led灯怎么点亮的看不懂 |