# My first PIC C program

#### CVMichael

Joined Aug 3, 2007
419
Question 1:
I am using PCW, CCS C to write the code and compile.
I am using PIC16F877 chip, and I connected some LEDs to RC and RD pins.

I just want to make the LEDs flash (for now), but I can't get it to work...
Here's the code I tried to compile, but i get an error
Rich (BB code):
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

void main() {
int k = 0;

do {
for (k = 0; k < 15; k++) {
delay_ms(100);
PORTC = k;            <- I get an error here: "Undefined identifier PORTC"
}
} while (TRUE);
}
Question 2:
PS, I also have MPLAB IDE v7.60, how can I write C code and compile in MPLAB instead of PCW ?

Any help apreciated
Thanks

#### beenthere

Joined Apr 20, 2004
15,819
The PIC probably can't push enough current out the pins to light the LED's. Use a hight level on the pin to turn on a logic level FET like a VN10LP, which controls current through the LED.

#### CVMichael

Joined Aug 3, 2007
419
I put the LEDs in series with 2.2 K resistors
I have a KIT that I bought (but using another chip, PIC16F627) that has the LEDs in series with 660 Ohms resistor connected directly to the chip and it works just fine.

So, I'm pretty sure that's not a problem...

What about my original problem ? how to actually get the PIC to output anything because the compiler gives me error on "PORTC = k;"
I could not find a simple example that does that... the only example I found was using PORTC = something, so therefore my code is using that...

#### sax1johno

Joined Oct 20, 2007
17
Hey,

I'm not familiar with the CCS compiler, but I will do my best to help out.
The "Invalid identifier" probably means that PORTC is an undefined constant. The error is most likely in your include line. I'm not sure for CCS, but GCC would require the following:

#include "16F887.h"
#include <16F887.h>

Also, make sure that your include directory and libraries are linking properly when compiling.

#### kender

Joined Jan 17, 2007
264

#### jan_ram

Joined Jan 11, 2008
2
HI CVMICHAEL,

The problem is actually that PORTC doesn point out C port of ur muc.. CCS just takes it as a variable.. If u want to out ur k value on port C use set_tris_portc(k).. It will work..

I would like to know where u got the burning kit for PIC16F877.. I hardly need a good working kit..

#### ramukumar.m

Joined Mar 21, 2008
1
HI CVMICHAEL,

The problem is actually that PORTC doesn point out C port of ur muc.. CCS just takes it as a variable.. If u want to out ur k value on port C use set_tris_portc(k).. It will work..

I would like to know where u got the burning kit for PIC16F877.. I hardly need a good working kit..
hi jan ram
i have the low voltage dowloading kit for 16F877a and 18 series if u want mail me