PIC18F26K22 – Blink

Here’s a fancier version of the usual blink routine that also demonstrates the various options for setting the internal oscillator.

/*
* A more complicated Blink program for the PIC18F26K22
*
* Set the clock:
* 111 = HFINTOSC ? (16 MHz)
* 110 = HFINTOSC/2 ? (8 MHz)
* 101 = HFINTOSC/4 ? (4 MHz)
* 100 = HFINTOSC/8 ? (2 MHz)
* 011 = HFINTOSC/16 ? (1 MHz)(3)
*
* Use the PLL to quadruple the frequency.
* OSCTUNEbits.PLLEN = 1;
*
* connect LEDs to RA0 - RA5
*
* The program clock speed can be measured on pin RA6
*/
#include /* MCU header file ***********/
#include

#pragma config WDTEN = OFF
#pragma config FOSC=INTIO7 // ;Internal oscillator block
#pragma config PLLCFG = ON
#pragma config PRICLKEN = ON
#pragma config IESO = OFF
#pragma config PWRTEN = OFF // ;Power up timer disabled

int counter;
void main (void)
{
OSCCON = 0x62; // Fosc = 8MHz
OSCCONbits.SCS0 = 0;
OSCCONbits.SCS1 = 0;
OSCTUNEbits.PLLEN = 1; // Use the PLL to up the clock to 32Mhz

counter = 1;
TRISA = 0; /* configure PORTB for output */
while (counter <= 255)
{
PORTA = counter; /* display value of ‘counter’ on the LEDs */
Delay10KTCYx(100);
counter++;
}

}

Leave a comment