欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
紅綠燈
[打印本頁]
作者:
123123444
時間:
2018-6-2 17:09
標題:
紅綠燈
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit RED_A=P1^0; //東西向紅燈
sbit YEL_A=P1^1; //東西向黃燈
sbit GRE_A=P1^2; //東西向綠燈
sbit RED_B=P1^3; //南北向紅燈
sbit YEL_B=P1^4; //南北向黃燈
sbit GRE_B=P1^5; //南北向綠燈
uchar Time_Count=0,Flash_Count=0,Operation_Type=1; //分別用于計中斷次數,計閃爍次數(2倍),保存當前狀態值
void time0() interrupt 1 //T0定時器中斷服務函數
{
TH0=(65536-50000)/256; //重置定時器初值
TL0=(65536-50000)%256;
switch(Operation_Type) //根據狀態值執行相應語句
{
case 1: RED_A=0;YEL_A=0;GRE_A=1; //東西向綠燈亮
RED_B=1;YEL_B=0;GRE_B=0; //南北向紅燈亮
if(++Time_Count!=100)return; //5s時間未到退出switch語句
Time_Count=0; //5s時間到計數值清零
Operation_Type=2; //狀態轉移值變為2,準備狀態轉移
break; //退出switch語句
case 2: if(++Time_Count!=8)return; //400ms未到退出switch語句
Time_Count=0;
YEL_A=!YEL_A;GRE_A=0; //東西向黃燈閃,綠燈滅
if(++Flash_Count!=10)return; //閃爍5次未到退出
Flash_Count=0; //閃爍次數清零
Operation_Type=3; //狀態轉移值變為3,準備狀態轉移
break;
case 3: RED_A=1;YEL_A=0;GRE_A=0; //東西向紅燈亮
RED_B=0;YEL_B=0;GRE_B=1; //南北向綠燈亮
if(++Time_Count!=100)return; //5s未到退出
Time_Count=0;
Operation_Type=4; //狀態轉移值變為4,準備狀態轉移
break;
case 4: if(++Time_Count!=8)return; //0.4s未到退出
Time_Count=0;
YEL_B=!YEL_B;GRE_B=0; //南北向黃燈閃爍,綠燈滅
if(++Flash_Count!=10)return; //閃爍5次未到退出
Flash_Count=0;
Operation_Type=1; //重新轉移到狀態1
break;
}
}
void main()
{
TMOD=0x01;
ET0=1;
EA=1;
TH0=(65536-50000)/256; //定時50ms初值
TL0=(65536-50000)%256;
TR0=1; //啟動T0定時器
while(1);
}
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit RED_A=P1^0;
sbit YEL_A=P1^1;
sbit GRE_A=P1^2;
sbit RED_B=P1^3;
sbit YEL_B=P1^4;
sbit GRE_B=P1^5;
uchar Time_Count=0,Flash_Count=0,Operation_Type=1;
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
switch(Operation_Type)
{
case 1: RED_A=0;YEL_A=0;GRE_A=1;
RED_B=1;YEL_B=0;GRE_B=0;
if(++Time_Count!=100)return;
Time_Count=0;
Operation_Type=2;
break;
case 2: if(++Time_Count!=8)return;
Time_Count=0;
YEL_A=!YEL_A;GRE_A=0;
if(++Flash_Count!=10)return;
Flash_Count=0;
Operation_Type=3;
break;
case 3: RED_A=1;YEL_A=0;GRE_A=0;
RED_B=0;YEL_B=0;GRE_B=1;
if(++Time_Count!=100)return;
Time_Count=0;
Operation_Type=4;
break;
case 4: if(++Time_Count!=8)return;
Time_Count=0;
YEL_B=!YEL_B;GRE_B=0;
if(++Flash_Count!=10)return;
Flash_Count=0;
Operation_Type=1;
break;
}
}
void main()
{
TMOD=0x01;
ET0=1;
EA=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
while(1);
}
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1