微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 6位LED显示单片机控制电子钟/计数器

6位LED显示单片机控制电子钟/计数器

时间:11-10 来源:互联网 点击:

void main(){ //主程序
P1=0xff;
P3=0xff;
time0_init();
while(1){
switch(program){
case 0: while(program==0){ //时钟菜单
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=1;
break;
}
}
break; //校时菜单
case 1: while(program==1){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=2;
break;
case 3: hour++;
if(hour>=24)hour=0;
break;
case 4: minute++;
if(minute>=60)minute=0;
break;
}
}
break;
case 2: while(program==2){ //闹钟菜单
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=3;
break;
case 3: delayed_hour++;
if(delayed_hour>=25)delayed_hour=0;
break;
case 4: delayed_minute++;
if(delayed_minute>=60)delayed_minute=0;
break;
}
}
break;
case 3: while(program==3){ //倒计时菜单
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=4;
break;
case 3: count_bit++;
if(count_bit>=7)count_bit=0;
break;
case 4: switch(count_bit){
case 0: count_second+=1;
break;
case 1: count_second+=10;
break;
case 2: count_minute+=1;
break;
case 3: count_minute+=10;
break;
case 4: count_hour+=1;
break;
case 5: count_hour+=10;
break;
case 6: break;
}
if(count_hour>=100) count_hour-=100;
if(count_minute>=60) count_minute-=60;
if(count_second>=60) count_second-=60;
break;
}
if(count_bit==6) countdown_mark=1;
else countdown_mark=0;
}
break;
case 4: count_hour=0; //秒表菜单
count_minute=0;
count_second=0;
while(program==4){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=5;
break;
case 3: stopwatch_mark=~stopwatch_mark;
break;
case 4: if(stopwatch_mark==0){
count_hour=0;
count_minute=0;
count_second=0;
}
break;
}
}
break; //计数器菜单
case 5: count_hour=0;
count_minute=0;
count_second=0;
while(program==5){
switch(show_key()){
case 0: break;
case 1: program=0;
break;
case 2: program=0;
break;
case 3: count_second++;
if(count_second>=100){
count_second=0;
count_minute++;
if(count_minute>=100){
count_minute=0;
count_hour++;
if(count_hour>=100)count_hour=0;
}
}
break;
case 4: count_hour=0;
count_minute=0;
count_second=0;
break;
}
if(P3_7==0){
while(P3_7==0) show_key();
count_second++;
if(count_second>=100){
count_second=0;
count_minute++;
if(count_minute>=100){
count_minute=0;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top