匿名
未登录
登录
丢石头百科
搜索
查看“STM8 UART接收中断程序”的源代码
来自丢石头百科
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
STM8 UART接收中断程序
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
<table border="0" cellpadding="0" cellspacing="0" style="color: rgb(72, 61, 139); font-family: Arial, 新宋体, 微软雅黑; font-size: 12px;" width="780"><tbody><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">系统功能</th></tr></tbody></table> 使用STM8的USART进行自发自收(将发送引脚RXD短接到接收引脚TXD),发出数据:0,1,2。。。数据,能接收到自己发出的数据:0,1,2。。。使用LED作出简单指示! </th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">硬件设计</th></tr></tbody></table> [[File:STM8_LED_PB.jpg]] LED控制电路原理图 [[File:STM8_UART.jpg]] UART电路原理图</th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">软件设计</th></tr></tbody></table> /********************************************************************* 微 雪 电 子 WaveShare <a class="Blue_2_12px_" href="https://{{SERVERNAME}}/" style="color: rgb(7, 66, 184);">http://www.waveShare.net 目标系统: 基于STM8单片机 应用软件: Cosmic CxSTM8 说 明: 若用于商业用途,请保留此段文字或注明代码来源 深 圳 市 微 雪 电 子 有 限 公 司 保 留 所 有 的 版 权 *********************************************************************/ /*---------------------------------------------------------------------- 实验内容: USART自发自收,使用PB口的LED指示接收到的数据,观察是否与发送的数据一致。 ---------------------------------------------------------------------- 硬件连接: 将MCU.RXD与MCU.TXD使用短路帽短接,将PB口的LED指示灯使能开关切换到"ON"状态。 ----------------------------------------------------------------------*/ #include <STM8S207S8.h> #define LED_DDR PB_DDR #define LED_PORT PB_ODR #define LED_CR1 PB_CR1 #define LED_CR2 PB_CR2 void Init_UART3(void) { UART3_CR1=0x00; UART3_CR2=0x00; UART3_CR3=0x00; // 设置波特率,必须注意以下几点: // (1) 必须先写BRR2 // (2) BRR1存放的是分频系数的第11位到第4位, // (3) BRR2存放的是分频系数的第15位到第12位,和第3位 // 到第0位 // 例如对于波特率位9600时,分频系数=2000000/9600=208 // 对应的十六进制数为00D0,BBR1=0D,BBR2=00 UART3_BRR2=0x00; UART3_BRR1=0x0d; UART3_CR2=0x2c;//允许接收,发送,开接收中断 } void UART3_sendchar(unsigned char c) { while((UART3_SR & 0x80)==0x00); UART3_DR=c; } @far @interrupt void UART3_Recv_IRQHandler (void) { unsigned char ch; ch=UART3_DR; LED_PORT=ch; return; } void main(void) { unsigned char i=0; LED_DDR=0XFF; LED_CR1=0XFF; LED_CR2=0X00; Init_UART3(); _asm("rim"); while(1) { UART3_sendchar(i); i++; }; } </th></tr><tr><th class="type_483D8B" scope="col" style="line-height: 20px; font-weight: normal; border-top-style: none;" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="120"><tbody><tr><th align="center" bgcolor="#698192" class="white_12px_b" height="20" scope="col" style="font-size: 12px; color: rgb(255, 255, 255); line-height: 20px; font-family: Arial, Helvetica, sans-serif;">系统调试</th></tr></tbody></table> 短接RXD与TXD能接收到自己发送的数据,断开短接没有接收到数据。 系统不断发送数据:0,1,2。。。若正常接收,将收到0,1,2。。。。 用LED作数据指示,LED往上加,说明系统程序正常执行。</th></tr></tbody></table>
返回至
STM8 UART接收中断程序
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
首页
首页
树莓派
主机
配件包
外壳
键鼠
电源
扩展板
显示屏
墨水屏
摄像模块
通信模块
继电器
电机驱动板
游戏机
产品分类
树莓派
Arduino
micro:bit
STM32
Espressif
WiFi模块
蓝牙模块
无线模块
LoRa模块
4G模块
GSM
GPRS
以太网
导航模块
北斗卫星
GPS
LCD
墨水屏
OLED
摄像头
USB模块
串口模块
RS232
RS485
CAN
传感器
温度模块
湿度模块
气压模块
继电器
电机模块
指纹模块
电平转换
音频模块
编程器
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志