starting pic programming with X8

Thread Starter

embpic

Joined May 29, 2013
186
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.
 

t06afre

Joined May 11, 2009
5,934
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
 

tshuck

Joined Oct 18, 2012
3,535
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?
 

Thread Starter

embpic

Joined May 29, 2013
186
i am using pic16f876a mplab x8

my code is

Rich (BB code):
#include<xc.h>
__CONFIG(XT)

void main()
{
     TRISA = 0X00;
      PORTA = 0X00;
      ADCON1 = 0X06;
      PORTA = 0X55;
     while(1);
}
 
Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,009
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.
 

t06afre

Joined May 11, 2009
5,934
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"
Rich (BB code):
// PIC16F876A Configuration Bit Settings
// CONFIG
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#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)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
 

tshuck

Joined Oct 18, 2012
3,535
You may need to fix your path to the XC8 compiler:
Project -> "Set Language Tool Locations" -> "Microchip XC8 Toolsuite"
Mine is at:


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


Verify that the paths listed are the same...
 

Attachments

Top