新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機模擬汽車轉(zhuǎn)向燈

單片機模擬汽車轉(zhuǎn)向燈

作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
程序?qū)崿F(xiàn)功能,當(dāng)上燈亮低電平上燈亮,其它同樣道理,但兩燈亮低電平時,其它兩個低電平就會使亮燈不能同時亮,代碼如下:
#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);
}
}



評論


技術(shù)專區(qū)

關(guān)閉