[cpp]
#include<reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ENLED1=P1^4;
sbit ENLED2=P1^3;
void display();
void int_init();
main()
{
P0=0x00;
ENLED1=0;
ENLED2=0;
//選中定時器1方式1
TMOD |= 0x10;
TMOD &= 0xdf;
TR1 = 1;
//0xF8CD 是2ms,定時器1方式1
TH1=0xF8;
TL1=0xCD;
int_init();
while(1);
}
void int_init()
{
ET1 = 1;
EA = 1;
}
void display()
{
static uint8 n;
switch(n)
{ www.2cto.com
case 0:ADDR0=0;ADDR1=0;ADDR2=0;n++;break;
case 1:ADDR0=0;ADDR1=0;ADDR2=1;n++;break;
case 2:ADDR0=0;ADDR1=1;ADDR2=0;n++;break;
case 3:ADDR0=0;ADDR1=1;ADDR2=1;n++;break;
case 4:ADDR0=1;ADDR1=0;ADDR2=0;n++;break;
case 5:ADDR0=1;ADDR1=0;ADDR2=1;n++;break;
case 6:ADDR0=1;ADDR1=1;ADDR2=0;n++;break;
case 7:ADDR0=1;ADDR1=1;ADDR2=1;n=0;break;
}
}
void interrupt_led() interrupt 3
{
TH1=0xF8;
TL1=0xCD;
display();
}
作者:chenqiai0