高手来练练手
时间:10-02
整理:3721RD
点击:
大家来帮我纠纠错的哪里,我的本意是想通过笔记本下发命令显示数字,然后数码管显示数字,但是我每次发送数字,数码管总是显示乱码,全亮,请问原因是什么?
#include<reg52.h>
#include"usual.h"
void show_shu(uint8 num);
uint8 num;
uint8 table[] = {
0xC0,0XF9,0XA4,0XB0,0X99,
0X92,0X82,0XF8,0X80,0X90
}; //共阳数码管 0-9
void UART_init(void) //串口初始化
{
SCON = 0X50;
TMOD = 0X20;
TH1 = 0XFD;
TL1 = 0XFD;
TR1 = 1;
ES = 1;
EA = 1;
}
void main()
{
UART_init();
ADDR3 = 1; ENLED = 0;
while(1)
{
show_shu(num);
}
}
void uart_interrupt() interrupt 4 //串口中断子程序
{
if(TI)
{
TI = 0;
}
if(RI)
{
RI =0;
num = SBUF;
}
}
void show_shu(uint8 num) //数码管刷新程序
{
static uint8 j = 0;
switch(j)
{
case 0 : P0 = 0XFF; ADDR0 = 0; ADDR1 = 0; ADDR2 = 0; P0 = table[num]; j++; break; //ADDR0~3是38译码器引脚
case 1 : P0 = 0XFF; ADDR0 = 1; ADDR1 = 0; ADDR2 = 0; P0 = table[num+1];j++;break;
}
if(j == 2)
j = 0;
}
#include<reg52.h>
#include"usual.h"
void show_shu(uint8 num);
uint8 num;
uint8 table[] = {
0xC0,0XF9,0XA4,0XB0,0X99,
0X92,0X82,0XF8,0X80,0X90
}; //共阳数码管 0-9
void UART_init(void) //串口初始化
{
SCON = 0X50;
TMOD = 0X20;
TH1 = 0XFD;
TL1 = 0XFD;
TR1 = 1;
ES = 1;
EA = 1;
}
void main()
{
UART_init();
ADDR3 = 1; ENLED = 0;
while(1)
{
show_shu(num);
}
}
void uart_interrupt() interrupt 4 //串口中断子程序
{
if(TI)
{
TI = 0;
}
if(RI)
{
RI =0;
num = SBUF;
}
}
void show_shu(uint8 num) //数码管刷新程序
{
static uint8 j = 0;
switch(j)
{
case 0 : P0 = 0XFF; ADDR0 = 0; ADDR1 = 0; ADDR2 = 0; P0 = table[num]; j++; break; //ADDR0~3是38译码器引脚
case 1 : P0 = 0XFF; ADDR0 = 1; ADDR1 = 0; ADDR2 = 0; P0 = table[num+1];j++;break;
}
if(j == 2)
j = 0;
}
大家帮忙看看啊,纠结很久了
刷新程序没加延时。
延时应该如何加入?不是很明白,谢谢
在线等待好心人士帮忙更改下