这个学习板的数码管是用P0显现笔划,P2选通每个字的
#include
#include
unsigned char data dis_digit;
unsigned char code dis_code[11] =
{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0xFF}; //共阳极数码管
unsigned char data dis_buf[10];
unsigned char data dis_index;
unsigned char i = 0, j = 0;
void main(void)
{
unsigned char i;
P0 = 0xFF;
P2 = 0xFF;
TMOD = 1;
TH0 = 0xFC;
TL0 = 0x17;
IE = 0x82;
for(i=0;i<=9;i++)
{
dis_buf[i] = dis_code[i];
}
dis_digit = 0xFE;
dis_index = 0;
TR0 = 1;
while(1);
}
void timer0() interrupt 1
//定时器0中止服务程序, 用于数码管的动态扫描
//dis_index–显现索引, 用于标识当时显现的数码管和缓冲区的偏移量
//dis_gigit–位选通道, 传送到P2口用于选通当时数码管的数值, 如为0xFE时选通P2.0口数码管
//dis_buf–显现缓冲区基地址
{
TH0 = 0xFC;
TL0 = 0x17;
P2 = 0xFF; //先封闭一切数码管
P0 = dis_buf[dis_index];
P2 = dis_digit;
dis_digit = _crol_(dis_digit, 1); //位选通道左移, 下次中止时选通下一位数码管
i++;
if (i==100)
{
j++;
i = 0;
if (j == 5)
{
dis_index++;
if (dis_index == 10)
{
dis_index = 0;
}
i = 0;
j = 0;
}
}
//dis_index &= 0x07; //8个数码管悉数扫描完, 重新开始
}