Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ccs compiler and header files

Status
Not open for further replies.

jay543_uk

New Member
hi all, iv been using asembly code with a 16f876a and for a few months now and have got the hang of controling inputs and outputs and some mssp function but i would like to start using C, iv started read "ABSOLUTE BEGINNER'S GUILD TO C" which all seems to be making sense but how do i no what function i can use on a pic.
iv got a copy of ccs c compiler and i see i can add a few header files to my project but how do i no what these header files can do.

Code:
#include "C:\Documents and Settings\JASON\My Documents\Pic Projects\New Folder\main.h"
  #include <assert.h>
  #include <ctype.h>
  #include <errno.h>
  #include <float.h>
  #include <limits.h>
  #include <locale.h>
  #include <math.h>
  #include <s7600.h>
  #include <setjmp.h>
  #include <stdio.h>
  #include <stddef.h>
  #include <stdlib.h>
  #include <stdlibm.h>
  #include <string.h>


void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1););
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   // TODO: USER CODE!!

}

thanks for any help
jason
 
Why would you add them if you did not know what they are or do ?

You only add the header files if you need the library functions they are function prototypes for.

CCS has a compiler manual and another for the library. Find the functions you need in the second. It will tell you which header file to include for each function. CCS is good that it will only link in the code for the functions you use. Not the entire library.
 
Last edited:
hi there, as i said im very new to C and i was just looking at header files and wounded what each one did, iv not tryed to write any C code yet but i was just having a look round the ccs compiler.is the ccs compiler a good compiler for beginner.
 
hi there, as i said im very new to C and i was just looking at header files and wounded what each one did, iv not tryed to write any C code yet but i was just having a look round the ccs compiler.is the ccs compiler a good compiler for beginner.

It is a good compiler. Several good ones out there. I started with it and still use it for 16F chips.

Do not start by looking at the header files. Read the CCS Compiler Reference Manual June 2008. It explains all the functions and tells you which header file to include if you want to use that function.
 
can you use a pickit2 clone with the ccs compiler???
That's a trick question! :D They're not related directly. A PICkit 2 can program almost any PIC with almost any legal hex file. The hex files are created by assemblers or compilers. All PIC assemblers and compilers make the same format of hex files. Therefore you can use a PICkit 2 with any PIC assembler or compiler. If you couldn't, what use would it be?

To answer your question in one word, "Yes". :D
 
Hi Jay,

You should just jump in and start using the compiler, and before long you will get the hang of it. The CCS C compiler is one of the easiest to use, and comes with a large number of examples. Just look in the install directory (PICC) in the folder called - Examples. :D

If you have been working in assembler, then you might do a simple LED blink in C and then take a look at the list file to compare it with the same thing done in assembler. This will give you lots of insight into how your compiler works. Then go to your examples folder and try them all, or try some. By the time you work through two or three, you should be getting the hang of it.

I think the best thing about CCS is that they have an excellent support forum, with some very intelligent and helpful posters. Find it here:
CCS :: Index
 
So, which one would you choose Hi-Tech PICC or CSS?, I'm asking because of examples, because with them I will surly learn faster.
 
Last edited:
So, which one would you choose Hi-Tech PICC or CSS?, I'm asking because of examples, because with them I will surly learn faster.

Well, for the money: Hi-Tech is about 1k per family, and CCS is about 100 $ per family, and around $450 for the IDE, and all families. The IDE comes with lots of examples and other useful programs. I would go with CCS.

However, the one I use, and the best deal of all is Source Boost. A full license for non commercial use is less than $70. Find it here:
SourceBoost Technologies - Home of BoostC Free PIC C Compiler and BoostBasic Free Pic Basic Compiler

