|
在網上看到這種串口顯示方法,感覺挺方便就試了一下,但是有點不對勁,請大家幫忙看看這樣寫是不是對的.
單片機源程序如下:
- #include "STC15.h"
- #include <stdio.h>
- typedef unsigned char u8;
- typedef unsigned short u16;
- typedef unsigned long u32;
- void port_mode() // 端口模式
- {
- P0M1=0x00; P0M0=0x00;P1M1=0x00; P1M0=0x00;
- P2M1=0x00; P2M0=0x00;P3M1=0x00; P3M0=0x00;
- P4M1=0x00; P4M0=0x00;P5M1=0x00; P5M0=0x00;
- }
- void Uart1_Init() //串口初始化
- {
- SCON|=0x50;
- AUXR|=0X15;
- T2H=0XFC;
- T2L=0XF3;
- ES=1;
- EA=1;
- TI=1;
- }
- void main()
- {
- port_mode();
- Uart1_Init();
- printf("大家好!歡迎學習單片機\n");
-
- printf("********************************\n");
- printf("hello world\n"); // 最簡單輸出
- printf("How do you do!\n"); // 輸出換行符\n
- printf("歡迎學習 STC51 單片機\n"); // 中文輸出
- printf("********************************\n");
- while(1)
- {
-
- }
- }
- //void Uart1_Rountine() interrupt 4
- //{
- // if(RI)
- // {
- // RI=0;
- // }
- // else if(TI)
- // {
- // TI=0;
- // }
- //}
復制代碼 |
|