I have been trying to create a countdown timer using ARM7 micro-controller, once an switch input has been detected. So far I managed to create a delay function of 1 minute, and detect a switch input. However, once the switch is released, the countdown will stop.

First I have set up 2 Seven Segment displays which detect a switch input and can increment or decrement the minutes.

I have set the delay_MINUTE function as follows which is basically a 1 minute delay. I have checked this using an LED and this part of my program is working:

  void delay_MINUTE(void)
 T0TCR = 0x0;                   //Resetting Timer0

 T0MR0 = 499999;                //Loading match register value

 T0PR = 600;                  //Loading Prescalar register value  

 T0PC = T0TC = 0;             //The value in the register increments with   every     input pulse or Processor clock fed into it. 

 T0MCR = (1<<0) | (1<<2);     //Generates interrupt and reset on match.    

 T0TCR = 0x1;                   //Starting Timer

 while(!(T0IR & (1<<0)));       //Waiting for interrupt
 T0IR = (1<<0);               //Clearing interrupt

I am getting stuck in a simple part of the program. When a switch input is detected on P0.14, the current display should decrement by one, every one minute.

If I simply do:

     int y = 0;
     unsigned int SW3;
     if((SW3) == y)  //detecting switch input
        num_right --;

the number will only decrease by one when the switch is pressed, and not keep on counting down until it reaches 0. Any suggestions on how I could change my code to detect one switch input and continuously decrement after it has been released would be appreciated.

EDIT I have also tried creating a for-loop inside the switch statement such that when the switch is pressed, the countdown will start depending on the current digit being displayed. I am not sure if this is a good idea or not.


1 Answer 1


detect one switch input and continuously decrement after it has been released would be appreciated.

try this:

if (sw3_pressed()) 
  while (num_right--) delay_Minute();
  • \$\begingroup\$ Are you assuming a function here? I was detecting switch input just by using if((SW3) == y) or something of the sort \$\endgroup\$
    – Rizzo
    Feb 25, 2017 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.