All of them offer demo versions, and I think all have sample programs (although I haven't looked at HiTech lately.) CCS has the best forums though.
 
So, which one would you choose Hi-Tech PICC or CSS?, I'm asking because of examples, because with them I will surly learn faster.
I think that both are good. Hi-Tech PICC compiler is my personal favourite for the PIC16. I am quite surprised that few people say they're using it on this forums, especially since it's been installed by MPLAB.
I believe that it produces the highest-quality code. However, the Lite version doesn't support all the 16F devices. I've used it to develop some programs for the 16F627A (628A is not supported), 16F690, 16F887 and 12F629/675, for example. Despite those limitations, the Lite version can be used for commercial applications and that's quite interesting!
 
CCS also has a support forum with a section to share code. It is a great resource to find code. The people there will also provide help. The one thing you need to keep in mind with CCS is that the compilers come with 90 days (I think) of support/updates. One year of support can be purchased at any time even after your support has expired for $100.

I have not seen metrics on generated code size or open (admitted bugs) for any of the PIC compilers. About the only thing we have to go on is what people say (quite subjective) and the price.

For the 18F family C18 is free. It is the only demo/free C compiler without memory size restrictions that I am aware of.

BoostC is a good buy in that one inexpensive license covers several families.
While working on an article for JPUG I found BoostC for the 18F generated 7 instructions to toggle a bit where C18 used one. I see this as a warning flag only. My sample code was very small and I did not look into optimization.
 
Last edited:
While working on an article for JPUG I found BoostC for the 18F generated 7 instructions to toggle a bit where C18 used one. I see this as a warning flag only. My sample code was very small and I did not look into optimization.
3v0,

May I see the BoostC and MCC18 instructions you used please (sorry for off-topic)?

Mike
 
Last edited:
There is a review of several of the compilers here:
PIC micros and C - CCS C review however SourceBoost is not reviewed.

CCS also has a comparison page:
**broken link removed** however their info on SB isn't up to date.

CCS has its downside as well. The best way to use it (IMHO) is the PH Anderson does, without their propriety libraries, writing your own functions. I think CCS has improved their compilers quite a bit with regards to pointers, which are heart and soul of C. They often don't respond to bug requests, though.

The one I like least is MikroC, as they seem very protective of their propriety stuff, and theirs doesn't even integrate into MPLab.

I haven't tried the IAR, but it seems very high priced...

Yes, C18 is the only free one without restrictions, but it isn't without problems either.

Mike, I don't think you are off topic at all. I too would like to see those instructions.
 
3v0,

May I see the BoostC and MCC18 instructions you used please (sorry for off-topic)?

Mike

Please note that I feel this needs further study. This is the first boostC program I ever compiled. I am not saying it is a bad compiler. I still need to work through each instrucion to see what is going on but it looks like BoostC is testing the bit and setting or clearing it based on the test. What you would do if the bit toggle instruction did not exist.

BoostC
Code:
23:                  while(1)
  004C    D7F4     BRA 0x36
24:                  {
[B]25:                    lata.7 = ! lata.7;[/B]
  0036    6A01     CLRF 0x1, ACCESS
  0038    AE89     BTFSS 0xf89, 0x7, ACCESS
  003A    2A01     INCF 0x1, F, ACCESS
  003C    B001     BTFSC 0x1, 0, ACCESS
  003E    8E89     BSF 0xf89, 0x7, ACCESS
  0040    A001     BTFSS 0x1, 0, ACCESS
  0042    9E89     BCF 0xf89, 0x7, ACCESS
26:                    delay_ms(500);
  0044    0EF4     MOVLW 0xf4
  0046    6E01     MOVWF 0x1, ACCESS
  0048    EC02     CALL 0x4, 0
  004A    F000     NOP
MCC18
Code:
17:                  while(1)
  012A    D7F9     BRA 0x11e
18:                  {
[B]19:                    LATAbits.LATA7 = ! LATAbits.LATA7;[/B]
  011E    7E89     BTG 0xf89, 0x7, ACCESS
20:                    Delay10KTCYx(50);
  0120    0E32     MOVLW 0x32
  0122    6EE6     MOVWF 0xfe6, ACCESS
  0124    EC65     CALL 0xca, 0
  0126    F000     NOP
  0128    52E5     MOVF 0xfe5, F, ACCESS

I was working on an article for JPUG when I ran into this. I was attempting to show how procedural languages generated similar code. In this case Swordfish and C18. I was curious what BoostC would look like.

LATA.7 is undefined so I used PORTA

Swordfish LATA.7 is undefined so I used PORTA
Code:
7:                 While True
[B]8:                    Toggle(PORTA.7)[/B]
  0058    7E89     BTG 0xf89, 0x7, ACCESS
  005A    9E92     BCF 0xf92, 0x7, ACCESS
9:                    DelayMS(500)
  005C    0E01     MOVLW 0x1
  005E    6E05     MOVWF 0x5, ACCESS
  0060    0EF4     MOVLW 0xf4
  0062    DFD3     RCALL 0xa
  0064    D7F9     BRA 0x58
 
can you do the debugging in ccs or do you transfer it over to mplab and do it that way

You do not need to transfer files. CCS integrates with MPLAB. Use MPLAB project wizzard to create project using CCS compiler. After that you can build debug and run from inside MPLAB.

CCS sell its own IDE but it is more money and I prefer to a single IDE for all compiler. MPLAB.
 
Last edited:
Please note that I feel this needs further study. This is the first boostC program I ever compiled. I am not saying it is a bad compiler. I still need to work through each instrucion to see what is going on but it looks like BoostC is testing the bit and setting or clearing it based on the test. What you would do if the bit toggle instruction did not exist.
Thank you for the example. I'm very impressed that you look at the generated assembly code.

BoostC seems to be missing a toggle_bit() function to compliment their set_bit() and clear_bit() functions. This is one of those situations where having a good assembler background comes in handy as you test different C instruction constructs to find the one that generates the assembler code you're lookin' for (grin).

Anyway, you'll find the following BoostC instruction construct will generate the correct or preferred single word btg lata,7 assembler instruction;

Mike

Code:
  lata.7 ^= 1;
 
Last edited:
Well, for the money: Hi-Tech is about 1k per family, and CCS is about 100 $ per family, and around $450 for the IDE, and all families. The IDE comes with lots of examples and other useful programs. I would go with CCS.

However, the one I use, and the best deal of all is Source Boost. A full license for non commercial use is less than $70. Find it here:
SourceBoost Technologies - Home of BoostC Free PIC C Compiler and BoostBasic Free Pic Basic Compiler

All of them offer demo versions, and I think all have sample programs (although I haven't looked at HiTech lately.) CCS has the best forums though.



If we don't look at the price tag, because my collage will finance it, then only remains quality of compiler itself and service(demo code, boards).

I looked at both reviews and they were extremely informative:
PIC micros and C - CCS C review

CCS also has a comparison page:
**broken link removed**

Hi-Tech does look like best but with only 14 example programs vs 130 from css, there is no comparison, also css has good community, but Hi-Tech is recommended from Microchip and has this, which is mainly for Hi-Tech PICC.

So what it seems to me is that Microchip is pushing Hi-Tech PICC and that eventually it will get same popularity as CSS(maybe not because of price tag), but when?

Also CSS operates weird:
(copy from link above)
In the HiTech, C18 and IAR you can do the following:

RA0=1;
For the C18 you will have to define RA0 like:
#define RA0 PORTAbits.RH0

However there is no way to do such an assignment in the CCS compiler their you have to call a internal function:
#define RA0 PIN_A0
output_high(RA0);

The net result is that if you want to keep your code portable to the CCS compiler you would need to do something like this for all the other compilers:

#define output_high(x) {x=1;}
Thus you would have to use the output_high function/macro anytime you set a bit.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top