#include "n76e003.h" #include "system.h" #include "tm1650.h" #include "stdio.h" #include "BC26.h" #include "string.h" #define CHARTAST 1 #define NUMTAST 2 #define MENUTAST 3 #define BUFLEN 32 //字符串长度 typedef struct _UART_BUF { char buf [BUFLEN+1]; unsigned int index ; }UART_BUF; bit HaveTast=0; unsigned char Uart0Cmd; int SET_BIT4=0X10; int CLR_BIT4=0XEF; UART_BUF buf_uart2; //给字符串数组分配空间 void Uart0_Init(void); void Uart0_Process(void); void Uart0_SendChar(unsigned char Udat); void Uart0_SendString(unsigned char *PBuf); void Clear_Buffer(void) //数组清空 { Delay_ms(30); buf_uart2.index=0; memset(buf_uart2.buf,1,BUFLEN); } void nbiot_receive_process_event(unsigned char ch ) //将字符依次存入数组 { if(buf_uart2.index >= BUFLEN) { buf_uart2.index = 0 ; } else{ buf_uart2.buf[buf_uart2.index] = ch; buf_uart2.index++; } } void USART2_IRQHandler() interrupt 4 { char temp; temp=SBUF; nbiot_receive_process_event(temp); 将SUBF依次存入数组 RI=0; //串口中断标志位 置0 } void main(void) { System_Init(); TM1650_Init(); ToDisplay__(); Uart0_Init(); MODIFY_HIRC_166(); //调整波特率 while(1) { Uart0_SendString(buf_uart2.buf); //打印字符串内容 Delay_ms(1000); } } void Uart0_Init(void) { SCON=0x50; //模式一,定时器,八位自动重装 ClrBits(TMOD,T1_GATE|T1_CT|T1_M0); SetBits(TMOD,T1_M1); SetBits(PCON,SMOD); SetBits(CKCON,T1M); ClrBits(T3CON,BRCK); TH1=256 - (1000000/115200+1); //波特率115200 16.6MHz TR1=1; ES=1; EA=1; P0_Quasi_Mode(PIN_6|PIN_7); } void Uart0_SendChar(unsigned char Udat) //串口发送单个字符 { SBUF=Udat; while(!TI); TI=0; } void Uart0_SendString(unsigned char *PBuf) //串口发送字符串 { while(*PBuf!='\0') { Uart0_SendChar(*PBuf); PBuf++; } } void MODIFY_HIRC_166(void) //调整时钟 { unsigned char hircmap0,hircmap1; unsigned int trimvalue16bit; if ((PCON&SET_BIT4)==SET_BIT4) { hircmap0 = RCTRIM0; hircmap1 = RCTRIM1; trimvalue16bit = ((hircmap0<<1)+(hircmap1&0x01)); trimvalue16bit = trimvalue16bit - 15; hircmap1 = trimvalue16bit&0x01; hircmap0 = trimvalue16bit>>1; TA=0XAA; TA=0X55; RCTRIM0 = hircmap0; TA=0XAA; TA=0X55; RCTRIM1 = hircmap1; PCON &= CLR_BIT4; } } [img][/img]
7_串口0接收发送字符串测试实验定时器1.zip
2020-7-24 09:35 上传
点击文件名下载附件
95.89 KB, 下载次数: 14
程序源码
收藏0 举报
643757107 发表于 2020-7-24 09:30 没看明白是什么问题,
新塘初级用户 发表于 2020-7-24 10:27 我整出来了,原来是没有清除TI
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
人才类勋章
发帖类勋章
等级类勋章
时间类勋章
6
36
0
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号