#include"reg52.h"
unsigned char cycle;
unsigned char on;
sbit led=P2^7;
sbit key1=P3^2;
sbit key2=P3^3;
unsigned char const lednum[]={0x28,0xEB,0x32,0xA2,0xE1,0xA4,0x24,0xEA,0x20,0xA0};
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
int i;
cycle=10;
on=9;
IT0=1;
IT1=1;
TMOD|=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
IE=0x87;
TR0=1;
while(1)
{
led=0;
delay(5000);
}
}
void timer0(void)interrupt 1 using 1
{
static unsigned char count=0;
P0=lednum[on];
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
if(count==on)
P1=0xff;
count++;
if(count==cycle)
{
count=0;
if(on!=0)
P1=0x00;
}
}
void int0(void)interrupt 0 using 1
{
delay(5000);
if(key1==0)
if(on>1)
on--;
}
void int1(void)interrupt 2 using 1
{
delay(5000);
if(key2==0)
if(on<9)
on++;
}
评论0