#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code table[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}
uchar key_mode=0;
uchar RXD_time=11;
sbit H_RED=P1^0;
sbit H_GREEN=P1^1;
sbit H_YELLOW=P1^2;
sbit L_RED=P1^4;
sbit L_GREEN=P1^5;
sbit L_YELLOW=P1^6;
sbit k1=P2^0;
sbit k2=P2^1;
sbit k3=P2^2;
sbit k4=P2^3;
sbit LED_com1=P2^6;
sbit LED_com2=P2^7;
void delay_LED(unsigned int i)
{
unsigned int j;
for(j=0;j<i;j++)
}
void display(uchar RXD_time)
{
uchar shi,ge;
shi=RXD_time/10;
ge=RXD_time%10;
LED_com1=1;
LED_com2=1;
LED_com1=0;
P0=table[shi];
LED_com2=1;
delay_LED(20);
LED_com1=1;
P0=table[ge];
LED_com2=0;
delay_LED(20);
}
void int0() interrupt 0
if (k1==0) key_mode=1;
if (k2==0) key_mode=2;
if (k3==0) key_mode=3;
if (k4==0) key_mode=4;
}
void T0_int() interrupt 1
{
uchar i;
TH0=0x3C ;
TL0=0xB0;
i++;
if(i==10)
{
i=0;
L_YELLOW=~L_YELLOW;
H_YELLOW=~H_YELLOW;
}
}
void T1_int() interrupt 3
{
uchar i;
TH1=0x3C;
TL1=0xB0 ;
i++;
if(i==220)
{
i=0;
RXD_time--;
}
}
void main(void)
{
IT0=1;
EX0=1 ;
TMOD=0x11 ;
TH0=0x3C ;
TL0=0xB0 ;
ET0=1 ;
TH1=0x3C ;
TL1=0xB0 ;
ET1=1 ;
EA=1 ;
P1=1 ;
while(1)
{
if(key_mode==1)
{
L_RED=0;
H_RED=0;
}
if (key_mode==2)
{
TR0=1;
}
if (key_mode==3)
{
H_GREEN=0;
L_RED=0;
}
if (key_mode==4)
{
L_RED=0;
delay_LED(11000);
L_GREEN=0;
H_GREEN=0;
delay_LED(8000);
H_YELLOW=0;
delay_LED(3000);
H_RED=0;
TR1=1;
}
while(1);
}
}
|