# BLINK program Problem using PIC16f628A and MikroC

#### glenn_boy13

Joined Dec 19, 2012
29
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:
Rich (BB code):
void main() {
TRISA = 0x00;
PORTA = 0x00;
while(1)
{
RA2_bit=1;  // I TRIED PORTA.RA2  <- IS THAT CORRECT?
//PORTA.RA2 compiles! :) But same result :(
Delay_ms(1000);
RA2_bit=0;
Delay_ms(1000);
}
}
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 Im really pushing myself to study in advance).

#### glenn_boy13

Joined Dec 19, 2012
29

#### glenn_boy13

Joined Dec 19, 2012
29
ok, thanks for the help everyone
in mikroC, click project >> EDIT PROJECT >> INTOSC:CLKOUT
and in ICprog: OSCILLATOR-> INTRC CLKOUT

#### absf

Joined Dec 29, 2010
1,949
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....

Allen

#### glenn_boy13

Joined Dec 19, 2012
29
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.

glenn

#### KnRele

Joined Jan 7, 2013
20
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

#### thatoneguy

Joined Feb 19, 2009
6,359
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)