能发一个详细的程序吗?再解释一下相关的知识点,可以吗?我实在是不会了!求大神指教
打算不帮你的,今天有点闲帮你写一个参考程序,你的分数就5分,哎就帮你写一个把,程序可以显示65536, 但是串口一帧数据只有8位才255,要用两个字节数据链接来发送,FF FF 高八位在前,第八位在后,程序如下:
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**/
#include "REG52.H"
sbit delu = P2^6; //数码管段选
sbit wela = P2^7; //数码管位选
unsigned char code value_tab[] =
{
0x3F,
0x06,
0x5B,
0x4F,
0x66,
0x6D,
0x7D,
0x07,
0x7F,
0x6F
}; //0-9
unsigned int UARTBufByte;
unsigned char MEC_TEMP;
unsigned char ENT_BLER;
bit UART_Error;
bit Flag_Error;
/*
** 软件延时1ms子函数
**/
void Delay_1ms(unsigned int time)
{
unsigned int x, y;
for(x = time; x > 0; x--)
for(y = 120; y > 0; y--);
}
/*
** 数码管显示遥控器按键值子函数
**/
void Shumg_Display_dataCmd(unsigned int value_bai)
{
delu = 0;
P0 = value_tab[value_bai / 10000];
delu = 1;
delu = 0;
P0 = 0xFF;
wela = 0;
P0 = 0xFE;
wela = 1;
wela = 0;
Delay_1ms(3);
delu = 0;
P0 = value_tab[value_bai % 10000 / 1000];
delu = 1;
delu = 0;
P0 = 0xFF;
wela = 0;
P0 = 0xFD;
wela = 1;
wela = 0;
Delay_1ms(3);
delu = 0;
P0 = value_tab[value_bai % 1000 / 100];
delu = 1;
delu = 0;
P0 = 0xFF;
wela = 0;
P0 = 0xFB;
wela = 1;
wela = 0;
Delay_1ms(3);
delu = 0;
P0 = value_tab[value_bai % 100 / 10];
delu = 1;
delu = 0;
P0 = 0xFF;
wela = 0;
P0 = 0xF7;
wela = 1;
wela = 0;
Delay_1ms(3);
delu = 0;
P0 = value_tab[value_bai % 10];
delu = 1;
delu = 0;
P0 = 0xFF;
wela = 0;
P0 = 0xEF;
wela = 1;
wela = 0;
Delay_1ms(3);
}
void UART_RecevirBuf(void)
{
unsigned int i;
for(i = 0; i < 4000; i++)
{
if(RI)
{
ENT_BLER = SBUF;
RI = 0;
UART_Error = 0;
return;
}
}
UART_Error = 1;
}
int main(void)
{
PCON&= 0x7F;
TCON = 0x00;
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD; //波特率9600 晶振:11.0592
TL1 = 0xFD;
TR1 = 1;
ES = 1;
EA = 1;
while(1)
{
if(Flag_Error)
{
UARTBufByte = MEC_TEMP;
UARTBufByte <<= 8;
UARTBufByte |= ENT_BLER;
Flag_Error = 0;
}
//
Shumg_Display_dataCmd(UARTBufByte);
}
}
void UART_IRQ(void)interrupt 4
{
if(RI)
{
MEC_TEMP = SBUF;
RI = 0;
UART_RecevirBuf();
Flag_Error = 1;
if(UART_Error)return;
}
}
串口发送FF FF 显示65536
实在不好意思。能麻烦发一个完整的吗