A little fun with the 12F675 and mikroC

I have a small example that should get you going with the PIC 12F675 microcontroller and mikroC PRO. I am using the EasyPIC5 development board but I am sure you can adapt it to many development systems. It’s just a small introduction you can use as a tutorial on getting started with a comon, cheap and simple microcontroller.

bit oldstate; // Old state flag

void main() {
ANSEL = 0; // Configure AN pins as digital
CMCON = 7; // Turn off the comparators
TRISIO = 0; // configure pins of GPIO as output
TRISIO3_bit = 1;
GPIO = 0xFF;
do {
if (Button(&GPIO, 3, 1, 1)) { // Detect logical one
oldstate = 1; // Update flag
}
if (oldstate && Button(&GPIO, 3, 1, 0)) {
// Detect one-to-zero transition
GPIO = ~GPIO; // Invert GPIO
oldstate = 0; // Update flag
} // beginning of a repeat loop
} while(1); // endless loop
}

Copy and paste the code above in MikroC PRO. You can use the free version as the PIC12F675 only has 1K flash memory. This small example changes the state of the LEDs on every press on the GPIO3 button (RA3 on the EasyPIC5). Don’t forget to set MCLR and oscillator as internal - so you get three extra pins! GPIO3 is input only so we will use it for a button. Should you want to test this on a breadboard or something similar this should be the schematic:

schema_12f675_leds" alt=“schema_12f675_leds

You can find it on GitHub .