/** ****************************************************************************** * @file USART/Printf/main.c * @author MCD Application Team * @version V3.3.0 * @date 04/16/2010 * @brief Main program body ****************************************************************************** * @copy * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2> */ /* Includes ------------------------------------------------------------------*/#include "stm32f10x.h"#include "stm32_eval.h"#include <stdio.h>/** @addtogroup STM32F10x_StdPeriph_Examples * @{ *//** @addtogroup USART_Printf * @{ */ /* Private typedef -----------------------------------------------------------*//*神州III号LED灯相关定义*/#define RCC_GPIO_LED RCC_APB2Periph_GPIOF /*LED使用的GPIO时钟*/#define LEDn 4 /*神舟III号LED数量*/#define GPIO_LED GPIOF /*神舟III号LED灯使用的GPIO组*/#define DS1_PIN GPIO_Pin_6 /*DS1使用的GPIO管脚*/#define DS2_PIN GPIO_Pin_7/*DS2使用的GPIO管脚*/#define DS3_PIN GPIO_Pin_8 /*DS3使用的GPIO管脚*/#define DS4_PIN GPIO_Pin_9/*DS4使用的GPIO管脚*//* Private macro -------------------------------------------------------------*//* Private variables ---------------------------------------------------------*/USART_InitTypeDef USART_InitStructure;/* Private function prototypes -----------------------------------------------*/#ifdef __GNUC__ /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)#else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)#endif /* __GNUC__ */ /* Private functions ---------------------------------------------------------*//******************************************************************************** Function Name : Delay* Description : Inserts a delay time.* Input : nCount: specifies the delay time length.* Output : None* Return : None*******************************************************************************/void Delay(vu32 nCount){ for(; nCount != 0; nCount--);}/** * @brief Main program * @param None * @retval None */int main(void){ /*LED管脚初始化*/ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE); GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_LED, &GPIO_InitStructure); GPIO_SetBits(GPIO_LED, DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN);/*关闭LED灯*/ /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ /*串口参数配置*/ USART_InitStructure.USART_BaudRate = 115200; /*设置波特率为115200*/ USART_InitStructure.USART_WordLength = USART_WordLength_8b; /*设置数据位为8位*/ USART_InitStructure.USART_StopBits = USART_StopBits_1; /*设置停止位为1位*/ USART_InitStructure.USART_Parity = USART_Parity_No; /*无奇偶校验*/ USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /*没有硬件流控*/ USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /*发送与接收*/ /*完成串口COM1的时钟配置、GPIO配置,根据上述参数初始化并使能*/ STM_EVAL_COMInit(COM1, &USART_InitStructure); printf("\n\r---------------------------------------------\n "); printf("\n\rWWW.ARMJISHU.COM\n "); printf("\n\r神舟III号 串口1发送实验程序\n"); while (1) { GPIO_ResetBits(GPIO_LED, DS1_PIN);Delay(0x3FFFFF); GPIO_SetBits(GPIO_LED, DS1_PIN);Delay(0x3FFFFF); //printf("\n\r神舟III号 串口1测试程序\n"); USART_SendData(USART1,26); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE) == RESET); }}/** * @brief Retargets the C library printf function to the USART. * @param None * @retval None */PUTCHAR_PROTOTYPE{ /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ USART_SendData(EVAL_COM1, (uint8_t) ch); /*发送一个字符函数*/ /* Loop until the end of transmission */ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)/*等待发送完成*/ { } return ch;}#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(uint8_t* file, uint32_t 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/** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
下载STM32(神舟III号 串口1发送实验程序)用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论