Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include 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(); 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(); } } } 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions