用定时器中断遇到的问题

2019-08-17 10:02发布

用的52单片机的定时器0中断,在中断函数使用如下代码时,在串口助手中不能看到发送的数据
    static unsigned int number=0;
    number++;
    if(number>=500)
    {
      Uart1SendChar(number>>8);
      Uart1SendChar(number);
      number=0;
    }
当代码调整如下时:
    static unsigned int number=0;
    number++;
   Uart1SendChar(number>>8);
    Uart1SendChar(number);
通过串口助手接收的数据为
00 2B 00 2C 00 2D 00 2E 00 2F 00 30 00 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 3A 00 3B 00 3C 00 3D 00 3E 00 3F 00 40 00 41 00 42 00 43 00 44 00 45 00 46 00 47 00 48 00 49 00 4A 00 4B 00 4C 00 4D 00 4E 00 4F 00 50 00 51 00 52 00 53 00 54 00 55 00 56 00 57 00 58 00 59 00 5A 00 5B 00 5C 00 5D 00 5E 00 5F 00 60 00 61 00 62 00 63 00 64 00 65 00 66 00 67 00 68 00 69 00 6A 00 6B 00 6C 00 6D 00 6E 00 6F 00 70 00 71 00 72 00 73 00 74 00 75 00 76 00 77 00 78 00 79 00 7A 00 7B 00 7C 00 7D 00 7E 00 7F 00 80 00 81 00 82 00 83 00 84 00 85 00 86 00 87 00 88 00 89 00 8A 00 8B 00 8C 00 8D 00 8E 00 8F 00 90 00 91 00 92 00 93 00 94 00 95 00 96 00 97 00 98 00 99 00 9A 00 9B 00 9C 00 9D 00 9E 00 9F 00 A0 00 A1 00 A2 00 A3 00 A4 00 A5 00 A6 00 A7 00 A8 00 A9 00 AA 00 AB 00 AC 00 AD 00 AE 00 AF 00 B0 00 B1 00 B2 00 B3 00 B4 00 B5 00 B6 00 B7 00 B8 00 B9 00 BA 00 BB 00 BC 00 BD 00 BE 00 BF 00 C0 00 C1 00 C2 00 C3 00 C4 00 C5 00 C6 00 C7 00 C8 00 C9 00 CA 00 CB 00 CC 00 CD 00 CE 00 CF 00 D0 00 D1 00 D2 00 D3 00 D4 00 D5 00 D6 00 D7 00 D8 00 D9 00 DA 00 DB 00 DC 00 DD 00 DE 00 DF 00 E0 00 E1 00 E2 00 E3 00 E4 00 E5 00 E6 00 E7 00 E8 00 E9 00 EA 00 EB 00 EC 00 ED 00 EE 00 EF 00 F0 00 F1 00 F2 00 F3 00 F4 00 F5 00 F6 00 F7 00 F8 00 F9 00 FA 00 FB 00 FC 00 FD 00 FE 00 FF 01 00 01 01 01 02 01 03 01 04 01 05 01 06 01 07 01 08 01 09 01 0A 01 0B 01 0C 01 0D 01 0E 01 0F 01 10 01 11 01 12 01 13 01 14 01 15 01 16 01 17 01 18 01 19 01 1A 01 1B 01 1C 01 1D 01 1E 01 1F 01 20 01 21 01 22 01 23 01 24 01 25 01 26 01 27 01 28 01 29 01 2A 01 2B 01 2C 01 2D 01 2E 01 2F 01 30 01 31 01 32 01 33 01 34 01 35 01 36 01 37 01 38 01 39 01 3A 01 3B 01 3C 01 3D 01 3E 01 3F 01 40 01 41 01 42 01 43 01 44 01 45 01 46 01 47 01 48 01 49 01 4A 01 4B 01 4C 01 4D 01 4E 01 4F 01 50 01 51 01 52 01 53 01 54 01 55 01 56 01 57 01 58 01 59 01 5A 01 5B 01 5C 01 5D 01 5E 01 5F 01 60 01 61 01 62 01 63 01 64 01 65 01 66 01 67 01 68 01 69 01 6A 01 6B 01 6C 01 6D 01 6E 01 6F 01 70 01 71 01 72 01 73 01 74 01 75 01 76 01 77 01 78 01 79 01 7A 01 7B 01 7C 01 7D 01 7E 01 7F 01 80 01 81 01 82 01 83 01 84 01 85 01 86 01 87 01 88 01 89 01 8A 01 8B 01 8C 01 8D 01 8E 01 8F 01 90 01 91 01 92 01 93 01 94 01 95 01 96 01 97 01 98 01 99 01 9A 01 9B 01 9C 01 9D 01 9E 01 9F 01 A0 01 A1 01 A2 01 A3 01 A4 01 A5 01 A6 01 A7 01 A8

想问下是什么原因导致不能进行判断呢?

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
南有乔木
1楼-- · 2019-08-17 13:27
 精彩回答 2  元偷偷看……
275891381
2楼-- · 2019-08-17 16:34
volatile 修饰你的变量试试,不行你就上传全部代码吧,不然没法看

一周热门 更多>