Question
1. Add three more LEDs to PC1, PC2 and PC3. Modify the code so that when any switch is pressed the corresponding LED flashes for
1. 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.
2.Modify the code so that A keypad is interfaced which permits users to enter a PIN number. If a known sequence of numbers is entered in correct order, a door in unlocked for 4 seconds. No display is shown on LCD during this time. If an incorrect PIN number is entered the system displays the dialog "INCORRECT PIN" for 3 seconds, and then returns to the default display. The default display is "ENTER PIN NUMBER". In the default state, the entered numbers are displayed as * and after four entries, one of the states above is entered.
#include
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(); } } } void delay_ms(int d) { _delay_ms(50); } void LCDinit(void) // Initialize LCD { DDRD = 0xFF; // Port D is output PORTD = 0x00; // E = 0 delay_ms(5); // Wait for LCD PORTD = PORTD & 0x0F; // mask away high nibble from Port D PORTD = PORTD | 0x20; // enable 4-bit data transfer Strobe(); Unpack_To_PortD(0x28); // enable 4-bit data transfer Unpack_To_PortD(0x0C); // display on, no cursor Unpack_To_PortD(0x06); // cursor shifts right Clear_Display(); } void LCDstr(char *strg) // Output a string of characters { char character; // Exits loop when character = NULL PORTD = PORTD | 0b00000100; // E = 1 PORTD = PORTD & 0b11111101; // RW = 0, PORTD = PORTD | 0b00000001; // RS = 1 (Data) while (character = *strg) { Unpack_To_PortD(character); // write data to LCD *strg++; } } Strobe() { PORTD = PORTD | 0b00000100; // E = 1 Short_Delay; PORTD = PORTD & 0b11111011; // E = 0 delay_ms(1); } Clear_Display() { PORTD = PORTD | 0b00000100; // E = 1 PORTD = PORTD & 0b11111100; // RW = 0, RS = 0 (Cmd) Short_Delay(); // Wait for LCD Unpack_To_PortD(0x01); // clear LCD
Unpack_To_PortD(0x02); // cursor home } Short_Delay() { char i; for (i=0; i<2; i++){}; } Unpack_To_PortD(char data) { char temp; temp = data; PORTD = PORTD & 0x0F; // mask away high nibble from Port D data = data & 0xF0; // mask away low nibble from data PORTD = PORTD | data; // data low nibble to Port D high nibble Strobe(); PORTD = PORTD & 0x0F; // mask away high nibble from Port D temp = temp <<4; // move data low nibble to high nibble PORTD = PORTD | temp; // data low nibble to Port D high nibble Strobe();} FlashLED() { PORTC = PORTC | 0b00000001; delay_ms(250); PORTC = PORTC & 0b11111110; // Flash LED once delay_ms(250); }Port_Init(){ DDRB = DDRB | 0b00000011; // PortB0 and PB1 are outputs PORTB = PORTB & 0b00000000; // PortB0 and PB1 are 0 DDRC = DDRC | 0b00000001; // PortC0 is an output PORTC = PORTC & 0b00000000; // Lower PC0 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started