|
有大佬知道为什么我这接收端接收到的数据在为什么在1602上不显示吗?这是部分程序,我自己写的感觉问题很大,lcd驱动程序就不放上来了,下面有仿真图
单片机源程序如下:
- #include <reg51.h>
- #include "lcd.h"
- void LcdInit();
- void LcdDisplay();
- void delay(unsigned int i);
- void UART_T();
- void UART_init(void);
- uchar TIME[7];
- unsigned char receiveData=0;
- char r = 0;
- unsigned char rec[7];
- void UART_init(void)
- {
- SCON=0X50;
- TMOD=0X20;
- PCON=0x80;
- TH1=0XF3;
- TL1=0XF3;
- TR1=1;
- TI=0;
- ES=1;
- EA=1;
- }
- void UART_T() interrupt 4
- {
- if(RI)
- {
- receiveData = SBUF;
- if((receiveData==0x59))
- {
- r = 0;
- }
- rec[r] = receiveData;
- r++;
- while(!RI);
- RI = 0;
- }
- RI = 0;
- }
- void main()
- {
- LcdInit();
- delay(1000);
- UART_init();
- while (1)
- {
- TIME[0]=rec[0];
- TIME[1]=rec[1];
- TIME[2]=rec[2];
- TIME[3]=rec[3];
- TIME[4]=rec[4];
- TIME[5]=rec[5];
- TIME[6]=rec[6];
- delay(100);
- LcdDisplay();
- }
- }
- void LcdDisplay()
- {
- LcdWriteCom(0x80 + 0x40);
- LcdWriteData('0'+TIME[4] / 16);
- LcdWriteData('0' + (TIME[4] & 0x0f));
- LcdWriteData(':');
- LcdWriteData('0' + TIME[5] / 16);
- LcdWriteData('0' + (TIME[5] & 0x0f));
- LcdWriteData(':');
- LcdWriteData('0' + TIME[6] / 16);
- LcdWriteData('0' + (TIME[6] & 0x0f));
- LcdWriteCom(0x80);
- LcdWriteData('2');
- LcdWriteData('0');
- LcdWriteData('0' + TIME[0] / 16);
- LcdWriteData('0' + (TIME[0] & 0x0f));
- LcdWriteData('-');
- LcdWriteData('0' + TIME[1] / 16);
- LcdWriteData('0' + (TIME[1] & 0x0f));
- LcdWriteData('-');
- LcdWriteData('0' + TIME[2] / 16);
- LcdWriteData('0' + (TIME[2] & 0x0f));
- LcdWriteCom(0x8B);
- LcdWriteData('0' + (TIME[3] & 0x07));
- }
- void delay(unsigned int i)
- {
- while(i--);
- }
复制代码 |
|