|
駕駛員命令 開(kāi)關(guān)狀態(tài)
S0 S1
駕駛員未發(fā)出命令 0 0
駕駛員發(fā)出左轉(zhuǎn)顯示命令 1 0
駕駛員發(fā)出右轉(zhuǎn)顯示命令 0 1
駕駛員發(fā)出汽車(chē)故障顯示命令 1 1
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機(jī)源程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit S1=P1^0;
- sbit S2=P1^1;
- sbit L1=P1^4;
- sbit L2=P1^5;
- sbit R1=P1^6;
- sbit R2=P1^7;
- void delay(uint x)
- {
- int t;
- while(x--)
- for(t=0;t<125;t++); //延時(shí)1ms
-
- }
- void main()
- {
- P1=0X03; //0000 0011
- while(1)
- {
- {
- if (S1==1&&S2==1)
- delay(10);
- if (S1==1&&S2==1) //消抖
- {
- L1=1,L2=1,R1=1,R2=1; //雙閃
- delay(50);
- L1=0,L2=0,R1=0,R2=0;
- delay(50);
- }
- }
- {
- if (S1==1&&S2==0)
- delay(10);
- if (S1==1&&S2==0) //左轉(zhuǎn)
- {
- L1=1,L2=1,R1=0,R2=0;
- delay(50);
- L1=0,L2=0,R1=0,R2=0;
- delay(50);
- }
- }
- {
- if (S1==0&&S2==1)
- delay(10);
- if (S1==0&&S2==1) //右轉(zhuǎn)
- {
- L1=0,L2=0,R1=1,R2=1;
- delay(50);
- L1=0,L2=0,R1=0,R2=0;
- delay(50);
- }
- }
-
- {
- if (S1==0&&S2==0)
- delay(10);
- if (S1==0&&S2==0) //正常
- {
- L1=0,L2=0,R1=0,R2=0;
-
- }
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
汽車(chē)轉(zhuǎn)向燈單片機(jī).rar
(17.41 KB, 下載次數(shù): 100)
2018-10-31 18:05 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|