A little fun with the 12F675 and mikroC

September 17, 2009
By

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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

  • masoud

    hi why fosc/4 answer me a way to get just fosc internal for pic 12f675

  • http://twitter.com/sarimkhan Sarim Khan

    set MCLR and oscillator as internal
    How to do that ?

  • http://twitter.com/sarimkhan Sarim Khan

    set MCLR and oscillator as internal
    How to do that ?

  • http://twitter.com/sarimkhan Sarim Khan

    set MCLR and oscillator as internal
    How to do that ?

  • Prayagsygnet

    its nice project, I made it in microc, but I’ve made some modification in program, chaser sequence, …..Thanks

Follow Me

Subscribe via RSS