高级会员
- 积分
- 626
- 金钱
- 626
- 注册时间
- 2020-11-21
- 在线时间
- 123 小时
|
发表于 2021-8-28 16:35:18
|
显示全部楼层
本帖最后由 xiaoqi976633690 于 2021-8-28 16:39 编辑
- <div class="blockcode"><blockquote>
- #include <iostm8s003F3.h>
- #include "usart.h"
- #include "stdio.h"
- #define uint unsigned int
- #define uchar unsigned char
- #define ulong unsigned long
- uint x;
- void delay_ms(ulong i)
- {
- while(i--);
-
- }
- int main( void )
- {
- CLK_CKDIVR_HSIDIV = 0; //时钟初始化 16mhz不分频
- UART1_Init(); //串口初始化
- UART1_Send_Str("hello world!\n\r");
- asm("rim");
- uint x=0,i;
- unsigned char number[]={'0','1','2','3','4','5','6','7','8','9'};
- uint n[]={1000,100,10,1};
- while(1)
- {
- x++;
- delay_ms(65535);
- UART1_Send_Str("x的值为:");
- for(i=0;i<4;i++)
- {
- switch(x/(n[i])%10) //提取千百十个位的数
- {
- case (0) : UART1_Send_Date8(number[0]);break;
- case (1) : UART1_Send_Date8(number[1]);break;
- case (2) : UART1_Send_Date8(number[2]);break;
- case (3) : UART1_Send_Date8(number[3]);break;
- case (4) : UART1_Send_Date8(number[4]);break;
- case (5) : UART1_Send_Date8(number[5]);break;
- case (6) : UART1_Send_Date8(number[6]);break;
- case (7) : UART1_Send_Date8(number[7]);break;
- case (8) : UART1_Send_Date8(number[8]);break;
- case (9) : UART1_Send_Date8(number[9]);break;
- }
-
- }
- UART1_Send_Str("\n\r");
- }
- }
复制代码
参考数码管的比较简单容易理解串口打印内容如下
[2021-08-28 16:37:24.764]
RX:x的值为:0234
[2021-08-28 16:37:25.033]
RX:x的值为:0235
[2021-08-28 16:37:25.310]
RX:x的值为:0236
[2021-08-28 16:37:25.579]
RX:x的值为:0237
[2021-08-28 16:37:25.856]
RX:x的值为:0238
[2021-08-28 16:37:26.127]
RX:x的值为:0239
[2021-08-28 16:37:26.402]
RX:x的值为:0240
[2021-08-28 16:37:26.688]
RX:x的值为:0241
|
|