Home > Back-end >  Traffic signal detection and traffic to save several groups of traffic, averaging out data, average
Traffic signal detection and traffic to save several groups of traffic, averaging out data, average

Time:09-19


 # include & lt; Reg51. H>//the header file 
#include
# define uchar unsigned char
# define uint unsigned int//macro definition

Uchar buf [4].//second show variable
Uchar sec_dx=20.//something several default
Uchar sec_nb=30;//the default value is
Float set_timedx=20;//set the direction of time
Float set_timenb=20;//set the time between the
Int n, I, j;
Uchar data countt0 countt1, flag, flag1, flag2, count2, flag3, flag5, num2, num3=0, dxnum, nbnum=4, sum1, sum2, a, b;//timer 0 interruption times
//defines 6 set switch
Sbit k3=P3 ^ 4;//confirm
Sbit k5=P3 ^ 1;//ban
Sbit k6=P1 ^ 5;//night mode
Sbit k7=P3 ^ 7;//vehicle detection, the model key
Sbit k8=P3 ^ 5;//what vehicle detection
Sbit k9=P3 ^ 6;//the vehicle test

Sbit BUZZ=P3 ^ 0;

Sbit Red_nb=P2 ^ 6;//the red sign
Sbit Yellow_nb=P2 ^ 5;//the yellow sign
Sbit Green_nb=P2 ^ 4;//the green light to sign

Sbit Red_dx=P2 ^ 3;//something red mark
Sbit Yellow_dx=P2 ^ 2;//something yellow sign
Sbit Green_dx=P2 ^ 1;//something green light sign

Bit set=0;//adjustable direction switch key symbol=1, north and south, something=0,
Bit dx_nb=0;//control bits between east and west, south and north
Bit shanruo=0;//flashing sign a
Bit yejian=0;//yellow lights flashing sign a night
Bit flag_k8=0, flag_k9=0;

Uchar code table [11]={//common cathode font size
0 x3f,//- 0
0 x06,//- 1
0 x5b,//2
-0 x4f,//- 3
0 x66,//4
-0 x6d,//- 5
0 x7d,//6
-0 x07,//7
-0 x7f,//8
-0 x6f,//- 9
0 x00//- NULL
};

//function declaration section
Void delay (int ms);//delay subroutine
Void the key ();//button scanning subroutine
Void key_to1 ();//key processing subroutine
Void key_to2 ();
Void key_to3 ();
Void the display ();//display subroutine
Void logo ();//boot LOGO
Void Buzzer ();
//main program
Void main ()
{
TMOD=0 x11;//timer Settings
TH1=0 x3c;
TL1=0 xb0;
TH0=0 x3c;//timer 0 set initial value 0.05 S
TL0=0 xb0;
EA=1;//always interrupt
ET0=1;//timer 0 interrupts enabled
ET1=1;//open timer interrupt 1
TR0=1;//start the timer 0
TR1=1;//open the timer 1
EX0=1;//open external interrupt 0
EX1=1;//open external interrupt 1
The logo ();//boot initialization
The P2=0 xc3;//the default state, green light, the red light
Sec_nb=sec_dx + 5;//by default the passage of time more than anything for 5 seconds
While (1)//the main loop
{
The key ();//call button scanning program

The display ();//call display program
}
}
//function definition of some
Void key scanning subroutine (void)//buttons
{
If (k3!=1)//when the K3 (confirm) key press
{
The display ();//call display, used to delay shake
If (k3!=1)//if certain press
{
flag=0;
TR0=1;//start the timer 0
Flag3=0;
TR1=1;
Sec_nb=set_timenb;//from the interrupt response, still display Settings values
Sec_dx=set_timedx;//display Settings of time
//off timer 1
Dx_nb=0;
If (set==0)//time down to 0
{
P2=0X00;//out according to
Green_dx=1;//something green light
Red_nb=1;//the red light
Sec_nb=sec_dx + 5;//back to the initial value
}
The else
{
The P2=0 x00;//the green light, something red
Green_nb=1;
Red_dx=1;
Sec_dx=sec_nb + 5;
}
}
}
If (k5!=1)//when the K5 (banned) key when press the
{
The display ();//call display, used to delay shake
If (k5!=1)//if certain press
{
Flag3=0;
1 - flag5 flag5=;
If (flag5==1)
{
TR0=0;//off timer
The P2=0 x00;//out according to
Sec_dx=00;//four directions of the time of 00
Sec_nb=00;
Red_dx=1;
Red_nb=1;
}//all buy red
If (flag5==0)
{
TR0=1;
P2=0X00;//out according to
Dx_nb=0;
Green_dx=1;//something green light
Red_nb=1;//the red light
Sec_dx=set_timedx;
Sec_nb=sec_dx + 5;
}//back to the initial value
Do
{
The display ();//call display, used to delay
}
While (k5!=1);//wait for key releases
}
}
If (k6!=1)//when the K6 (night mode) press
{
The display ();//call display, used to delay shake
If (k6!=1)//if certain press
{
TR0=0;//off timer
The P2=0 x00;
Flag3=1;
Sec_dx=00;//four directions of the time of 00
Sec_nb=00;
Do
{
The display ();//call display, used to delay
}
While (k6!=1);//wait for key releases
}
}
If (k7!=1)//when the K6 (night mode) press
{
The display ();//call display, used to delay shake
If (k7!=1)//if certain press
{
Flag++;
If (flag>
=3)flag=1;//model beyond the scope of reset
If (flag==1)
{
TR0=0; TR1=1;
Sec_dx=set_timedx;
Sec_nb=set_timenb;//display Settings of initial transit time
Do
{
The display ();//call display, used to delay
}

While (k7!=1);
}
If (flag==2)
{
TR0=0; TR1=1;
//display vehicle counting

Sec_dx=flag2;
Sec_nb=flag1;
Do
{
The display ();//call display, used to delay
}
While (k7!=1);
}
}
}
If (k8!=1 & amp; & Flag_k8==0)//
{
The display ();//call display, used to delay shake
If (k8!=1 & amp; & Flag_k8==0)//if certain press
{
Flag_k8=1;
If (Green_dx==1)
{
Flag2 + +;//what traffic add
If (flag2 & gt;
=99)Flag2=0;
}
Else if (Red_dx==1)
{
BUZZ=0;//a red light buzzer alarm
Countt1=0;
}

If (flag==0)
{;
}
If (flag==1)
{
Sec_dx=set_timedx;
Sec_nb=set_timenb;//display Settings
the passage of time}
If (flag==2)
{
Sec_nb=flag1;//display vehicle counting
Sec_dx=flag2;
}
}
}
Else if (k8==1 & amp; & Flag_k8==1)
{flag_k8=0; }

If (k9!=1 & amp; & Flag_k9==0)//
{
The display ();//call display, used to delay shake
If (k9!=1 & amp; & Flag_k9==0)//if certain press
{
Flag_k9=1;
If (Green_nb==1)
{
Flag1 + +;//the north-south traffic add
If (flag1 & gt;
=99)Flag1=0;
}
Else if (Red_nb==1)
{
BUZZ=0;
Countt1=0;
}



//vehicle maximum count 99
If (flag==0)
{;
}
If (flag==1)
{
Sec_nb=set_timenb; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull