驾驶员命令 开关状态
S0 S1
驾驶员未发出命令 0 0
驾驶员发出左转显示命令 1 0
驾驶员发出右转显示命令 0 1
驾驶员发出汽车故障显示命令 1 1
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #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++); //延时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) //左转
- {
- 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) //右转
- {
- 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;
-
- }
- }
- }
- }
复制代码
所有资料51hei提供下载:
汽车转向灯单片机.rar
(17.41 KB, 下载次数: 100)
|