#include
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几句不执行如图?哪里错误?请教!
没看出来有问题
[ 本帖最后由 huo_hu 于 2012-9-7 12:08 编辑 ]
我用kEILl调试单步就如上图,程序没看出错,问题在哪?
这是因为你的case 0: case 2:永远也到达不了
http://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
回复 5楼 ddllxxrr 的帖子
他说的是44,45,54,55那几句被执行,case 0,case 2是去了的哦。
回复 7楼 lcofjp 的帖子
对,看看汇编代码,有可能是汇编代码的问题。
回复 10楼 虚V界 的帖子
感谢你的答案,佩服!!