gwzyou 发表于 2019-8-25 21:16:30

关于串口通信的问题,求教

我想让电脑串口发送数据,单片机识别此数字是几,然后显示到数码管上。
可是把接受到的数字定义为 intreceived 或 char received 都不行,怎么定义?还是存在其他问题
#include<reg52.h>
sbit a=P2^2;
sbit b=P2^3;
sbit c=P2^4;
typedef unsigned char u8;
typedef unsigned int u16;
u8 received;
u8 x;

u8 code smg[]={0x3f, 0x06 , 0x5b , 0x4f , 0x66 , 0x6d ,
                0x7d , 0x07 , 0x7f, 0x6f };
void play(u16 i)
{a=0;b=0;c=0;

P0=smg;
}

void chuankou()
{
TMOD=0X20;
TR1=1;
TH1=0XF3;
TL1=0XF3;
PCON=0X80;
EA=1;
ES=1;
SCON=0X50;
}

void chuan() interrupt 4
{
received=SBUF;
x=received;
RI=0;
play(x);
}


main()
{chuankou();
while(1);

}

页: [1]
查看完整版本: 关于串口通信的问题,求教