void usart1_receivedata(u8 usart1_buf[100])
{
u8 *rev_buf=usart1_buf;
u8 addr=0; //地址偏移量
u8 revice_ok=0;//接收完成标志
u8 data;
if(data=='\0')//接收完成
{
rev_buf[addr]='\0';
addr=0;
revice_ok=1;
}
else//正常接收
{
if(USART1->SR & 1<<5)
data=USART1->DR;//读取同时会清除标志
rev_buf[addr++]=data;
}
}
int main()
{
u32 baud=115200;
u8 temp,i;
u8 usart1_buf[100]={0};
beep_init();
led_init();
key_init();
usart1_init(baud);
while(1)
{
if(key_ass())
{
USART1->DR='A';
while(!(USART1->SR & 1<<7)){}
USART1->DR='B';
while(!(USART1->SR & 1<<7)){}
USART1->DR='C';
while(!(USART1->SR & 1<<7)){}
USART1->DR='D';
while(!(USART1->SR & 1<<7)){}
}
usart1_receivedata(usart1_buf);
if(strcmp((const char *)usart1_buf,"led2on")==0)
led2(0);
}
}
|