STC89C51单片机串口通讯 ,发送数据数码管不显示,大佬们帮忙看看代码哪里出问题了?
#include<reg51.h>#include<intrins.h>intnum=0;voidtimer1init();voiddelay(chark){while(...
#include <reg51.h>
#include <intrins.h>
int num=0;
void timer1init();
void delay(char k)
{
while(k--);
}
void display(int i)
{
static int wei;
char code a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
switch(wei)
{
case 0: P2=0x7F;P0=a[i/100]; break;
case 1: P2=0xBF;P0=a[i/10%10];break;
case 2: P2=0xDF;P0=a[i%10]; break;
}
wei++ ;
if(wei==3)
wei=0;
delay(2);
}
void timer0init()
{
EA=1;
ET0=1;
TR0=1;
// REN=1;
TMOD |=0x01;
TH0=0xed;
TL0=0xff;
}
void UARTInit()
{
EA=1;
ES=1;
SM0=0;
REN=1;
TR1=1;
TMOD |=0x01;
TH1=0xfd;
TL1=0xfd;
}
void main()
{
timer0init();
UARTInit();
while(1)
{
}
}
void int1() interrupt 1
{
TH0=0xed;
TL0=0xff;
display(num);
}
void UART() interrupt 4
{
if(RI)
{
num=SBUF;
RI=0;
}
} 展开
#include <intrins.h>
int num=0;
void timer1init();
void delay(char k)
{
while(k--);
}
void display(int i)
{
static int wei;
char code a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
switch(wei)
{
case 0: P2=0x7F;P0=a[i/100]; break;
case 1: P2=0xBF;P0=a[i/10%10];break;
case 2: P2=0xDF;P0=a[i%10]; break;
}
wei++ ;
if(wei==3)
wei=0;
delay(2);
}
void timer0init()
{
EA=1;
ET0=1;
TR0=1;
// REN=1;
TMOD |=0x01;
TH0=0xed;
TL0=0xff;
}
void UARTInit()
{
EA=1;
ES=1;
SM0=0;
REN=1;
TR1=1;
TMOD |=0x01;
TH1=0xfd;
TL1=0xfd;
}
void main()
{
timer0init();
UARTInit();
while(1)
{
}
}
void int1() interrupt 1
{
TH0=0xed;
TL0=0xff;
display(num);
}
void UART() interrupt 4
{
if(RI)
{
num=SBUF;
RI=0;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询