#include "stdio.h" //sprintf相关函数支持的头文件。 #include <STDARG.H> //多参数函数支持的头文件。 #define UART_PRINTF_EN 1 /* ******************************************** * 函数名称 : bsp_uart1_init * 函数说明 : bsp_uart1_init * 备 注 : **********************************************/ void bsp_uart1_init(void) { P16_PushPull_Mode; //TX引脚 P02_Quasi_Mode; //RX引脚 SCON_1=0x50;//设置串口1工作在模式1(8位数据,不带奇偶校验) clr_TR3; //停止定时器3 RH3=0xFF; RL3=0x94; //9600 set_TR3; //使能定时器3 set_ES_1; //使能串口1中断 RS485_UART1_REVC; uart1_busy = 0; } /********************************************* * 函数名称 : uart_char * 函数说明 : id 0:串口0, 1:串口1, ch:要发送的字符 * 备 注 : **********************************************/ void uart_char(u8 id,u8 ch) { switch (id) { case 0: // RS485_UART0_SEND;//使能485发送 // uart0_busy = 1; // SBUF=ch; // while(uart0_busy); // RS485_UART0_REVC;//使能485接收 break; case 1: // RS485_UART1_SEND; uart1_busy = 1; SBUF_1=ch; while(uart1_busy); // RS485_UART1_REVC; break; default: break; } } /********************************************* * 函数名称 : uart_string * 函数说明 : id 0:串口0, 1:串口1, str:要发送的字符串 * 备 注 : **********************************************/ void uart_string(u8 id,u8 * str) { while(*str){ uart_char(id,*str++); } } #ifdef UART_PRINTF_EN /********************************************* * 函数名称 : uart_string 串口打印函数。 * 函数说明 : id 0:串口0, 1:串口1, str:要发送的格式化字符串 * 备 注 : **********************************************/ void uart_printf(u8 id,const char * str,...) { char xdata buf[32]; //注意数组缓存的大小,打印字符超过数组大小会导致出现死机或者其它问题 va_list vp; va_start(vp, str); vsprintf(buf,str,vp); va_end(vp); uart_string(id,buf); } #endif /********************************************* * 函数名称 : Uart1_ISR * 函数说明 : 串口1中断处理 * 备 注 : **********************************************/ void Uart1_ISR(void) interrupt 15 { if(RI_1) { RI_1=0; // uart1_receive_callback(); } if(TI_1) { uart1_busy = 0; TI_1=0; } }
举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
时间类勋章
人才类勋章
发帖类勋章
等级类勋章
22
1575
3
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号