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. The code and include files can be found here in GitHub – https://github.com/JamieStarling/MCU_FUN/tree/master/Microchip/PIC10F322
#include "includes/10F322_deviceconfig.h"
void main ()
{
ANSELAbits.ANSA0 = 0; //Disable Analog
//Set Pin 0 PortA.0 as output
TRISAbits.TRISA0 = 0;
//The Forever Loop
while (1)
{
//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);
//End of Loop
}
}