1. Engineering
  2. Electrical Engineering
  3. using atmel avr using atmega16 board add three more leds...

Question: using atmel avr using atmega16 board add three more leds...

Question details

Using atmel AVR using ATmega16 board Add three more LEDs to PC1, PC2 and PC3. Modify the code so that when any switch is pressed the corresponding LED flashes for 2 seconds. If switch 1 is pressed, LED 1 flashes, if switch 2 is pressed, LED 2 flashes etc. Remove the LCD from the code. When you are complete, you code will have no extraneous functions. Only those functions used will Be included in your program. This is the source code that needs to adjusted. /************************** Keypad ********************************/ /* */ /* A four switch keypad is connected to the controller */ /* using standard scanning techniques. */ /* PortB0 and B1 are outputs, PORTB3 and B4 are inputs */ /* PortC0 is an output to an LED level indicator. */ /* */ /* Note that the LCD is used here even though it is not */ /* required for the project. It is used for development */ /* and troubleshooting - and then deleted from the final */ /* release of the project. */ /* */ /* */ /*********************** INCLUDES (libraries) *********************/ #include #include /****************************** DEFINITIONS ***********************/ /****** DECLARATIONS ( variables and function prototypes )*********/ void LCDstr (char *strg); void LCDinit(void); char DefaultMessage[] = "I love Embedded Systems"; char Switch1[] = "Switch 1 is active"; char Switch2[] = "Switch 2 is active"; char Switch3[] = "Switch 3 is active"; char Switch4[] = "Switch 4 is active"; Strobe(); Clear_Display(); Unpack_To_PortD(char data); Short_Delay(); Port_Init(); FlashLED(); /******************************************************************/ /**************************** MAIN ********************************/ void main(void) { LCDinit(); Port_Init(); Clear_Display(); LCDstr (DefaultMessage); delay_ms(1500); Clear_Display(); while(1) { PORTB = PORTB & 0b11111110; // Lower PB0 PORTB = PORTB | 0b00000010; // Raise PB1 if ((PINB & 0b00000100)==0) { LCDstr (Switch1); // Display switch 1 active FlashLED(); // Flash LED once delay_ms(100); Clear_Display(); } if ((PINB & 0b00001000)==0) { LCDstr (Switch2); // Display switch 2 active FlashLED(); // Flash LED twice FlashLED(); delay_ms(50); Clear_Display(); } PORTB = PORTB & 0b11111101; // Lower PB1 PORTB = PORTB | 0b00000001; // Raise PB0 if ((PINB & 0b00000100)==0) { LCDstr (Switch3); // Display switch 3 active FlashLED(); // Flash LED three times FlashLED(); FlashLED(); Clear_Display(); } if ((PINB & 0b00001000)==0) { LCDstr (Switch4); // Display switch 4 active FlashLED(); // Flash LED four times FlashLED(); FlashLED(); FlashLED(); Clear_Display(); } } } /************************ MACROS AND FUNCTIONS ********************/ void delay_ms(int d) { for(int i = 0;i

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution