#include
#include
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code table1[]={0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,};
unsigned char code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,};
***it seg1 = P2^0;
***it seg2 = P2^1;
***it seg3 = P2^2;
***it seg4 = P2^3;
unsigned char i=0,j,g,k;
void delay(void)
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
void MCU_Init(void)
{
TMOD = 0x11;
TH0 = 0x3C;
TL0 = 0xB0;
EA = 1;
ET0 = 1;
TR0 = 0;
TH1 = 0x3C;
TL1 = 0xB0;
ET1 = 1;
TR1 = 0;
IT0=1; //INT0下降沿中断
EX0=1; //允许INT1中断
IT1=1; //INT0下降沿中断
EX1=1; //允许INT1中断
}
void main (void)
{
MCU_Init();
while(1)
{
seg1 = 1;
seg2 = 1;
seg3 = 1;
seg4 = 1;
P0=table[g%10];
seg1 = 1;
seg2 = 1;
seg3 = 1;
seg4 = 0;
delay();
seg1 = 1;
seg2 = 1;
seg3 = 1;
seg4 = 1;
P0=table[g/10];
seg1 = 1;
seg2 = 1;
seg3 = 0;
seg4 = 1;
delay();
}
}
void ex0(void) interrupt 0
{
TR0 = 0;
TR1 = 1;
k=0;g=0;
}
void timer0Interrupt(void) interrupt 1
{
TH0 = 0x3C;
TL0 = 0xB0;
k++;
if(k==20)
{
k=0;
g--;
if(g==0)
{TR0 = 0;}
P1=table1[g];
}
}
void ex1(void) interrupt 2
{
TR0 = 1;
TR1 = 0;
k=0;
g=59;
}
void Timer1Interrupt(void) interrupt 3
{
TH1 = 0x3C;
TL1 = 0xB0;
j++;
if(j==20)
{
j=0;
g++;
if(g==9)
{g=1;}
P1=table2[g-1];
}
}
希望在还没按下按键就是接上电流的时候实现p1^0的led闪烁
|