#include <stdlib.h>
#include <string.h>
#include "lcd.h"
#include "keypad.h"
#include "calculation.h"
// Declare external variables for keypad row and column pins
extern volatile char *rows_pinC;
extern volatile char *colum_pinA;
// Renamed function for better readability
void user_delay() {
volatile long i;
for (i = 0; i < 50000; i++);
}
// Initialize the system: keypad and LCD setup
void setup() {
init_keypad_pin(); // Initialize keypad pins
init_LCD_pin(); // Initialize LCD pins
init_lcd(); // Initialize LCD display
// Main loop for continuously checking the keypad
while (1) {
*rows_pinC = 0x0F; // Set all rows high
*colum_pinA = 0x00; // Set all columns low
while (*colum_pinA == 0); // Wait until a key is pressed
// Scan for the pressed key from the keypad
char key = keypad_scan();
// If 'C' is pressed, clear the display
if (key == 'C') {
clear_display();
} else {
// Process the input key and handle calculations
process_key_input(key);
}
user_delay(); // Delay to debounce the key press
}
}
// Empty loop function since we are using an infinite loop in setup
void loop() {}