My first PIC C program

Discussion in 'Programmer's Corner' started by CVMichael, Oct 19, 2007.

  1. CVMichael

    Thread Starter Senior Member

    Aug 3, 2007
    416
    17
    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
    Code ( (Unknown Language)):
    1.  
    2. #include <16F877.h>
    3. #fuses HS,NOWDT,NOPROTECT,NOLVP
    4. #use delay(clock=20000000)
    5. #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
    6.  
    7. void main() {
    8.    int k = 0;
    9.  
    10.    do {
    11.       for (k = 0; k < 15; k++) {
    12.          delay_ms(100);
    13.          PORTC = k;            <- I get an error here: "Undefined identifier PORTC"
    14.       }
    15.    } while (TRUE);
    16. }
    17.  
    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
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    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.
     
  3. CVMichael

    Thread Starter Senior Member

    Aug 3, 2007
    416
    17
    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...
     
  4. sax1johno

    Member

    Oct 20, 2007
    17
    0
    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"
    instead of
    #include <16F887.h>

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

    Senior Member

    Jan 17, 2007
    263
    0
  6. jan_ram

    New Member

    Jan 11, 2008
    2
    0
    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..
     
  7. ramukumar.m

    New Member

    Mar 21, 2008
    1
    0
    hi jan ram
    i have the low voltage dowloading kit for 16F877a and 18 series if u want mail me
     
  8. Nomad

    Active Member

    Oct 21, 2007
    43
    0
    pics i've played with have a max pin current of 25ma. they can sink more than source. theres also port and overall limits but an led is a slam dunk. wish i knew c. want that in basic? lol
     
  9. sirch

    New Member

    May 19, 2008
    5
    0
    Enable Portc As Output Port By Writing Into Trisc Register From Bank1.
     
Loading...