Saturday, November 14, 2015

PIC12F615 Tutorial: Oscillator and Pin Configurations

This tutorial on the PIC12F615 microcontroller shows how to configure the microcontroller internal oscillator pins of this microcontroller.
About PIC12F615:
PIC12F615 is a small programmable integrated circuit that has 8 pins which 5 can be used as I/O and 1 as an input only, its block diagram and pinout descriptions are as shown in the following image:
PIC12F615 pin 
Some PIC12F615 features:
The following list summarize some of the microcontroller features:
  • Software selectable internal oscillator frequency: 4MHz or 8MHz.
  • 5 I/O pins and 1 input only.
  • Three timer modules: two of 8-bit and one 16-bit
  • PWM module.
  • Analogue comparator module.
  • 4-Channel A/D converter of 10-bit resolution.
  • In-Circuit Serial Programming (ICSP) via two pins.
Internal oscillator configuration:
It is easy to adjust the internal oscillator of the PIC12F615 using the programming software (in our case we are going to use mikroC pro for PIC compiler), 4MHz or 8MHz can be chosen.
pic12f615 mikroc

Here the internal oscillator is used at 8MHz.
Example 1:
This example shows how to connect LEDs with all the available outputs of PIC12F615 and make them blinking.
We have 5 pins can be used as outputs, the internal oscillator is used and MCLR pin function is disabled.
Circuit schematic diagram is shown below:

pic12f615 led blink mikroc
MikroC code:

void main() {
  ANSEL = 0;    // All I/O pins are configured as digital
  GPIO = 0;     // Initial state of all outputs
  TRISIO = 0;   // All pins are configured as outputs

 GPIO = ~GPIO;    // Inverse all outputs state

PIC12F615 configuration video:
The following video shows more about the configuration of the microcontroller.

Example 2:
This example shows how to configure some pins as inputs and the others as outputs.
Circuit schematic as the following below:

pic12f615 input read button mikroc

In this example we have 3 LEDs and 3 push buttons, every push button controls one LED, the LED connected to GP0 is controlled by the push button connected to GP3 and  so on.
The internal pull-up resistor is used for the inputs except for GP3 which doesn't have a pull-up resistor when it is configured as an input.
The internal oscillator is used at 8MHz.
MikroC code:

void main() {
  ANSEL = 0;        // All I/O pins are configured as digital
  GPIO = 0;         // Initial state of GPIO port
  TRISIO = 0x38;   // Set GP3, GP4, and GP5 as inputs and others as outputs
  OPTION_REG.F7 = 0;
  WPU = 0x30;      // Enable pull-up resistors

   if(Button(&GPIO, 3, 100, 0))
     GPIO.F0 = ~GPIO.F0;
   if(Button(&GPIO, 4, 100, 0))
     GPIO.F1 = ~GPIO.F1;
   if(Button(&GPIO, 5, 100, 0))
     GPIO.F2 = ~GPIO.F2;

The following video has more descriptions about the circuit schematic and the C code: