sbit LS138A=P2^2;
sbit LS138B=P2^3;
sbit LS138C=P2^4;
unsigned int LedNumVal = 0 ,LedOut[8];
// 此表为 LED 的字模 // 0 1 2 3 4 5 6 7 8 9 A b c d E - L P U Hidden _ (20)
unsigned char code Disp_Tab[] = { ~0xC0,~0xF9,~0xA4,~0xB0,~0x99,~0x92,~0x82,~0xF8,~0x80,~0x90,~0x88,~0x83,~0xC6,~0xA1,~0x86,~0xbf,~0xc7,~0x8c,~0xc1, ~0xff, ~0xf7 };
void delay(unsigned int i)
{
char j;
for(i; i > 0; i--)
for(j = 200; j > 0; j--);
}
display()
{ unsigned char i;
LedOut[0]=Disp_Tab[LedNumVal%10000/1000];
LedOut[1]=Disp_Tab[LedNumVal%1000/100]&0x7f;
LedOut[2]=Disp_Tab[LedNumVal%100/10];
LedOut[3]=Disp_Tab[LedNumVal%10];
for( i=0; i<8; i++)
{ P0 = LedOut[i];
switch(i)
{
case 0S138A=0; LS138B=0; LS138C=0; break;
case 1S138A=1; LS138B=0; LS138C=0; break;
case 2S138A=0; LS138B=1; LS138C=0; break;
case 3S138A=1; LS138B=1; LS138C=0; break;
case 4S138A=0; LS138B=0; LS138C=1; break;
case 5S138A=1; LS138B=0; LS138C=1; break;
case 6S138A=0; LS138B=1; LS138C=1; break;
case 7S138A=1; LS138B=1; LS138C=1; break;
}
delay(150);
}
}
/********************************************************
* 主程序 *
********************************************************/
void main(void)
{
P0=0xff;
P1=0xff;
P2=0xff;
// IT0=0; //低电平触发
IT0=1; //下降沿触发
EX0=1;
while(1)
{
display();
}
}
/********************************************************
* INT0中断函数
(crazybc.com) *
********************************************************/
void counter(void) interrupt 0
{
// unsigned char x;
EX0=0;
LedNumVal++; //中断计数
EX0=1;
}
/********************************************************/
|