#include<reg52.h>
#include <intrins.h>
sbit sensor=P1^0;
sbit DU=P2^6;
sbit WE=P2^7;
unsigned int time_count=0;
char flag=0;
#define led_off {P1 |= 0xf0;}
#define led_on {P1 &= 0x0f;}
unsigned char nobody[]={0x00,0x54,0x5c,0x00,0x7c,0x5c,0x5e,0x6e},
people[]={0x00,0x73,0x79,0x3f,0x73,0x38,0x79,0x00},
wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void dispaly(char body)
{
char i;
if(body)
for(i=0;i<8;i++)
{
P0=people[i];
DU=1;
DU=0;
P0=wei[i];
WE=1;
WE=0;
P0=0xff;
WE=1;
WE=0;
}
else
for(i=0;i<8;i++)
{
P0=nobody[i];
DU=1;
DU=0;
P0=wei[i];
WE=1;
WE=0;
P0=0xff;
WE=1;
WE=0;
}
}
/*------------------------------------------------
¶¨ê±Æ÷03õê¼»ˉoˉêy
------------------------------------------------*/
void timer0_init()
{
TMOD = 0x01;
TH0 = 0x4C;
TL0 = 0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
}
main()
{
timer0_init();
while(1)
{
dispaly(flag);
}
}
void timer0() interrupt 1
{
TH0 = 0x4C; //éèÖÃ3õê¼Öμ,Îa50ms
TL0 = 0x00;
sensor=1;
if(sensor)
{
time_count=0;
flag=1;
}
else if(flag)
time_count++;
if(time_count>50)//2500ms,·aËøê±¼ä2.5s
{
time_count=0;
flag=0;
}
} |