Welcome to the TechSpot OpenBoards. Please read the FAQ if you have any questions. Login to participate.
|
|||||||
write an integer to a variable
![]() |
| Thread Tools |
|
#1
|
|||
|
|||
|
write an integer to a variable
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; } } Last edited by cibiieph; 04-25-2006 at 02:01 AM. |
|
#2
|
||||
|
||||
|
"Does not work" means what?
Is the keypad input smart? Usually, when one reads button presses in a uC, you have to account for the key bounce. A la when you get the interrupt, you wait for sth like 200ms to let the signal stabilise. Maybe this will help a bit: http://www.atmel.com/dyn/resources/p...ts/doc1232.pdf Or something else from here: http://www.atmel.com/dyn/products/ap...?family_id=607 |
|
|
![]() |
| Thread Tools | |
|
| Similar Topics | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| NERO invalid write state | worntilltorn | Misc. Software & Utilities | 2 | 10-15-2005 01:55 AM |
| CD Read and write speed compared to DVD Read and write speed & Graphics chipsets?? | wise_rob | Storage & Networking | 0 | 02-01-2005 04:20 AM |
| DVD Problems! | skybronco07 | Storage & Networking | 9 | 11-23-2004 10:05 AM |
| DVD files not recognised | imatinkerer | Audio and Video | 10 | 03-07-2004 03:28 AM |
| User Review: Western Digital Special Edition 120GB HDD | Vehementi | Storage & Networking | 12 | 10-08-2003 09:57 PM |
All times are GMT -4. The time now is 09:00 AM.



