<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include <reg52.h></span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include "delay.h"</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include <stdio.h></span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> uart_init() { SCON = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0x50</span>; TMOD |= <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0x20</span>; TH1 = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0xfd</span>; TR1 = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>; } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> uart_send_byte(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> byte) { SBUF = byte; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span>(!TI); TI = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//ÊÖ¶¯Çå0</span> } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> uart_send_str(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> *s) { <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span>((*s) != <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'\0'</span>) { uart_send_byte(*s); s++; } } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> main() { <span c
单片机中串口显示数字1至10
最新推荐文章于 2024-05-18 16:54:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)