Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Interrupt problem using ATmega32A

Status
Not open for further replies.

sgreen

Junior Member level 3
Junior Member level 3
Joined
Nov 15, 2012
Messages
31
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Visit site
Activity points
1,481
I used ATmega32A to scan a keypad every 30ms. I want to create interrupt in Clear Timer on Compare Match (CTC) Mode. But interrupt is not working. What is the problem in my code? Code is included here.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <avr/io.h>
//#include <util/delay.h>
#include <avr/interrupt.h>
// Port Mapping
#define KEYPAD_UPPER_PORT_DIR       DDRA
#define KEYPAD_UPPER_PORT_DATA  PORTA
#define KEYPAD_UPPER_PORT_IN        PINA
#define KEYPAD_LOWER_PORT_DIR       DDRB
#define KEYPAD_LOWER_PORT_DATA  PORTB
#define KEYPAD_LOWER_PORT_IN        PINB
#define TASK_PERIOD_DEBOUNCE_MS     30  
volatile uint32_t task_time_debounce = TASK_PERIOD_DEBOUNCE_MS;
unsigned char key;
void timer0_init(void);
 
 
int main(void)
{
    timer0_init();                          
    
    while(1)
    {
        if(task_time_debounce==0)
        {
        
    KEYPAD_UPPER_PORT_DIR &= 0x0f;
    KEYPAD_UPPER_PORT_DATA |= 0xf0;
    KEYPAD_LOWER_PORT_DIR |= 0x0f;
    KEYPAD_LOWER_PORT_DATA &= 0xf0;
    //_delay_us(5);
    key = (KEYPAD_UPPER_PORT_IN & 0xf0);
 
    // Get lower nibble
    KEYPAD_LOWER_PORT_DIR &= 0xf0;
    KEYPAD_LOWER_PORT_DATA |= 0x0f;
    KEYPAD_UPPER_PORT_DIR |= 0xf0;
    KEYPAD_UPPER_PORT_DATA &= 0x0f;
    //_delay_us(5);
    key = key | (KEYPAD_LOWER_PORT_IN & 0x0f);
      task_time_debounce=TASK_PERIOD_DEBOUNCE_MS;
        }     
    }     
}
void timer0_init(void){
 
   TIMSK |= (1<<OCIE0);
   TCCR0 = (1<<WGM01);              //Timer in CTC mode
   TCCR0 = ((1<<CS01)|(1<<CS00));   //1:64 prescaler
   OCR0=249;                        //Value to have an compare at every 1ms
                //Enable timer interrupts
   sei();                           //Enable global interrupts
}
ISR (TIMER0_COMP0_Vect) {
    // update system time
    //systime++;
 
    // decrement debouncing task time
    if (task_time_debounce > 0) {
        task_time_debounce--;
    }
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top