基于单片机的智能交通灯控制系统设计

if(count_oneway == 1) //第一次按下进入东西通行模式 {

nb_red = 0; dx_gre = 0; initnumber(); }

else if(count_oneway == 2) //第二次按下进入南北通行模式 {

nb_red = 1; dx_gre = 1; dx_red = 0; nb_gre = 0; initnumber(); }

if(botton2 == 0)

{ //第三次按下退出南北通行模式 delay_ms(10); if(botton2 == 0) {

count_oneway ++; while(!botton2); } } }

initcross();

count_oneway = 0; TR0 = 1;

breakflag = 1; } } }

//夜间模式 void night() {

if(botton3 == 0) {

delay_ms(10);

if(botton3 == 0) //判断是否按下按键进入夜间模式 {

u8 flag = 1; while(!botton3); TR0 = 0;

//timebreak0 = 0; initcross();

while(flag) {

dx_yel = 0; nb_yel = 0; initnumber();

if(botton3 == 0) //第二次按下退出夜间模式 {

delay_ms(10); if(botton3 == 0) {

flag =0;

while(!botton3); } } }

initcross(); TR0 = 1;

breakflag = 1; } } }

//路口调时 第一次按下=》设置东西红灯的时间;第二次按下=》设置东西绿灯的时间;第三次按下=》确认并退出 void settime() {

if(botton4 == 0) {

delay_ms(10);

if(botton4 == 0) {

while(!botton4); TR0 = 0;

count_settime = 0; //timebreak0 = 0; initcross();

count_settime ++; //记录按键次数 while(count_settime < 3) {

if(count_settime == 1) {

dx_red = 0; }

else if(count_settime == 2) {

dx_red = 1; dx_gre = 0; }

addtime(); //加时间 cuttime(); //减时间

if(count_settime == 1) //第一次按下设置东西红灯的时间 {

dx_redtime = dx_redtime + count_time; nb_redtime = dx_gretime + yeltime; nb_gretime = dx_redtime - yeltime; count_time = 0; }

else if(count_settime == 2) 下设置东西绿灯的时间 {

dx_gretime = dx_gretime + count_time; nb_redtime = dx_gretime + yeltime; nb_gretime = dx_redtime - yeltime; count_time = 0; }

if(botton4 == 0) {

delay_ms(10); if(botton4 == 0) {

while(!botton4); count_settime ++; } } }

count_time = 0; //清空时间改变量

count_settime = 0; //清空按键计数变量 initcross(); breakflag = 1;

TR0 = 1; //打开定时器 } } }

//时间加

void addtime() {

if(botton5 == 0) {

第二次按 // delay_ms(10); if(botton5 == 0) {

u8 flag = 1; while(!botton5); count_time ++; while(flag) {

显示时间

switch (count_settime) //调节时{

case 1:display_2(DONG,count_time + dx_redtime); display_2(XI,count_time + dx_redtime); display_2(NAN,count_time + dx_redtime); display_2(BEI,count_time + dx_redtime); break;

case 2:display_2(DONG,count_time + dx_gretime); display_2(XI,count_time + dx_gretime); display_2(NAN,count_time + dx_gretime); display_2(BEI,count_time + dx_gretime); break;

default: initnumber(); }

if(botton5 == 0) {

delay_ms(10); if(botton5 == 0) {

count_time ++; while(!botton5); } }

if(botton4 == 0) //按下调时键退出时间加 {

delay_ms(10); if(botton4 == 0) {

flag = 0;

while(!botton4); } }

if(botton6 == 0) //按下时间减键进入时间减 {

delay_ms(10);

联系客服:779662525#qq.com(#替换为@)