|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include "reg52.h"
sbit WEI = P2^7;
sbit DUA = P2^6;
#define uint unsigned int
#define uchar unsigned char
void UART_Init(void);
void SMG_Init(uchar i);
uchar code DuanMa[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,};
uchar code WeiMa[] = {0xef,0xdf,0xbf};
uchar ff;
void main(void)
{
UART_Init();
while(1)
{
;
}
}
void UART_Init(void)
{
EA = 1;
ES = 1;
TMOD = TMOD & 0xff;
TMOD = TMOD | 0x20;
SM0 = 0;
SM1 = 1;
REN = 1;
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1;
}
void SMG_Init(uchar i)
{
static uchar Num;
Num = i;
WEI = 1;
P0 = WeiMa;
WEI = 0;
switch(i)
{
case 0: DUA = 1; P0 = DuanMa[Num / 100]; DUA = 0; break;
case 1: DUA = 1; P0 = DuanMa[Num / 100 % 10]; DUA = 0; break;
case 2: DUA = 1; P0 = DuanMa[Num % 10]; DUA = 0; break;
}
}
void InitterruptUART(void) interrupt 4
{
uchar cnt;
uchar temp;
TH1 = 0xfd;
TL1 = 0xfd;
cnt++;
SMG_Init(ff);
if(RI == 1)
{
RI = 0;
ff = SBUF;
temp = ff;
SBUF = temp++;
if(TI == 1)
{
TI = 0;
}
}
} |
|