Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to make a digital alarm clock project with 1 6 F 8 7 7 A micro controller with CCS C but I have

I want to make a digital alarm clock project with 16F877A micro controller with CCS C but I have an error in code parts I change the time but I can't change the alarm time code part is below //LCD module connections
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define LCD_ENABLE_PIN PIN_C2
#define LCD_DATA4 PIN_C3
#define LCD_DATA5 PIN_C4
#define LCD_DATA6 PIN_C5
#define LCD_DATA7 PIN_C6
//End LCD module connections
// Keypad connections
#define ROW_A PIN_D4
#define ROW_B PIN_D5
#define ROW_C PIN_D6
#define ROW_D PIN_D7
#define COL_1 PIN_D2
#define COL_2 PIN_D1
#define COL_3 PIN_D0
#define SET_A PIN_B4
#define SET_B PIN_B5
#define SET_C PIN_B6
#define SET_D PIN_B7
#define ALARM_PIN PIN_A0
#include 16F877A.h>
#use delay(crystal=8000000)
#include
// Alarm hour and minute
int alarm_hour =12;
int alarm_minute =0;
// Function prototypes
void show_time();
void adjust_time();
void adjust_alarm();
void check_alarm();
// Hour, minute, and second values
int hour =0;
int minute =0;
int second =0;
void main(){
lcd_init(); // Initialize the LCD module
while(TRUE){
lcd_putc('\f'); // Clear the LCD screen
lcd_gotoxy(6,1); // Go to the 6th column of the 1st row
lcd_putc("TIME");
// Call the show_time function to display the time
show_time();
// Read keypad inputs to adjust the time and call the adjust_time function
adjust_time();
delay_ms(100); // Wait for 100 milliseconds
}
}
// Function to display the time
void show_time(){
// Update hour, minute, and second values
second++;
if(second ==60){
second =0;
minute++;
if(minute ==60){
minute =0;
hour++;
if(hour ==24)
hour =0;
}
}
// Print the time on the upper row of the LCD screen
lcd_gotoxy(1,1);
printf(lcd_putc, "TIME: %02d:%02d:%02d", hour, minute, second);
// Print the alarm time on the lower row of the LCD screen
lcd_gotoxy(1,2);
printf(lcd_putc, "ALARM: %02d:%02d", alarm_hour, alarm_minute);
}
// Function to read keypad inputs and adjust the time
void adjust_time(){
// Activate each column one by one and check the status of keys in each row
output_high(COL_1);
output_low(COL_2);
output_low(COL_3);
if(input(ROW_A)){
// Increment hour if key 1 is pressed
hour++;
if(hour ==24)
hour =0;
delay_ms(200); // Wait for stabilization of keypad integration
}
if(input(ROW_B)){
// Increment minute if key 2 is pressed
minute++;
if(minute ==60)
minute =0;
delay_ms(200); // Wait for stabilization of keypad integration
}
if(input(ROW_C)){
// Decrement hour if key 3 is pressed
hour--;
if(hour =0)
hour =23;
delay_ms(200); // Wait for stabilization of keypad integration
}
if(input(ROW_D)){
// Decrement minute if key 4 is pressed
minute--;
if(minute =0)
minute =59;
delay_ms(200); // Wait for stabilization of keypad integration
}
}
// Function to read keypad inputs and adjust the alarm time
void adjust_alarm(){
int row, col;
char key;
// Read each column in turn
for (col =0; col 3; col++){
// Activate a specific column
output_low(COL_1+ col);
// Check each row
for (row =0; row 4; row++){
// Check if the key is pressed
if (!input(ROW_A + row)){
// Find the number of the pressed key
key =(row *3)+ col +1;
// Adjust alarm hour or minute based on the key pressed
if (key =9){
alarm_hour = key;
} else if (key ==10){
alarm_hour =0;
} else if (key ==11){
alarm_minute =0;
} else if (key ==12){
alarm_minute =0;
}
// Wait to prevent multiple detections of the same key
delay_ms(200);
// Break the loop to check the entire keypad
row =4;
col =3;
}
}
// Deactivate the column
output_high(COL_1+ col);
}
}
// Function to check the alarm
void check_alarm(){
// Activate the alarm if hour and minute match the alarm time
if(hour == alarm_hour && minute == alarm_minute){
// Activate the alarm if hour and minute match the alarm time
if(hour == alarm_hour && minute == alarm_minute){
// Activate the buzzer
output_high(ALARM_PIN); can you help me I guess my keypad code is not true (please dont use chatgpt only experts give solution)
image text in transcribed

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 Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions