标题:
STM8F103串口发送及接收程序
[打印本页]
作者:
1092648746
时间:
2019-3-6 18:45
标题:
STM8F103串口发送及接收程序
最近在用STM8做东西,看到论坛上关于STM8的例程少之又少,故发一个串口例程
串口1波特率9600,不断发送数据,同时可响应接收数据,注释较少。
开发环境为IAR,可直接烧录生成的hex文件。
tu1.JPG
(76.75 KB, 下载次数: 77)
下载附件
2019-3-6 18:42 上传
tu2.JPG
(74.89 KB, 下载次数: 77)
下载附件
2019-3-6 18:43 上传
单片机源程序如下:
/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#define LED_GPIO_PORT (GPIOB)
#define LED_GPIO_PINS (GPIO_PIN_5)
void Delay(uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
void Init_UART1(void)
{
UART1_DeInit();
UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
enableInterrupts();
UART1_Cmd(ENABLE);
}
void Send(uint16_t dat)
{
while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));
UART1_SendData9(dat);
}
void main(void)
{
uint8_t i=0;
uint16_t j=0;
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
Init_UART1();
/* Infinite loop */
while (1)
{
for(j=0;j<60000;j++);
Send(i);
//UART1_SendData8(0x01);
i++;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
复制代码
所有资料51hei提供下载:
UARTX-RX.7z
(3.96 MB, 下载次数: 60)
2019-3-6 23:59 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
剑剑剑剑来!
时间:
2021-3-18 17:31
您好,我是一名机械电子工程专业的学习者,由于选择了总线传感器的组网与程序设计这一项目,与所学专业知识有偏差,现如今十分迷茫。但在看到了您对传感器驱动一帖子的评论后,逐渐找了一点灵感,想与您请教交流。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1