//目的:显示一个固定的数字
//有几个问题没搞明白,详见scan程序注释
# include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit addr0 = P1^0;
sbit addr1 = P1^1;
sbit addr2 = P1^2;
sbit addr3 = P1^3;
sbit enled = P1^4;
uchar a, b, c = 0;
uchar number[16] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xa7,0xa1,0x86,0x8e
};
void scan (void);
void main (void)
{
addr3 = 1;
while (1)
{
scan();
}
}
void scan (void)
{
//uchar a,b,c; 为什么不能定义为局部变量
uchar i = 158;//要显示的数字
enled = 1;// 这句和上边那句(uchar i = 158)位置为什么不能调啊
a = i/100;
addr0 = 1;
addr1 = 0;
addr2 = 1;
P0 = number[a]; //显示第一位
enled = 0;
enled = 1;
b = i%100/10;
addr0 = 0;
addr1 = 0;
addr2 = 1;
P0 = number[b]; //显示第二位
enled = 0;
enled = 1;
c = i%100%10;
addr0 = 1;
addr1 = 1;
addr2 = 0;
P0 = number[c]; //显示第三位
enled = 0;
}
|