BLINK program Problem using PIC16f628A and MikroC

Discussion in 'Embedded Systems and Microcontrollers' started by glenn_boy13, Jan 25, 2013.

  1. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    Hi, I've been using my beautiful own JDM programmer and IC-prog to burn hex files into my chips.
    Anyway, I've been struggling for a day to find out what's really wrong in my compiler settings.

    oh, I use mikroC pro. I have 3 pcs of pic16f628A, they work very well.
    but when I try to make a blink program using mikroC (note: I use 8mhz internal clock settings in mikroC, and tried 4mhz too! ), get the .hex file, burn it using IC-prog.

    PROBLEM: 1. The LED is not blinking!
    2. IT DOESN'T TURN ON, unless I "TOUCH" the chip!!!!
    note: PIN 4 MCLR is in HIGH!

    here is my code:
    Code ( (Unknown Language)):
    2. void main() {
    3.       TRISA = 0x00;
    4.       PORTA = 0x00;
    5.    while(1)
    6.    {
    7.               RA2_bit=1;  // I TRIED PORTA.RA2  <- IS THAT CORRECT?
    8.                               //PORTA.RA2 compiles! :) But same result :(
    9.               Delay_ms(1000);
    10.               RA2_bit=0;
    11.               Delay_ms(1000);
    12.    }
    13. }
    WHAT THE HECK is going on? :( huhuhu. All of my chips are fully working in bcd to hex decoder program.
    Should I use Assembly Language instead? Cause some people say that C is not quite compatible with this chip.

    please reply ASAP. :( Im not reviewing my schools stuffs (this is not my school stuff :p Im really pushing myself to study in advance).
  2. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    please helppppp
  3. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    ok, thanks for the help everyone :)
    in mikroC, click project >> EDIT PROJECT >> INTOSC:CLKOUT
  4. absf

    AAC Fanatic!

    Dec 29, 2010
    The 16F628 port A is defaulted to analogue. You have to set it to digital using CMCON = 0x07;
    before your LED on port A can start flashing.

    Read the datasheet on chapter 5.1 I/O PORT and chapter 10.0 Comparator module....

    glenn_boy13 likes this.
  5. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    yehey! Its you again sir Allen!!! I mean, Allen!!!!! ^_^ Good to see you here. I know someday you'll be replying to my queries here.

    Anyway, After a month, I was able to study PIC all by myself. hehe. From arduino to pic.
    I didn't use CMCON = 0x07; but it worked! I didn't have to set the port A to digital. I think it is like the arduino, in arduino I can use the Analog to digital without typing any codes.

  6. KnRele

    New Member

    Jan 7, 2013
    PICs aren't quite the same as Arduinos -- the PICs have more gotchas in them, in particular the 16F628 has a number of surprising defaults :)
  7. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    Does the program work in MikroC simulation?

    It normally catches things like analog ports being used as outputs.

    AVRs (What Arduino is based on) are the same way with registers, their state needs to be set before it can be used. The Arduino library functions of analogRead and digitalRead/Write automatically take care of setting the ports each time you call the function, which results in a good deal of wasted cycles if you are only using some pins for output only.

    The big bonus with PIC and C is you can both Simulate code before downloading it, and debug it while it is running on the chip (If you had a PICKit 2/3 or ICD 2/3)