|
交通灯仿真图,及程序
#include <reg51.h>
void delay500ms(unsigned char k);
void main(void)
{
SP = 0x60;
TMOD = 0x01;
IE = 0x85;
TCON = 0x05;
while(1)
{
P1 = 0x21;
delay500ms(40);
P1 = 0x41;
delay500ms(6);
P1 = 0x12;
delay500ms(40);
P1 = 0x14;
delay500ms(6);
}
}
void int_0(void) interrupt 0
{
unsigned char i1, i2;
i1 = P1;
for(i2=0; i2<60; i2++)
{
P1 = 0x21;
delay500ms(1);
P1 = 0x00;
delay500ms(1);
}
P1 = i1;
}
void int_1(void) interrupt 2
{
unsigned char j1, j2;
j1 = P1;
for(j2=0; j2<60; j2++)
{
P1 = 0x12;
delay500ms(1);
P1 = 0x00;
delay500ms(1);
}
P1 = j1;
}
void delay500ms(unsigned char m)
{
unsigned char k1, k2;
TH0=0x3C; TL0=0xB0;
TR0 = 1;
for (k1=0; k1<m; k1++)
{
for(k2=0; k2<10; k2++)
{
while(!TF0);
TF0 = 0;
TH0=0x3C; TL0=0xB0;
}
}
}
|
|