View previous topic :: View next topic |
Author |
Message |
richardm55
Joined: 15 Mar 2017 Posts: 12
|
How to start programing PICs with CCS C Compiler? |
Posted: Thu Mar 16, 2017 1:03 pm |
|
|
I am new to this forum and I have just started to learn about programming PICs. I like this CCS C Compiler and its simplicity and massive functionality. I have browsed manual for this compiler and I am impressed with diversity of functions and preprocessor directives. Of course, I will master them in the future but it requires a lot of time for that.
I would like to ask how to start now? Which functions and preprocessor directives are the most important to use for the most cases in programming? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Thu Mar 16, 2017 3:38 pm |
|
|
No simple answer. It depends what you actually want to _do_.
Look at the examples. Start with the simplest serial ones, and I/O ones. These are the foundation of everything, and the basics of these are needed for everything. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Thu Mar 16, 2017 5:30 pm |
|
|
1st program you should code is a 1Hz LED program.
Very simple yet it confirms your hardware works and the compiler's OK.
In choosing a PIC .buy a 'bigger' one. You always can use more RAM, I/O pins ! Also get one with at least 1 HW UART. Buy a TTL<>USB module as well. Best $2 you'll ever spend, makes it easy to communicate to a PC!
Jay |
|
|
richardm55
Joined: 15 Mar 2017 Posts: 12
|
|
Posted: Fri Mar 17, 2017 12:33 pm |
|
|
I can not believe. People, you can not understand what I said!
I did NOT ask for tips where to buy PICs because it is the easiest thing to do. There are plenty of them on ebay.
I asked simple questions:
1) Which functions from CCS C compiler most used for the most projects
2) Which preprocessor directives are the most used |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 17, 2017 1:13 pm |
|
|
Which items are most useful for beginners to understand ?
Functions:
Code: |
output_low()
output_high()
input()
getc()
putc()
printf()
delay_us()
delay_ms()
|
Preprocessor:
CCS Libraries:
Code: |
#use delay()
#use rs232()
#use i2c()
#use spi() |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Mar 17, 2017 1:16 pm |
|
|
All of those you need to know where and how to use, and the best place to see this is the example files.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Mar 17, 2017 2:02 pm |
|
|
this question..
Which functions and preprocessor directives are the most important to use for the most cases in programming?
Really depends on WHAT you will be doing with the PIC.
these...
getc()
putc()
printf()
I never used for 8 years as my projects did NOT involve 'RS232' aka serial communications. Probably 20-25 commercial products, that was 20 years ago...PCM v2.5xx, came with spiral wrapped manual !
Same holds true if you never use I2C devices or SPI....
While I tried USB with the 18F4550 when it came out, it ended up being easier and cheaper to just use a TTL<>USB module.
The '1Hz LED' program that I proffered does use defines, delays and I/O control and should be considered a starting program,something to easily prove the PIC works and you understand the 'basics' of CCS C .
Over the decades CCS has grown 'leaps and bounds', thousands of PICS, dozens of fuses, and hundreds of device drivers so choosing the 'most used' is difficult.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Mar 17, 2017 2:15 pm |
|
|
As I said:
"No simple answer. It depends what you actually want to _do_."
It really is fundamental.
Many users never use direct port I/O, while for others it is everywhere.
Again serial can be worked without (though it is also a very useful debugging tool).
Similarly I've got complete projects, that use almost no setup (basic 8 pin PIC, using internal clock), while others have a whole page of configurations (modern PIC with dozens of fuses and selectable peripherals).
The place to start is at the beginning. The 'flash an LED' program, then perhaps a serial example, then perhaps read an ADC value and send this to the serial or out a port. All of these have versions in the examples, which is why this is the place to start. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 17, 2017 2:43 pm |
|
|
Come on guys, he's a beginner. He wants to explore the PIC. The simple
functions I gave will get him started. Hey temtronic, we are out of the ASR33 era. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Mar 17, 2017 3:16 pm |
|
|
re: Quote: | Hey temtronic, we are out of the ASR33 era. |
Yes, but I can still communicate more efficiently and reliably using ASR33 tech than today's internet or wifi tech ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Mar 17, 2017 3:35 pm |
|
|
PCM programmer wrote: | Come on guys, he's a beginner. He wants to explore the PIC. The simple
functions I gave will get him started. Hey temtronic, we are out of the ASR33 era. |
Thing was he didn't say 'which ones should he start with', he said:
Quote: |
Which functions and preprocessor directives are the most important to use for the most cases in programming?
|
'most important'. Problem is why functions are most 'important', depends totally on what you want to do.
For the 'start', I'd stick by my suggestion to look at the examples.... |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Mar 17, 2017 4:41 pm |
|
|
"Most important" is kind of like asking which of your fingers are most important, or put another way, which ones you can remove and not miss.
Look through the examples first. Which examples? Which ones catch your eye? Which ones trigger an "I can make something really cool with this" reaction?
The only way to start is to dive in and actually start. I'd recommend a decent prototyping board/unit so that you can cut code, program, and test. The Lab-X1 from MELabs is my personal favourite. They publish the schematic (beware that a couple of lines are crossed on the SPI interface to the EEPROM socket though), so if you're familiar with PCBs and aren't afraid of soldering, you can make your own. Or they provide the system as a kit that you can solder yourself. It's not that expensive either way.
Also get a programmer - the CCS ICD units are decent, and I know that others here can chime in to recommend some Microchip units too.
If you want a decent book to guide you through some basic projects, I can recommend Barnett, Cox and O'Cull's Embedded C Programming and the Microchip PIC. That book is one of the few that uses the CCS compiler.
Lastly, look at the code library section of the forum. There's some good code there, there's some okay code there, and there's some bleh code there too (some of which was contributed by me many years ago). In no time you'll be creating your first project and shortly after that you'll be critiquing code posted here. |
|
|
richardm55
Joined: 15 Mar 2017 Posts: 12
|
|
Posted: Fri Mar 17, 2017 4:50 pm |
|
|
Thank you all guys for all you tips and advice. This time I got what I wanted real help from you.
Someone said very important things that the best way to learn is from examples and I will look at some of them and analyse what code is used there.
newguy, your book Barnett, Cox and O'Cull's Embedded C Programming and the Microchip PIC probably is good one but it is not new one. I saw it was issued in 2003. I did not realize that CCS C Compiler is so old. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Mar 17, 2017 8:19 pm |
|
|
Old doesn't mean bad. Sure, some of the newer features of the latest compiler version won't be covered but the basics are still the basics. It's a good book. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sat Mar 18, 2017 12:31 am |
|
|
It's worth saying, that though very old, it's worth having access to a copy of K&R. "The C programming language". This is the book that was written by the original authors of C, and is what CCS keeps _very_ closely to. It is not a 'friendly' book, but as a reference to how C instructions should be written and how they work, it really is the 'Bible'.
The differences in CCS, are because it is an 'embedded' language. So parts relating to handling stuff passed 'from' the OS, don't apply. |
|
|
|