write an integer to a variable

By cibiieph
Apr 25, 2006
Topic Status:
Not open for further replies.
  1. Hi everyone,

    I wanna write an integer (i.e 429) to a variable. Everytime I press a button on the keypad
    it calls ISR(INT2_vect) to display the number on the keypad. I already tried doing
    this with the scanf function but din not work. I also tried pressing a button and then
    disabling the interrupt, press three numbers and read them but again did not work.
    I'm doing this in C language and using WinAVR GCC compiler. This is how I
    have everything connected.

    keypad - encoder - atmega32 - LCD

    Any suggestions???

    int main(void)
    {
    Initialize_Atmega32(); // set baud rate, enable txpin, etc
    USART_Transmit_Clear_Screen(); // clear LCD screen

    GICR &=~(1<<INT2); //disable external interrup //disable external interrup
    MCUCSR |=(1<<ISC2); //rising edge
    GIFR |=(1<<INT2); // clear flag
    GICR |=(1<<INT2); // Enable INT2 interrupt, "should" call INT2_vect ISR when INT2 fires
    sei(); // Enable global interrupts

    while (1)
    {
    // waits for interrupt

    }

    return 0;
    }

    ISR(INT2_vect)
    {
    int x;
    DDRA = 0x0F; // pins 4,5,6, and 7 of PORTA collect number in ATmega32
    x = (PINA>>4);
    switch (x)
    {
    case 3:
    if ( (PINA>>4) == 3) // Press ENTER button to call INT2
    {
    GICR &=~(1<<INT2); // disable INT2 interrupt

    Base_Rate1 = (PINA>>4);
    delay_ms(5000); // delay 5 sec to try to press second digit on keypad

    Base_Rate2 = (PINA>>4);
    delay_ms(5000); // delay 5 sec to try to press third digit on keypad

    Base_Rate3 = (PINA>>4);

    strcpy(result, Base_Rate1); // concatenate three numbers together
    strcat(result, Base_Rate2);
    strcat(result, Base_Rate3);

    printNumber((int)result); // display three numbers as an integer on LCD
    }
    break;

    case 11:
    x = 0;
    printNumber(x); // display number 0
    break;

    case 13:
    x = 1;
    printNumber(x); // display number 1
    break;

    case 9:
    x = 2;
    printNumber(x); // display number 2
    break;

    case 5:
    x = 3;
    printNumber(x); // display number 3
    break;

    case 12:
    x = 4;
    printNumber(x);
    break;

    case 8:
    x = 5;
    printNumber(x);
    break;

    case 4:
    x = 6;
    printNumber(x);
    break;

    case 14:
    x = 7;
    printNumber(x);
    break;

    case 10:
    x = 8;
    printNumber(x);
    break;

    case 6:
    x = 9;
    printNumber(x);
    break;

    case 0:
    USART_Transmit('.'); // display a dot (.)
    break;
    }
    }
  2. Nodsu

    Nodsu Newcomer, in training Posts: 9,431

Topic Status:
Not open for further replies.


Add New Comment

TechSpot Members
Login or sign up for free,
it takes about 30 seconds.
You may also...


Get complete access to the TechSpot community. Join thousands of technology enthusiasts that contribute and share knowledge in our forum. Get a private inbox, upload your own photo gallery and more.