#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 } }
Standard input is empty
#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 } }