找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1045|回復(fù): 2
收起左側(cè)

單片機(jī)串口實(shí)現(xiàn)數(shù)碼管的動(dòng)態(tài)顯示,為什么無(wú)法接受數(shù)據(jù)?

[復(fù)制鏈接]
ID:904179 發(fā)表于 2021-4-13 13:29 | 顯示全部樓層 |閱讀模式
#include<reg52.h>#define uchar unsigned char

#define uint unsigned int
        unsigned char dat;//用于存儲(chǔ)單片機(jī)接收發(fā)送緩沖寄存器SBUF里面的內(nèi)容

uchar const dofly[]={0x05,0x7d,0x46,0x54,
0x3c,0x94,0x84,0x5d,0x04,0x14
};
uchar  code seg[]={0x01,0x79,0x42,0x50,0x38,
0x90,0x80,0x59,0x00,0x10
};
sbit wela=P2^7;
uchar bai,shi,ge;

void delay(unsigned int xms )
{
        unsigned int i,j;
        for(i=xms;i>0;i--)
                for(j=110;j>0;j--);
}

void display(dat)
{
        bai=dat/100;
        shi=(dat%100)/10;
        ge=dat%10;
        wela=1;
        P0=dofly[bai];
        P2=seg[0];
        delay(3);
        wela=1;
        P0=dofly[shi];
        P2=seg[1];
        delay(3);
        wela=1;
        P0=dofly[ge];
        P2=seg[2];
        delay(3);
}
void Init_Com(void)
{
        TMOD=0x20;
        PCON=0x00;
        SCON=0x50;
        TH1=0xfd;
        TL1=0xfd;
        TR1=1;
}
void main()
{
        Init_Com();
        while(1)
        {
                if(RI)
                        
                {dat=SBUF;
                        RI=0;
                        SBUF=dat;
                }
                display(dat);
        }
}
                        
為什么無(wú)法接受數(shù)據(jù),哪位大佬幫忙看看
回復(fù)

使用道具 舉報(bào)

ID:900662 發(fā)表于 2021-4-13 21:55 | 顯示全部樓層
你初始化的時(shí)候總中斷開關(guān)沒(méi)開   ,T1不會(huì)產(chǎn)生波特率,ES也沒(méi)開,串口中斷不開怎么接收數(shù)據(jù)呢????

ES=1; //開串口中斷  
    EA=1; //打開總中斷
回復(fù)

使用道具 舉報(bào)

ID:904179 發(fā)表于 2021-4-14 21:50 | 顯示全部樓層
jfmdam 發(fā)表于 2021-4-13 21:55
你初始化的時(shí)候總中斷開關(guān)沒(méi)開   ,T1不會(huì)產(chǎn)生波特率,ES也沒(méi)開,串口中斷不開怎么接收數(shù)據(jù)呢????

  ...

不行哎
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表