Saturday, December 5, 2015

PIC12F1822 LED Blink

PIC12F1822 all outputs blink
This topic shows how to configure all the available I/0 pins as outputs and make these outputs blink.
The PIC12F1822 has 8 pins which 6 can be used as inputs and 5 can be used as outputs. The pin RA3/Vpp/MCLR can be used as an input only.
The code is written using MikroC PRO for PIC compiler.
Internal oscillator of the microcontroller is used at 32MHz (actually internal 8MHz with PLL enabled which gives 8 X 4 == 32MHz).
Circuit schematic is shown below:
pic microcontroller blink led mikroc code
PIC12F1822 LED Blink mikroC Code:
MikroC edit project configurations are shown in the following image.
 led blink mikroc

void main() {
 OSCCON = 0xF0; // Internal oscillator 8MHz and PLL enabled
 ANSELA = 0;    // All I/O pins are configured as digital
 ADCON0 = 0;    // Disable ADC module
 PORTA = 0;     // Initial value of port A bits
 TRISA = 0;     // Port A pins are configured as outputs
 PORTA = ~PORTA;    // Invert all port A bits

PIC12F1822 LED Blink Video:
Video shows our example with hardware: