XXXXXX毕业设计
} }
//夜间模式 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)
32
XXXXXX毕业设计
{
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)
33
第一次按
第二次按
//
//XXXXXX毕业设计
{
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);
34
//调节时
XXXXXX毕业设计
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); if(botton6 == 0) {
while(!botton6); flag = 0;
//count_time --; cuttime(); } } } } } }
//时间减
void cuttime() {
if(botton6 == 0) {
delay_ms(10);
35
//按下调时键退出时间加
//按下时间减键进入时间减
XXXXXX毕业设计
if(botton6 == 0) {
u8 flag = 1; while(!botton6); 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(botton6 == 0) {
delay_ms(10); if(botton6 == 0) {
count_time --; while(!botton6); } }
if(botton4 == 0) //按下调时键退出时间减 {
delay_ms(10); if(botton4 == 0) {
flag = 0;
while(!botton4); } }
if(botton5 == 0) //按下时间加键进入时间加 {
delay_ms(10);
36