为什么a == 255这种判断无效啊?
写了这么一个东西在8位数码管上滚动显示数字0 - 9,但是发现运行一段时间后就开始显示乱七八糟的东西了。
#include<reg52.h>
sbit LATCH1 = P2 ^ 2;//段锁存
sbit LATCH2 = P2 ^ 3;//位锁存
char code digit[8] = {0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};//0 - 7 位
char code num[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//数字 0 - 9
void delay(unsigned int i);
void main()
{
char a = 0;
while (1)
{
P1 = digit[a % 8];
LATCH2 = 1;
LATCH2 = 0;
P1 = num[a % 10];
LATCH1 = 1;
LATCH1 = 0;
delay(5000);
}
}
void delay(unsigned int i)
{
while(i--);
}
while (1)
{
P1 = digit[a % 8];
LATCH2 = 1;
LATCH2 = 0;
P1 = num[a % 10];
LATCH1 = 1;
LATCH1 = 0;
a == 255 ? a = 0 : a++;//这里防止a溢出
delay(5000);
}
if (a == 255)
{
a = 0;
}else
{
a++;
}