// Include the XC8 library for PIC microcontroller functions #include <xc.h> #define _XTAL_FREQ 4000000 // Define the crystal oscillator frequency to enable proper delay calculations // Pin Definitions #define BUZZER RB0 // Assign the buzzer to RB0 pin for alarm activation #define SNOOZE_BUTTON RB1 // Assign the snooze button to RB1 pin to allow snoozing the alarm #define MOTOR_STEP RA0 #define LCD_RS RD0 #define LCD_EN RD1 #define LCD_D4 RD2 #define LCD_D5 RD3 #define LCD_D6 RD4 #define LCD_D7 RD5 // Function Prototypes void LCD_Init(); void LCD_Command(unsigned char); // Send a command to the LCD for controlling its operations void LCD_Char(unsigned char); // Send a character to the LCD for display void LCD_String(const char* str); // Display a string on the LCD void Stepper_Move(); // Move the stepper motor to create the alarm movement effect void Alarm_Trigger(); // Trigger the alarm by turning on the buzzer and moving the stepper motor void Snooze_Function(); // Implement snooze functionality by turning off the buzzer temporarily void main() { TRISB = 0x02; // Set RB1 as input for snooze button and RB0 as output for buzzer TRISA = 0x01; // Set RA0 as output for stepper motor control TRISD = 0x00; // LCD as output LCD_Init(); while (1) { // Simulated alarm condition (replace with RTC check in real implementation) if (/* Time Matched with Alarm Time */) { Alarm_Trigger(); } if (SNOOZE_BUTTON == 1) { Snooze_Function(); } } } void LCD_Init() { // Initialize the LCD in 4-bit mode for efficient communication LCD_Command(0x02); LCD_Command(0x28); LCD_Command(0x0C); LCD_Command(0x06); LCD_Command(0x01); __delay_ms(2); } void LCD_Command(unsigned char cmd) { PORTD = (cmd & 0xF0); LCD_RS = 0; LCD_EN = 1; __delay_ms(1); LCD_EN = 0; PORTD = ((cmd << 4) & 0xF0); LCD_EN = 1; __delay_ms(1); LCD_EN = 0; } void LCD_Char(unsigned char data) { PORTD = (data & 0xF0); LCD_RS = 1; LCD_EN = 1; __delay_ms(1); LCD_EN = 0; PORTD = ((data << 4) & 0xF0); LCD_EN = 1; __delay_ms(1); LCD_EN = 0; } void LCD_String(const char* str) { while (*str) { LCD_Char(*str++); } } void Stepper_Move() { for (int i = 0; i < 50; i++) { MOTOR_STEP = 1; __delay_ms(10); MOTOR_STEP = 0; __delay_ms(10); } } void Alarm_Trigger() { LCD_Command(0x01); LCD_String("ALARM TRIGGERED!"); BUZZER = 1; Stepper_Move(); } void Snooze_Function() { LCD_Command(0x01); LCD_String("SNOOZING..."); BUZZER = 0; __delay_ms(5000); // Snooze for 5 seconds }
Standard input is empty
// Include the XC8 library for PIC microcontroller functions
#include <xc.h>
#define _XTAL_FREQ 4000000 // Define the crystal oscillator frequency to enable proper delay calculations
// Pin Definitions
#define BUZZER RB0 // Assign the buzzer to RB0 pin for alarm activation
#define SNOOZE_BUTTON RB1 // Assign the snooze button to RB1 pin to allow snoozing the alarm
#define MOTOR_STEP RA0
#define LCD_RS RD0
#define LCD_EN RD1
#define LCD_D4 RD2
#define LCD_D5 RD3
#define LCD_D6 RD4
#define LCD_D7 RD5
// Function Prototypes
void LCD_Init();
void LCD_Command(unsigned char); // Send a command to the LCD for controlling its operations
void LCD_Char(unsigned char); // Send a character to the LCD for display
void LCD_String(const char* str); // Display a string on the LCD
void Stepper_Move(); // Move the stepper motor to create the alarm movement effect
void Alarm_Trigger(); // Trigger the alarm by turning on the buzzer and moving the stepper motor
void Snooze_Function(); // Implement snooze functionality by turning off the buzzer temporarily
void main() {
TRISB = 0x02; // Set RB1 as input for snooze button and RB0 as output for buzzer
TRISA = 0x01; // Set RA0 as output for stepper motor control
TRISD = 0x00; // LCD as output
LCD_Init();
while (1) {
// Simulated alarm condition (replace with RTC check in real implementation)
if (/* Time Matched with Alarm Time */) {
Alarm_Trigger();
}
if (SNOOZE_BUTTON == 1) {
Snooze_Function();
}
}
}
void LCD_Init() {
// Initialize the LCD in 4-bit mode for efficient communication
LCD_Command(0x02);
LCD_Command(0x28);
LCD_Command(0x0C);
LCD_Command(0x06);
LCD_Command(0x01);
__delay_ms(2);
}
void LCD_Command(unsigned char cmd) {
PORTD = (cmd & 0xF0);
LCD_RS = 0;
LCD_EN = 1;
__delay_ms(1);
LCD_EN = 0;
PORTD = ((cmd << 4) & 0xF0);
LCD_EN = 1;
__delay_ms(1);
LCD_EN = 0;
}
void LCD_Char(unsigned char data) {
PORTD = (data & 0xF0);
LCD_RS = 1;
LCD_EN = 1;
__delay_ms(1);
LCD_EN = 0;
PORTD = ((data << 4) & 0xF0);
LCD_EN = 1;
__delay_ms(1);
LCD_EN = 0;
}
void LCD_String(const char* str) {
while (*str) {
LCD_Char(*str++);
}
}
void Stepper_Move() {
for (int i = 0; i < 50; i++) {
MOTOR_STEP = 1;
__delay_ms(10);
MOTOR_STEP = 0;
__delay_ms(10);
}
}
void Alarm_Trigger() {
LCD_Command(0x01);
LCD_String("ALARM TRIGGERED!");
BUZZER = 1;
Stepper_Move();
}
void Snooze_Function() {
LCD_Command(0x01);
LCD_String("SNOOZING...");
BUZZER = 0;
__delay_ms(5000); // Snooze for 5 seconds
}