微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机模拟汽车转向灯

单片机模拟汽车转向灯

时间:11-21 来源:互联网 点击:

程序实现功能,当上灯亮低电平上灯亮,其它同样道理,但两灯亮低电平时,其它两个低电平就会使亮灯不能同时亮,代码如下:

#include

sbit P1_0 = P1^0;

sbit P1_1 = P1^1;

sbit P2_0 = P2^0;

sbit P2_1 = P2^1;

sbit P2_2 = P2^2;

sbit P0_0 = P0^0;

void delay(unsigned char i) {

unsigned int j = 0,k = 0;

for(k = 0; k < i; k++)

for(j = 0; j < 255; j++);

}

void main(void){

bit left,right,security;

while(1) {

left = P2_0;

right = P2_1;

security = P2_2;

P0_0 = 0;

if (left != 1 && right == 1) {

P1_0 = left;

delay(250);

}

if (right != 1 && left == 1) {

P1_1 = right;

delay(250);

}

if(security != 1 || (left != 1 && right != 1)) {

//P1_0 = P1_1 = security;

P1 = 0;

delay(250);

P1_0 = 1;

P1_1 = 1;

delay(250);

}

P1_0 = 1;

P1_1 = 1;

delay(500);

}

}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top