Page 1 of 1

Looking for XC8 commands

PostPosted: Tue Nov 25, 2014 11:43 pm
by kenDoubleU
I would welcome some help to get me started programming PIC devices.

Firstly I am a beginner and would like to be able to program various PIC devices such as PIC16F676 and PIC18F4550 for various electronic projects that I wish to build. Being in my mid 70’s learning to program a PIC in C is not going to be easy but that is the challenge! I will be using MPLAB X with XC8 C Compiler.

Having read as much as possible, I am now itching to make a start. But I seem to have hit a fundamental problem that I would appreciate some help with. Having learned the basics of ANSI ‘C’ what I have not been able to find on the Microchip site is the necessary specific commands to be able to apply ‘C’ in the PIC world. But with so much information, their site is overwhelming,

I have found out about the necessary #include and #pragma statements. And I have found the Library, giving some useful info such as __delay_ms(); CLTWDT(); SLEEP(); and the host of trig commands etc. But I have not seen a list of commands to address Ports; SFRs, etc. In the snippets of code that I have seen I realise that these PIC based commands must exist somewhere.

So assume that there must be a wealth of useful information that I have not been able to locate. Also, I think I am correct, that these commands vary with PIC families, so that the may be a different lists for PIC16Fxxx and PIC18Fxxx.

I would appreciate any help that will point me in the right direction to the source of this information, to enable me to make a start writing my first program.

Many thanks, Ken

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 4:05 am
by ric
Well they are not commands as such, they are just registers in the PIC, which are all documented in each PIC's datasheet.
With only some minor exceptions, XC8 uses exactly the same register names as you will find in the datasheet.
The names of bits within each register are also pretty similar. You can check the device header file for each PIC to see what names are in use.
e.g. for a PIC16F676, if you have XC8 version 1.32, you can look in C:\Program Files (x86)\Microchip\xc8\v1.32\include\pic16f676.h

A good place to get started would be the tutorials at http://gooligum.com.au/

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 6:31 am
by jtemples
Unless you have a reason to use those old PICs, I would suggest something more modern which might prove less frustrating to program.

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 10:33 am
by kenDoubleU
Ric thank you so much for your reply.

I know I used ‘commands’ in my posting but didn’t know the correct terminology. Having done much reading I thought that because now we do not use #include <PICdevice> as a header but use #include <xc.h> that the files on my C: drive were for compatibility of older C compilers and so I disregarded them!

Having looked in one of the device header files it was a little daunting to see then the length of text to type to address the registers. But at the end there was a whole host of #define’s that are much more user friendly. You mentioned version of XC8 and I am on v1.33 so no problems.

The Gooligum website is very good and I will probably buy the PIC tutorials as a good investment.

Again thank you for your help, and I guess I am correct an additional thanks for setting up this very useful PICforum.

Regards, Ken

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 10:40 am
by kenDoubleU
Hi jtemples Thank you for your reply. I had selected my PIC device choices on the functions that I needed for the projects; availability of the devices and the cost.

You are suggesting that I do not use these ‘old’ PICs but that I use something more modern that will be less frustrating to program. What had you in mind?

Regards, Ken

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 10:51 am
by ric
In the PIC16F family, look at the newer PIC16F1xxx parts.
Faster, cheaper, and easier to get going than the older chips.

I'm not so experienced with PIC18 parts, but there appear to be lot of nice new ones.

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 2:34 pm
by vloki
If you want to use 18F4550 because of USB capability and you are not fixed at Vdd = 5V
you might have a look at the 18FxxK50 or 18FxxJ50/J53 types.

If you do not need USB, I would recomend a 18FxxK22

Re: Looking for XC8 commands

PostPosted: Wed Nov 26, 2014 5:35 pm
by kenDoubleU
Ric and Vloki

Thank you for you ideas for PIC types. One problem seems to be within UK that there are only so many suppliers. Of these some sell a restricted range of devices but do not charge too much for postage; others give a full range but with higher delivery charges. Often a minimum spend will give a free delivery but one major distributor charges private customers, regardless of the order value.

As consequence I have focused first upon the needs for a particular project and then looked to see what PIC device would meet the requirements – but with an eye on the cost including delivery.

Many thanks for your replies, Ken