admin 管理员组

文章数量: 887007

【单片机】模拟汽车转弯灯

【单片机】模拟汽车转弯灯

  • 代码详解

代码详解

#include<reg51.h>
#include<intrins.h>
//功能:转弯灯#define uchar unsigned char
unsigned char code mon51[3] _at_ 0x3b;//保留0X3B开始三个程序空间作全速中断用uchar flag = 0 ;
sbit k1 = P1^0;
sbit k2 = P1^1;
sbit L1 = P1^4;																								  
sbit L2 = P1^5;
sbit L3 = P1^6;
sbit L4 = P1^7;//延时
void delay(unsigned int i)
{unsigned int j,k;for(k=0;k<i;k++)for(j=0;j<1000;j++);  
}
void main(void)
{P1=0xff;//P1口初始化while(1){if ( k1 == 1 && k2 == 0 ){if ( flag == 0){L1 = 0 ;L2 = 0 ;L3 = 1 ;L4 = 1 ;flag = 1 ;}else{L1 = 1 ;L2 = 1 ;L3 = 1 ;L4 = 1 ;flag = 0 ;				}delay(50);}else if ( k1 == 0 && k2 == 1 ){if ( flag == 0){L1 = 1 ;L2 = 1 ;L3 = 0 ;L4 = 0 ;flag = 1 ;}else{L1 = 1 ;L2 = 1 ;L3 = 1 ;L4 = 1 ;flag = 0 ;				}delay(50);}else{L1 = 1 ;L2 = 1 ;L3 = 1 ;L4 = 1 ;	flag = 0 ;		}}
}

本文标签: 单片机模拟汽车转弯灯