新手入门
- 积分
- 8
- 金钱
- 8
- 注册时间
- 2017-7-26
- 在线时间
- 1 小时
|
发表于 2017-7-26 09:21:40
|
显示全部楼层
void usart1_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 ,ENABLE);
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA ,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;//íÆíìêä3ö
GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_UP;//éÏà-
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
USART_InitStructure .USART_BaudRate =9600;
USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None ;//ûóDó2¼t¿ØÖÆá÷
USART_InitStructure .USART_Mode =USART_Mode_Rx |USART_Mode_Tx;
USART_InitStructure .USART_Parity =USART_Parity_No ;//ûóDÆæżD?Ñéλ
USART_InitStructure.USART_StopBits =USART_StopBits_1;
USART_InitStructure.USART_WordLength =USART_WordLength_8b ;//êy¾Y3¤¶è8λ
USART_Init (USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);//'®¿úê1Äü
}
int main ()
{
unsigned char a[26]={65,66,67};
unsigned char i;
delay_init(168);
usart1_init();
// led_init();
LED_Init();
while(1)
{
for(i=0;i<3;i++)
{
USART_SendData (USART1,a);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
// GPIO_ResetBits(GPIOF,GPIO_Pin_9);
LED0=!LED0;
}
delay_ms(1000);
}
} |
|