OK 我贴出来 , 麻烦大家了
#include "usart.h"
uint8_t data_u;
void delay_ss1(uint16_t k)
{
uint16_t i,j;
for(i=k;i>0;i--)
for(j=255;j>0;j--);
}
void usart_main(void)
{
while(1)
{
if((usart_flag_get(USART0,USART_FLAG_RBNE))==1)
{
data_u=usart_data_receive(USART0);
if(data_u==0x32)
{
delay_ss1(10);
gpio_bit_set(GPIOB,GPIO_PIN_0);
usart_data_transmit(USART0,data_u);
while(!(usart_flag_get(USART0,USART_FLAG_TC)));
delay_ss1(50);
gpio_bit_reset(GPIOB,GPIO_PIN_0);
}
}
}
}
void usart_init(void)
{
rcu_periph_clock_enable(RCU_USART0);
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0); //485¿ØÖÆÒý½Å
usart_baudrate_set(USART0, 19200);
usart_halfduplex_enable(USART0);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_enable(USART0);
usart_data_receive(USART0);
gpio_bit_set(GPIOB,GPIO_PIN_0);
delay_ss1(50);
usart_data_transmit(USART0,0X33);
while(!(usart_flag_get(USART0,USART_FLAG_TC)));
delay_ss1(50000);
delay_ss1(50000);
gpio_bit_reset(GPIOB,GPIO_PIN_0);
delay_ss1(5000);
}
|