fork download
  1. #include <xc.h>
  2.  
  3. // Configuration Bits (modify according to your specific settings)
  4. #pragma config FOSC = XT // External XT Oscillator
  5. #pragma config WDTE = OFF // Watchdog Timer Disable
  6. #pragma config PWRTE = OFF // Power-up Timer Disable
  7. #pragma config BOREN = ON // Brown-out Reset Enable
  8. #pragma config LVP = OFF // Low Voltage Programming Disable
  9. #pragma config CPD = OFF // Data EEPROM Memory Code Protection Disable
  10. #pragma config WRT = OFF // Flash Program Memory Write Enable Disable
  11. #pragma config CP = OFF // Flash Program Memory Code Protection Disable
  12.  
  13. void main() {
  14. unsigned char sec = 0, min = 0;
  15.  
  16. // Initialize ports
  17. TRISB = 0x00; // PORTB as output
  18. TRISD = 0x00; // PORTD as output
  19. PORTB = 0x00; // Clear PORTB
  20. PORTD = 0x00; // Clear PORTD
  21.  
  22. // Timer0 setup
  23. T0CON = 0x08; // Timer0, 8-bit mode, no prescaler
  24. TMR0 = 0; // Reset Timer0 count
  25.  
  26. while (1) {
  27. // Wait for Timer0 overflow
  28. if (INTCONbits.TMR0IF == 1) {
  29. TMR0 = 6; // Reload Timer0 to count for 1 second (assuming 60 Hz input)
  30. INTCONbits.TMR0IF = 0; // Clear overflow flag
  31.  
  32. sec++; // Increment seconds
  33.  
  34. if (sec == 60) { // Check for 60 seconds
  35. sec = 0; // Reset seconds
  36. min++; // Increment minutes
  37.  
  38. if (min == 60) { // Check for 60 minutes
  39. min = 0; // Reset minutes
  40. }
  41. }
  42.  
  43. PORTB = sec; // Display seconds on PORTB
  44. PORTD = min; // Display minutes on PORTD
  45. }
  46. }
  47. }
  48.  
Success #stdin #stdout 0.03s 25764KB
stdin
Standard input is empty
stdout
#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
        }
    }
}