Đây là RCC:
Code:
void RCC_Init(){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); }
Code:
void GPIO_Init(){ GPIO_InitTypeDef gpioconf; gpioconf.GPIO_Speed=GPIO_Speed_50MHz; gpioconf.GPIO_Mode=GPIO_Mode_IN_FLOATING; gpioconf.GPIO_Pin=GPIO_Pin_10; GPIO_Init(GPIOA,&gpioconf); gpioconf.GPIO_Mode=GPIO_Mode_AF_PP; gpioconf.GPIO_Pin=GPIO_Pin_9; GPIO_Init(GPIOA,&gpioconf); }
Code:
void USART_Init(){ USART_InitTypeDef usartconf; usartconf.USART_BaudRate=9600; usartconf.USART_Mode=USART_Mode_Rx | USART_Mode_Tx; usartconf.USART_Parity=USART_Parity_No; usartconf.USART_StopBits=USART_StopBits_1; usartconf.USART_WordLength=USART_WordLength_8b; usartconf.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_Init(USART1,&usartconf); USART_Cmd(USART1,ENABLE); }
Code:
int main(){ SystemInit(); RCC_Init(); GPIO_Init(); USART_Init(); while(1){ USART_SendData(USART1,'0'); for(int i=0;i<50000;i++); } }