fork download
  1. #include <xc.h>
  2.  
  3. // Configuration bits
  4. #pragma config FOSC = HS // High-speed oscillator
  5. #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
  6. #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
  7. #pragma config MCLRE = ON // RE3/MCLR pin function select bit (MCLR pin enabled)
  8. #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
  9. #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
  10. #pragma config BOREN = ON // Brown-out Reset Selection bits (BOR enabled)
  11. #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled)
  12. #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
  13. #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming disabled)
  14. #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)
  15. #pragma config BOR4V = BOR40V// Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
  16. #pragma config WRTC = OFF // Configuration register write-protection bit (Configuration registers are not write-protected)
  17. #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block is not write-protected)
  18. #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
  19. #pragma config EBTR0 = OFF // Table Read Protection bit (00000-007FFh) (Block 0 is not protected from table reads executed in other blocks)
  20. #pragma config EBTR1 = OFF // Table Read Protection bit (00800-00FFFh) (Block 1 is not protected from table reads executed in other blocks)
  21. #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block is not protected from table reads executed in other blocks)
  22.  
  23. void delay_1ms() {
  24. T0CON = 0x00; // Timer0 with no prescaler, 16-bit mode
  25. TMR0H = 0xF6; // Load high byte of initial value
  26. TMR0L = 0x3C; // Load low byte of initial value
  27. T0CONbits.TMR0ON = 1; // Turn on Timer0
  28.  
  29. while (!INTCONbits.TMR0IF); // Wait for Timer0 overflow flag to be set
  30.  
  31. T0CONbits.TMR0ON = 0; // Turn off Timer0
  32. INTCONbits.TMR0IF = 0; // Clear Timer0 overflow flag
  33. }
  34.  
  35. void main() {
  36. TRISB = 0x00; // Configure PORTB as output (for testing, toggle an LED)
  37. LATB = 0x00; // Clear PORTB
  38.  
  39. while (1) {
  40. LATBbits.LATB0 = ~LATBbits.LATB0; // Toggle RB0 (connected to an LED)
  41. delay_1ms(); // 1 ms delay
  42. }
  43. }
  44.  
Success #stdin #stdout 0.02s 25588KB
stdin
Standard input is empty
stdout
#include <xc.h>

// Configuration bits
#pragma config FOSC = HS     // High-speed oscillator
#pragma config WDTE = OFF    // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF   // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON    // RE3/MCLR pin function select bit (MCLR pin enabled)
#pragma config CP = OFF      // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF     // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON    // Brown-out Reset Selection bits (BOR enabled)
#pragma config IESO = OFF    // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF   // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF     // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming disabled)
#pragma config WRT = OFF     // Flash Program Memory Self Write Enable bits (Write protection off)
#pragma config BOR4V = BOR40V// Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRTC = OFF    // Configuration register write-protection bit (Configuration registers are not write-protected)
#pragma config WRTB = OFF    // Boot Block Write Protection bit (Boot block is not write-protected)
#pragma config WRTD = OFF    // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
#pragma config EBTR0 = OFF   // Table Read Protection bit (00000-007FFh) (Block 0 is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF   // Table Read Protection bit (00800-00FFFh) (Block 1 is not protected from table reads executed in other blocks)
#pragma config EBTRB = OFF   // Boot Block Table Read Protection bit (Boot block is not protected from table reads executed in other blocks)

void delay_1ms() {
    T0CON = 0x00;          // Timer0 with no prescaler, 16-bit mode
    TMR0H = 0xF6;          // Load high byte of initial value
    TMR0L = 0x3C;          // Load low byte of initial value
    T0CONbits.TMR0ON = 1;  // Turn on Timer0

    while (!INTCONbits.TMR0IF);  // Wait for Timer0 overflow flag to be set

    T0CONbits.TMR0ON = 0;  // Turn off Timer0
    INTCONbits.TMR0IF = 0; // Clear Timer0 overflow flag
}

void main() {
    TRISB = 0x00;  // Configure PORTB as output (for testing, toggle an LED)
    LATB = 0x00;   // Clear PORTB

    while (1) {
        LATBbits.LATB0 = ~LATBbits.LATB0; // Toggle RB0 (connected to an LED)
        delay_1ms(); // 1 ms delay
    }
}