XC8 Code to Blink an LED with a PIC10F322 Micro-controller.  The LED is hooked up to PortA.0.  Blinking a LED on a MCU is much like a “Hello World” program.

The code will blink an LED on PortA.0 ever second. 

#include <xc.h>
#include <stdint.h>

//Device Configuration
#pragma config FOSC = INTOSC  // Oscillator Selection 
#pragma config BOREN = ON    // Brown-out Reset
#pragma config WDTE = OFF    // Watchdog Timer
#pragma config PWRTE = ON    // Power-up Timer
#pragma config MCLRE = OFF   // MCLR Pin Function Select bit->MCLR pin function is digital input, MCLR internally tied to VDD
#pragma config CP = OFF      // Code Protection 
#pragma config LVP = OFF     // Low-Voltage Programming 
#pragma config LPBOR = ON    // Brown-out Reset Selection bits
#pragma config BORV = LO    // Brown-out Reset Voltage Selection
#pragma config WRT = OFF    // Flash Memory Self-Write Protection

//Used to calculate the delay time - Change depending on processor Speed
#define _XTAL_FREQ 8000000  //8 MHz (default after Reset)

//Prototypes
void setup (void);
void blink_led(void);



void main(void)
{
    setup();
    
    while(1)
    {
      blink_led(); 
    }
}

void setup (void)
{
    ANSELAbits.ANSA0 = 0; //Disable Analog
    //Set Pin 0 PortA.0 as output
    TRISAbits.TRISA0 = 0;
}

void blink_led(void)
{
    //Set PortA.0 High (turn on LED)
    LATAbits.LATA0 = 1;      
        
    //Wait 1 second
    __delay_ms(1000);
        
    //Set PortA.0 Low  (turn off LED)
    LATAbits.LATA0 = 0;
        
    //Wait 1 second
    __delay_ms(1000); 
}

Something You Might Be Intrested In


 

10F32X Rapid Prototype Board

Make The PIC10F322 and other PIC10F Processors Breadboard Friendly for Quick and Easy Prototyping.

{Click to learn more}

PIC10F322 - XC8 Code to Blink LED