#include <xc.h>
// Configuration Bits (modify according to your specific settings)
#pragma config FOSC = XT // External XT Oscillator
#pragma config WDTE = OFF // Watchdog Timer Disable
#pragma config PWRTE = OFF // Power-up Timer Disable
#pragma config BOREN = ON // Brown-out Reset Enable
#pragma config LVP = OFF // Low Voltage Programming Disable
#pragma config CPD = OFF // Data EEPROM Memory Code Protection Disable
#pragma config WRT = OFF // Flash Program Memory Write Enable Disable
#pragma config CP = OFF // Flash Program Memory Code Protection Disable
void main() {
unsigned char sec
= 0, min = 0;
// Initialize ports
TRISB = 0x00; // PORTB as output
TRISD = 0x00; // PORTD as output
PORTB = 0x00; // Clear PORTB
PORTD = 0x00; // Clear PORTD
// Timer0 setup
T0CON = 0x08; // Timer0, 8-bit mode, no prescaler
TMR0 = 0; // Reset Timer0 count
while (1) {
// Wait for Timer0 overflow
if (INTCONbits.TMR0IF == 1) {
TMR0 = 6; // Reload Timer0 to count for 1 second (assuming 60 Hz input)
INTCONbits.TMR0IF = 0; // Clear overflow flag
sec++; // Increment seconds
if (sec == 60) { // Check for 60 seconds
sec = 0; // Reset seconds
min++; // Increment minutes
if (min == 60) { // Check for 60 minutes min = 0; // Reset minutes }
}
PORTB = sec; // Display seconds on PORTB
PORTD
= min; // Display minutes on PORTD }
}
}