Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me provide pseudocode for the code below? #include config.h #include lcd.h #include keypad.h #include led.h #include app.h // Flags volatile bool flag_access_granted

Can someone help me provide pseudocode for the code below?

#include "config.h"

#include "lcd.h"

#include "keypad.h"

#include "led.h"

#include "app.h"

// Flags

volatile bool flag_access_granted = false;

volatile bool flag_change_code = false;

volatile bool flag_ask_password = true;

char password_user[PASSWORD_WIDTH];

char password_temp[PASSWORD_WIDTH];

uint8_t miss_count = 0;

int main(void) {

lcd_init();

keypad_init();

led_init();

// Check if password is written to EEPROM or not

if(eeprom_read_byte(EEPROM_DATA_FLAG_ADDR) != 0x01) {

//Setup defaule password

app_update_pass("1234");

//Setup defaule access code

app_update_code("ABCD");

eeprom_write_byte(EEPROM_DATA_FLAG_ADDR, 0x01);

}

while (1) {

if(flag_ask_password) {

app_ask_passcode(password_user, "Enter Password: ", PASSWORD_WIDTH);

flag_ask_password = false;

}

if(!(app_verify_password(password_user))) { // If password matches

flag_ask_password = false; // No need to ask for password again

miss_count = 0;

lcd_clear();

lcd_set_cursor(0, 0);

lcd_write_str("Welcome");

lcd_set_cursor(1,0);

lcd_write_str("Tanzeem Salim!");

led_ON_green(); // Turn ON Green LED

led_OFF_red(); // Turn OFF Red LED

_delay_ms(5000); // Wait here for 5 Seconds

led_OFF_green(); // Turn off the Green LED

// Ask for the Access Code

app_ask_passcode(password_user, "Enter Acc Code: ", ACCESS_CODE_WIDTH);

if(app_verify_code(password_user)) {

lcd_clear();

lcd_write_str("Wrong access..");

lcd_set_cursor(1, 5);

lcd_write_str("Code");

_delay_ms(3000);

flag_ask_password = true; // Continue main operation

} else {

flag_access_granted = true;

}

} else { // If password not matched

flag_ask_password = true; // ask for password again

miss_count++;

lcd_clear();

led_OFF_green();

}

// If password did not match for more than 3 times

if(miss_count >= 3) {

// Reset the counter

miss_count = 0;

lcd_clear();

for(uint8_t i = 0; i < 3; i++) {

lcd_set_cursor(0,0);

lcd_write_str("Wrong Password!");

lcd_set_cursor(1,0);

lcd_write_str("Intruder Alert!!");

led_OFF_red();

_delay_ms(500);

lcd_set_cursor(1,0);

lcd_write_str(" ");

led_ON_red();

_delay_ms(500);

}

lcd_set_cursor(1,0);

lcd_write_str("Intruder Alert");

_delay_ms(30000); // Freeze the system for 30 Secs

led_OFF_red(); // Turn off Indicator

lcd_clear();

flag_ask_password = true; // Resume normal operation

}

// ---- End of Intruder alert message -----

// -------- Change password ------

if(flag_access_granted) {

flag_access_granted = false; //Clear the flag first

lcd_clear();

lcd_write_str("Access granted !");

_delay_ms(2000);

lcd_clear();

lcd_write_str("Change Password!");

_delay_ms(2000);

app_ask_passcode(password_user, "New Password:", PASSWORD_WIDTH);

_delay_ms(1000); // Wait for a second

app_ask_passcode(password_temp, "Re-enter:", PASSWORD_WIDTH);

if(app_compare_codes(password_user, password_temp, PASSWORD_WIDTH)) {

lcd_clear();

lcd_write_str("Failed!!");

_delay_ms(3000); // Wait for 3 Seconds

} else {

app_update_pass(password_user); // Update a new password

lcd_clear();

lcd_write_str("Successfully");

lcd_set_cursor(1, 0);

lcd_write_str("changed password");

_delay_ms(3000); // Wait for some time

flag_change_code = true; // Allow to change access code too

}

}

// ------- End change of password ------------

// --- Change the access code -----

if(flag_change_code) {

flag_change_code = false;

lcd_clear();

lcd_write_str("Change Acc Code!");

_delay_ms(2000);

app_ask_passcode(password_user, "New Acc Code:", ACCESS_CODE_WIDTH);

_delay_ms(1000); // Wait for 2 seconds

app_ask_passcode(password_temp, "Re-enter:", ACCESS_CODE_WIDTH);

if(app_compare_codes(password_user, password_temp, ACCESS_CODE_WIDTH)) {

lcd_clear();

lcd_write_str("Failed!!");

_delay_ms(3000); // Wait for 3 Seconds

} else {

app_update_code(password_user); // Update a new password

lcd_clear();

lcd_write_str("Successfully");

lcd_set_cursor(1, 0);

lcd_write_str("changed acc code");

_delay_ms(2000); // Put some delay here too

flag_ask_password = true; // Allow the normal operation now

}

}

// ------ End change of Access code ------------

}

}

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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions