Skip to content

Instantly share code, notes, and snippets.

@toctan
Last active August 29, 2015 14:07
Show Gist options
  • Save toctan/d204a9267faa9f67daaf to your computer and use it in GitHub Desktop.
Save toctan/d204a9267faa9f67daaf to your computer and use it in GitHub Desktop.
#include <reg52.h>
/* 这两个貌似没用? */
/* #define uint unsigned int */
/* #define uchar unsigned char */
#define FORWARD 1
#define STOP 0
#define BACKWARD 0
sbit backward_signal = P3^7;
sbit forward_signal = P3^1;
sbit intersection_signal = P3^2;
sbit traffic_signal = P3^3;
int status = STOP;
void forward() { P1 = 0xf0; }
void stop() { P1 = 0xff; }
void backward() { P1 = 0x0f; }
void keep_going() {
if(status == FORWARD)
forward();
else
backward();
}
void main() {
while(1) {
if(!forward_signal)
status = FORWARD;
if(!backward_signal)
status = BACKWARD;
if(!intersection_signal) {
if(traffic_signal)
keep_going();
else
stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment