starting pic programming with X8

Discussion in 'Embedded Systems and Microcontrollers' started by embpic, Jun 22, 2013.

  1. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    hi friendz
    i am starting to programming pic in c. befor i was program p89v51rd2. and pic is too different than 8051 in compiler.
    so help to configure configuration register with 4MHz crystal and other feather.

    As i includede file XC.h mplab give error that can't open file and was select compiler while starting projects.

    thanx.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Post your code, and also which PIC do you use :) Are you using MPLAB or MPLABX. I would recommend MPLAB as it is still much better documentated
     
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You should post your code..

    XC8 uses #pragma to set configuration bits.

    What version of MPLAB are you using?

    What are the feathers you'd like to have?
     
  4. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    i am using pic16f876a mplab x8

    my code is

    Code ( (Unknown Language)):
    1.  
    2. #include<xc.h>
    3. __CONFIG(XT)
    4.  
    5. void main()
    6. {
    7.      TRISA = 0X00;
    8.       PORTA = 0X00;
    9.       ADCON1 = 0X06;
    10.       PORTA = 0X55;
    11.      while(1);
    12. }
    13.  
     
    Last edited by a moderator: Jun 23, 2013
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Thanks for the code tags bertus!!!

    embpic: you get code tags by using the # icon above the reply window. Anything between the tags gets formatted as bertus added to your post. It just makes things more readable! I also use it when I want to make a table to show some relationships,as it keeps formatting (spaces and tabs) intact.

    PLEASE learn how to use them. You can check it with the PREVIEW button without actually posting anything.

    So... your code is actually quite good. Port A has analog functions and it looks like you turned them off by setting ADCON1 (most people miss that first time out) (and I still miss it on my 1,000th time out).

    I do not know why MPALB/XC8 cannot find xc.h. It's "built into" the search path in my installation, so perhaps something went wrong in your installation; maybe you changes a path or apiece is missing XC8 is a separate download and install). To fix this in your code you can hit them on the menu at Project | Build Options | Project to open the options window. Select Directories, Include Search Path, then hit NEW and browse for the place where xc.h is on your computer. Hit OK and rebuild.

    Then you hit the next problem: __CONFIG(XT) needs a ; at the end... Then next time you compile you may get a "undefined symbol XT." I couldn't find the symbols for the config bits, so someone else will have to help you today (I'll be out on a lighthouse without even any cell service).

    Also, your PORTA=0x55; attempts to set the RA6 bit high: there is no RA6 bit on this device. The code will run fine, just nothing happens on the pin that isn't there. ;-)

    I deleted the __config line, your code compiled and ran fine in the MPLAB simulator. So keep whacking this, you are very close.
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Which version do you use of the XC8 compiler?
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This is the way it is done, using __config is obsolete. Every supported PIC micro has it own file regarding the configuration bits setting. Your file may be found in the path named something like this "C:\Program Files\Microchip\xc8\v1.12\docs\chips\16f876a.html"
    Code ( (Unknown Language)):
    1.  
    2. // PIC16F876A Configuration Bit Settings
    3. // CONFIG
    4. #pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
    5. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
    6. #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
    7. #pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
    8. #pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
    9. #pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
    10. #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
    11. #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You may need to fix your path to the XC8 compiler:
    Project -> "Set Language Tool Locations" -> "Microchip XC8 Toolsuite"
    Mine is at:
    [​IMG]

    In your open project, verify you are, indeed, attempting to use the XC8 compiler:
    Project -> "Set Language Toolsuite" -> "Microchip XC8 Toolsuite"
    See here:
    [​IMG]

    Verify that the paths listed are the same...
     
Loading...