switch 语句困惑?

2019-03-24 18:59发布

#include <reg52.h>
sbit ENLED = P1^4;
sbit ADDR3 = P1^3;
sbit ADDR2 = P1^2;
sbit ADDR1 = P1^1;
sbit ADDR0 = P1^0;

unsigned char code Ledcode[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
unsigned char val=0;
// 延时
void delay(unsigned int i)
{
while (i--);
}

main()
{
unsigned int val=0, n=0;

while (1)
{
  n++;
  if (n >13)
  {
   n = 0;
   if (val >= 9)
    val = 0;
   else
    val++;
   P0 = Ledcode[val];
  }
  switch (n%6)
  {
   case 0:
    ADDR0 = 0;
    ADDR1 = 0;
    ADDR2 = 0;
    break;
   case 1:
    ADDR0 = 1;
    ADDR1 = 0;
    ADDR2 = 0;
    break;
   case 2:
    ADDR0 = 0;
    ADDR1 = 1;
    ADDR2 = 0;
    break;
   case 3:
    ADDR0 = 1;
    ADDR1 = 1;
    ADDR2 = 0;
    break;
   case 4:
    ADDR0 = 0;
    ADDR1 = 0;
    ADDR2 = 1;
    break;
   case 5:
    ADDR0 = 1;
    ADDR1 = 0;
    ADDR2 = 1;
    break;
  }
// delay(100);
}
}
以上程序运行没问题,仿真单步 case 0: case 2:中44,45,54,55几句不执行如图?哪里错误?请教! 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。