串口程序
單片機源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- int main(void)
- {
- u8 t=0;
- u8 len;
- u16 times=0;
- Stm32_Clock_Init(9);
- delay_init(72);
- uart_init(72,9600);
- LED_Init();
- while(1)
- {
- PrintHex(208);
- PrintLongInt(0xffffffff);
- PrintShortIntHex(3456);
- Prints("你好kk中國\r\n");
- if(USART_RX_STA&0x80)
- {
- len=USART_RX_STA&0x3f;
- // printf("\n你發送的消息為:\n");
- for(t=0;t<len;t++)
- {
- USART1->DR=USART_RX_BUF[t];
- while((USART1->SR&0x40)==0);
-
- }
- //printf("\n\n");
- USART_RX_STA=0;
- }
- else
- {
- times++;
- if(times%5000==0)
- {
- //printf("\n串口實驗\n");
- }
- //if(times%200==0)printf("請輸入數據,以回車鍵結束\n");
- delay_ms(20);
- }
- LED1=0;
- delay_ms(100);
- LED1= 1;
- // t++;
-
- }
- }
復制代碼
所有資料51hei提供下載:
串口.zip
(232.66 KB, 下載次數: 20)
2017-12-14 21:56 上傳
點擊文件名下載附件
stm32寄存器程序 下載積分: 黑幣 -5
|