完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家有空帮我看下我这为什么只能接收一个字符 而接收字符串 串口就会出现乱码问题,
一下是我的代码 #include "N76E003.h" #include "SFR_Macro.h" #include "Common.h" #include "Delay.h" #include "Function_define.h" #include "string.h" #include "intrins.h" #define BUFFER_SIZE 16 #define N 2 char UART_BUFFER[BUFFER_SIZE],temp,i; UINT16 u16CNT=0,u16CNT1=0; bit riflag; /** * FUNCTION_PURPOSE: serial interrupt, echo received data. * FUNCTION_INPUTS: P0.7(RXD) serial input * FUNCTION_OUTPUTS: P0.6(TXD) serial output */ void SerialPort0_ISR(void) interrupt 4 { if(RI) { RI = 0; UART_BUFFER[u16CNT++] = SBUF; if(u16CNT==N) { riflag = 1; } } } /************************************************************************************************************ * Main function ************************************************************************************************************/ void main (void) { P12_PushPull_Mode; P06_Quasi_Mode; P07_Quasi_Mode; SCON = 0xD0; // Special setting the mode 3 and TMOD |= 0x20; //Timer1 Mode1 set_SMOD; //UART0 Double Rate Enable set_T1M; clr_BRCK; //Serial port 0 baud rate clock source = Timer1 TH1 = 256 - (1000000/115200+1); /*16 MHz */ set_TR1; set_RB8; //This bit is for setting the stop bit 2 high/low status, clr_TI; set_ES; //enable UART interrupt set_EA; //enable global interrupt while(1) { if(riflag==1) { ES = 0; for(temp=0;temp { SBUF=UART_BUFFER[temp]; while(!TI); TI=0; } temp=0; ES = 1; riflag = 0; } } } 帮指点一下,谢谢 |
|
相关推荐
1个回答
|
|
找到问题了,我把波特率改为9600就行了
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
854 浏览 2 评论
【youyeetoo X1 windows 开发板体验】+ 影音处理和AI模型移植
716 浏览 5 评论
I.MX6ULL-飞凌 ElfBoard ELF1板卡- 移植zbar的方法
879 浏览 0 评论
1553 浏览 3 评论
由于 Windows 无法加载这个设备所需的驱动程序,导致这个设备工作异常?
2444 浏览 1 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
3728 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-3-29 08:21 , Processed in 0.631168 second(s), Total 71, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 深圳华秋电子有限公司
电子发烧友 (电路图) 粤公网安备 44030402000349 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号