Mostafa Fatouh
Newbie level 1
- Joined
- Jun 15, 2014
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 28
I got a problem of an avr program i was designing .
" I am trying to use a
8-1 multiplexer With AtMEGA16
trying to maximize my input pins so i made my program to scan all the addresses of the multiplexer and listen to an
interrupt
if an interrupt happens the program check which address was sent at this moment then print a string on LCD (and it is managed by switch case) ...
THE PROBLEM IS :: when an interrupt happens it get in to the switch case and execute all the cases under the one it starts on
EX: if i pressed the first button(First address) it will execute all the cases, but if i pressed the second one it will execute it' case and the third case ans so on.
this is my code
" I am trying to use a
8-1 multiplexer With AtMEGA16
trying to maximize my input pins so i made my program to scan all the addresses of the multiplexer and listen to an
interrupt
if an interrupt happens the program check which address was sent at this moment then print a string on LCD (and it is managed by switch case) ...
THE PROBLEM IS :: when an interrupt happens it get in to the switch case and execute all the cases under the one it starts on
EX: if i pressed the first button(First address) it will execute all the cases, but if i pressed the second one it will execute it' case and the third case ans so on.
this is my code
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 int main(void) { ////////////////////// SETMUSK(MCUCR,ISC01); /* When(ISC01 =1 and ISC00 =0 )The falling edge of INT0 generates an interrupt request. so we can use Internal PUll UP Resistance*/ CLEARMUSK(MCUCR,ISC00); /////////////////////// GICR = 0x40; CLEARMUSK(SFIOR,PUD); //Enabling Pull up resistor DDRC = 0xFF; LCD_Init(); DDRC = 0xFF; DDRA = 0xFF; DDRD = 0x00; LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("Program Starting !!"); _delay_ms(250); _delay_ms(250); _delay_ms(250); _delay_ms(250); _delay_ms(250); _delay_ms(250); _delay_ms(250); LCD_send_command(CLEAR_DISPLAY_AND_RAM); sei(); // enabling global interrupt musk while(1) { for (PORTA=Addr0;PORTA <= 7;PORTA++) ; //TODO:: Please write your application code } } ISR(INT0_vect)/*sending the ISR address to the vector table using this statement here (INT0_vect)*/ { switch (PINA) { case Addr0 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("First\0"); _delay_ms(200); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr1 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("Second\0"); _delay_ms(200); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr2 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("Third\0"); _delay_ms(200); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr3 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("Fourth\0"); _delay_ms(250); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr4 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("FiFth\0"); _delay_ms(250); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr5 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("sixth\0"); _delay_ms(250); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr6 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("seventh\0"); _delay_ms(250); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } case Addr7 : { LCD_send_command(CLEAR_DISPLAY_AND_RAM); LCD_display_string("eights\0"); _delay_ms(250); LCD_send_command(CLEAR_DISPLAY_AND_RAM); break; } //default: // break; } }
Last edited by a moderator: