单片机模拟汽车转向灯
时间: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;
delay(250);
P1_0 = 1;
P1_1 = 1;
delay(250);
}
P1_0 = 1;
P1_1 = 1;
delay(500);
}
单片机模拟汽车转向 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)