OK, here goes:
The microcontroller is an mdm-1. RS Stock no. 351-7545
One button is used to cycle through the various test modes. This button is connected to the microcontrollers external interrupt. By pressing the button the mode is incremented in the external interrupt’s ISR.
The other button is used to start and in some cases stop the selected test. When the button is pressed the timer/ counter overflows, which generates an interrupt. The ISR for the timer/ counter overflow contains the code to start the relevant test and reset the count to FFFF.
I’m pretty sure the only other way of generating an interrupt from an external source would be using the chips comparator to detect when the button is pressed.
This is the timer ISR. It works fine with all tests and as you can see disables and re-enables the interrupt. This causes no problems.
insert
Code:
// start button handling
#int_timer1
void timer1_isr(void)
{
disable_interrupts(INT_TIMER1);
if(start_flag==STOP) //toggle start/stop of the test
start_flag=START;
else
start_flag=STOP;
set_timer1(0xFFFF); //initial timer1 value ready for overflow from start button
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
}
This section does cause problems:
insert
Code:
//enable all interrupts
enable_interrupts(GLOBAL);
//setup the timers that we require
setup_timer_1(T1_EXTERNAL); // external counter setup for start button
set_timer1(0xFFFF); //initial timer1 value ready for overflow from start button
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
So… why does the start button need to be presses twice before it is registered first of all?
After the ISR the button only needs to be pressed once, also enabling the timer/counter anywhere outside of the ISR caused the mentioned problem.
Also if my company made me use this microcontroller operate with a full PC keyboard I would say ‘no’.