/* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" #include "misc.h"
__IO bool Time_Interval_OK; __IO uint16_t Sec; __IO uint16_t Min; __IO uint16_t Hour;
/* -----------------------------------------------*/ /************************************************* 函数: void RCC_Config(void) 功能: 配置系统时钟 参数: 无 返回: 无 **************************************************/ void RCC_Configuration(void) { /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); /* Enable GPIO clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); /* Enable UART clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); } /************************************************* 函数: void NVIC_Configuration(void) 功能: 切套向量中断控制寄存器 参数: 无 返回: 无 **************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Configure the NVIC Preemption Priority Bits */ NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; /* Enable the USART1 Interrupt */ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
} /************************************************* 函数: void GPIO_Configuration(void) 功能: 端口锁定 参数: 无 返回: 无 **************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure UART_Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//GPIO_TxPin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure UART_Rx as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//GPIO_RxPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure);
} /************************************************* 函数: void USART_Configuration(void) 功能: 串口配置 参数: 无 返回: 无 **************************************************/ void USART_Configuration(void) {
USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 57600; //BaudRate USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8 Bits USART_InitStructure.USART_StopBits = USART_StopBits_1; //One Stop Bit USART_InitStructure.USART_Parity = USART_Parity_No ; // No parity USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//Hardware flow control disabled (RTS and CTS signals) USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // USART_Init(USART3, &USART_InitStructure); /* Configure the USART1 */ USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); /* Enable USART1 Receive and Transmit interrupts */ USART_Cmd(USART3, ENABLE); /* Enable the USART1 */ }
/************************************************* 函数: int main(void) 功能: 主函数 参数: 无 返回: 无 **************************************************/ int main(void) { RCC_Configuration(); NVIC_Configuration(); GPIO_Configuration(); USART_Configuration(); while (1) { USART_SendData(UART4, 0x55); } }
|