|
|
在網(wǎng)上看到這種串口顯示方法,感覺(jué)挺方便就試了一下,但是有點(diǎn)不對(duì)勁,請(qǐng)大家?guī)兔纯催@樣寫(xiě)是不是對(duì)的.
單片機(jī)源程序如下:
- #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("大家好!歡迎學(xué)習(xí)單片機(jī)\n");
-
- printf("********************************\n");
- printf("hello world\n"); // 最簡(jiǎn)單輸出
- printf("How do you do!\n"); // 輸出換行符\n
- printf("歡迎學(xué)習(xí) STC51 單片機(jī)\n"); // 中文輸出
- printf("********************************\n");
- while(1)
- {
-
- }
- }
- //void Uart1_Rountine() interrupt 4
- //{
- // if(RI)
- // {
- // RI=0;
- // }
- // else if(TI)
- // {
- // TI=0;
- // }
- //}
復(fù)制代碼 |
|