I have an issue where I want to count how many times I hit a switch using an interrupt. I tried placing the count variable inside the main but it claims that count does not exist. I put count inside the pragma but I know that will reset the count value to 0. How should I approach this problem?
I'm using the STM8S003K3
volatile int count = 0;
#pragma vector = 8
__interrupt void EXTI_PORTD_IRQHandler(void){
count++;
PD_ODR_ODR3 = !PD_ODR_ODR3;
}
void main() {
__disable_interrupt();
PD_ODR = 0; // All pins are turned off.
PD_DDR = 0xff; // All pins except PD4 are outputs.
PD_CR1 = 0xff; // Push-Pull outputs.
PD_CR2 = 0xff; // Output speeds up to 10 MHz.
//
// Now configure the input pin.
//
PD_DDR_DDR4 = 0; // PD4 is input.
PD_CR1_C14 = 0; // PD4 is floating input.
//
// Set up the interrupt.
//
EXTI_CR1_PDIS = 2; // Interrupt on falling edge only.
EXTI_CR2_TLIS = 0; // Falling edge only.
__enable_interrupt();
while (1) {
__wait_for_interrupt();
}
}