思路如下,请参考。
- void main(void) {
- int timerCount[5]={0,0,0,0,0}; //5个计时器
- char timerPtr; //计时器指针
- char timerShowPtr; //计时器显示指针
- char timerStat; //计时状态 1 计时 0 停止计时
- timerPtr=0; //初始状态为全零
- timerShowPtr=0;
- timerStat=0;
- while (1) {
- if (timerStat==1) {
- timerCount[timerPtr]++;
- }
- else {
- 显示当前计时器 timerCount[timerShowPtr];
- }
- }
- }
- void exint0() interrupt 0 { //按键1中断
- timerStat=1-timerStat; //计时和停止计时切换
- }
- void exint1() interrupt 2 { //按键2中断
- if (timerStat==0) { //停止计时中
- timerShowPtr++;
- if (timerShowPtr>=5) timerShowPtr=0;
- }
- else { //计时中
- timerPtr++;
- if (timerPtr>=5) timerPtr=0;
- timeCount[timerPtr]=0;
- }
- }
复制代码 |