#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar f;
sbit LED1=P1^0;
sbit LED2=P1^1;
sbit LED3=P1^2;
sbit LED4=P1^3;
sbit LED5=P1^4;
sbit LED6=P1^5;
sbit LED7=P1^6;
sbit LED8=P1^7;
void delay_ms()
{
uchar i;
while(i--)
for(i=0;i<125;i++)
;
}
void flicker(void)
{
P1=0x00;
delay_ms();
P1=0xff;
delay_ms();
}
void main(void)
{
EA=1;
EX0=1;
EX1=1;
f=1;
while(1)
{
switch(f)
{
case 1:flicker();break;
case 2:
LED1=0;
LED3=0;
LED5=0;
LED7=0;
LED2=1;
LED4=1;
LED6=1;
LED8=1;
break;
case 3:
LED1=1;
LED3=1;
LED5=1;
LED7=1;
LED2=0;
LED4=0;
LED6=0;
LED8=0;
break;
}
delay_ms();
}
}
void int0()interrupt 0
{
f=2;
}
void int1()interrupt 2
{
f=3;
#define uchar unsigned char
#define uint unsigned int
uchar f;
sbit LED1=P1^0;
sbit LED2=P1^1;
sbit LED3=P1^2;
sbit LED4=P1^3;
sbit LED5=P1^4;
sbit LED6=P1^5;
sbit LED7=P1^6;
sbit LED8=P1^7;
void delay_ms()
{
uchar i;
while(i--)
for(i=0;i<125;i++)
;
}
void flicker(void)
{
P1=0x00;
delay_ms();
P1=0xff;
delay_ms();
}
void main(void)
{
EA=1;
EX0=1;
EX1=1;
f=1;
while(1)
{
switch(f)
{
case 1:flicker();break;
case 2:
LED1=0;
LED3=0;
LED5=0;
LED7=0;
LED2=1;
LED4=1;
LED6=1;
LED8=1;
break;
case 3:
LED1=1;
LED3=1;
LED5=1;
LED7=1;
LED2=0;
LED4=0;
LED6=0;
LED8=0;
break;
}
delay_ms();
}
}
void int0()interrupt 0
{
f=2;
}
void int1()interrupt 2
{
f=3;