Searching \ for '[PIC] Introductory Book to C18?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Introductory Book to C18?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Introductory Book to C18?'
2011\05\23@004650 by Jeff Stevens

flavicon
face
All,

I have some experience with PIC16Fs and assembly as a hobbyist and
have more recently been delving into 18Fs with the C18 compiler.
While there is quite a bit of information online, I'm looking for an
actual book which covers 18Fs with a focus on using C18.  There are
quite a few books on the 18F available but they generally seem to use
CCS or a couple of other compilers which I'm not even remotely
familiar with.  Is there a good book out there which covers the 18F
line and C18?  Is the lack of books in this area indicative of some
problem with C18?

-Jef

2011\05\23@075450 by Olin Lathrop

face picon face
Jeff Stevens wrote:
> I have some experience with PIC16Fs and assembly as a hobbyist and
> have more recently been delving into 18Fs with the C18 compiler.
> While there is quite a bit of information online, I'm looking for an
> actual book which covers 18Fs with a focus on using C18.

Since you're already familiar with the PIC 18, it sounds like you need a
book on C18 alone.  There is such a thing.  It's called the manual and comes
with C18.  I expect you can download it for free from the Microchip web
site, but haven't actually looked myself.

I have read said manual, and it tells you what you need to know if you're
already familiar with the PIC 18 architecture.

Everything you need is in the combination of the PIC datasheet and the C18
manual.  Any book that pretends to cover that is only going to not garble
something at best.

> Is the lack of books in this area indicative of some
> problem with C18?

As I said, the books you need are there.

My impression of C18 is that the code generator is pretty solid, but some
very poor choices were made in how the C18 runtime environment uses the PIC
18 architecture.  The data stack conventions are downright stupid, the
allocation of FSRs annoying, and the subroutine calling conventions "less
than optimal".

If you mix C18 and MPASM code, be prepared to hold your nose while being
forced to do inefficient things in MPASM.  In my PIC development
environment, I have a C18 compatibility switch that tries to allow the same
source code to work with and without C18, with the C18 version taking more
cycles and program memory.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000

2011\05\25@190413 by Jeff Stevens

flavicon
face
> Since you're already familiar with the PIC 18, it sounds like you need a
> book on C18 alone.  There is such a thing.  It's called the manual and comes
> with C18.  I expect you can download it for free from the Microchip web
> site, but haven't actually looked myself.

Yes, my focus is more on the specifics of C18 than the chip itself.
The PIC18 is so similar to the PIC16 and microchip's data sheets are
specific to the point of repetitiveness.  As a result of your urging
to go back to the C18 manual, I actually printed it out to make it a
bit more useful.   However, there are still reasons I'm looking for a
book.  While it may be a good reference manual, it's just that.  No
different than referring to Harbison and Steele for standard C.  They
book I'm looking for is something like a bunch of application notes,
stylistic samples, and explanations of how to do a few of the things
that seem so trivial in assembler but have no obvious solution in C18.

In any case, I found "Applying PIC18 Microcontrollers: Architecture,
Programming, and Interfacing using C and Assembly" by Brey.  I have no
idea if it's what I'm looking for, but it does apparently include a
fair bit of C18.  Earlier today I requested a copy through the local
library.

Thanks,

Jeff

2011\05\25@191050 by V G

picon face
On Wed, May 25, 2011 at 7:04 PM, Jeff Stevens <spam_OUTjeffTakeThisOuTspammossycup.com> wrote:

> [...] that seem so trivial in assembler but have no obvious solution in
> C18.
>

You probably already know this, but you can do inline assembler for those
parts.

I don't understand what you mean by "specific" to C18. I assume you know C
well, and PIC18 assembler well, so everything should transfer over. Port
names are the same (if I can remember correctly), and all other register
names are the same. The compiler specifics (optimizations, etc), are listed
in the hep manual.

What specifically are you looking for

2011\05\26@085115 by Olin Lathrop

face picon face
Jeff Stevens wrote:
> Yes, my focus is more on the specifics of C18 than the chip itself.
> The PIC18 is so similar to the PIC16 and microchip's data sheets are
> specific to the point of repetitiveness.  As a result of your urging
> to go back to the C18 manual, I actually printed it out to make it a
> bit more useful.   However, there are still reasons I'm looking for a
> book.  While it may be a good reference manual, it's just that.  No
> different than referring to Harbison and Steele for standard C.  They
> book I'm looking for is something like a bunch of application notes,
> stylistic samples, and explanations of how to do a few of the things
> that seem so trivial in assembler but have no obvious solution in C18.

I don't understand.  If you know how C18 works, you should be able to
synthesize anything you want to do from the tools it makes available.  This
is no different from knowing the instruction set and the machine
architecture to synthesize what you want to do in MPASM.

What specifically do you want to do that you don't know how?


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000

2011\05\27@110428 by Gerhard Fiedler

picon face
Jeff Stevens wrote:

> Yes, my focus is more on the specifics of C18 than the chip itself.
> The PIC18 is so similar to the PIC16 and microchip's data sheets are
> specific to the point of repetitiveness.  As a result of your urging
> to go back to the C18 manual, I actually printed it out to make it a
> bit more useful.  
I never actually used C18, but from what it seems, the manual is more of
a reference. For me, the electronic form of references is much more
useful, mostly because of searching -- that's what I do most with
references.

> No different than referring to Harbison and Steele for standard C.  
I don't know Harbinson and Steele, but if it's too much of a reference
manual, there is a large number of (generic) introductory material about
the language C itself (without focus on C18). I still think that
Kernighan and Ritchie provide everything you need to know about C
(besides the reference of your specific compiler -- which you have --
and of course the language standard -- which you may also want to have).

> They book I'm looking for is something like a bunch of application
> notes,

I'm sure there is a bunch of Microchip app notes that uses C18 and
contain C18 code.

> stylistic samples,
I wouldn't trust Microchip with this, and this is also nothing specific
to C18. C language style is independent of the target system, and
embedded projects for small processors in C look the same (in terms of
style) no matter for which processor you write.

> and explanations of how to do a few of the things that seem so trivial
> in assembler but have no obvious solution in C18.

Like what? There's always inline assembly if you really need it.

All in all, it seems there isn't much C18 specific in your questions.
You may get better answers by either widening your scope (C in (small)
embedded systems) or restricting it (how to do something specific in
C18).

Gerhar

2011\05\27@132738 by William \Chops\ Westfield

face picon face
>> and explanations of how to do a few of the things that seem so  
>> trivial
>> in assembler but have no obvious solution in C18.
>
> Like what? There's always inline assembly if you really need it.

The world could probably use a good book on "low level C", rather than  yet more desktop-gui-oriented tomes, but like other commenters, I'm  having trouble figuring out what you're looking for.

There are C reference manuals for C.
There are data sheets for the hardware.
There are a couple techniques used to make C match up with the names  and descriptions in data sheets, but it's usually just a matter of  noticing "bit variables" or "we use defines and bit numbers" or "we  have pointers and masks" or "structures and bitfields" and carrying on  from there (hoping that the implementation stays reasonably  consistent, and crossing  your fingers that staying with the  "standardized" methodology makes your code more readable than re- architecting things to your personal preferences...

(Some of the secret is in trusting that the compiler will do  reasonable things given standardish syntax.  PORTB |= 2 had better  compile to a single BSF instruction when possible (for example), or  you go yell at the compiler vendor.)

BillW

2011\05\27@174720 by Gerhard Fiedler

picon face
William "Chops" Westfield wrote:

> (Some of the secret is in trusting that the compiler will do  
> reasonable things given standardish syntax.  PORTB |= 2 had better  
> compile to a single BSF instruction when possible (for example), or  
> you go yell at the compiler vendor.)

Part of /this/ secret is reading the compiler documentation (assuming,
of course, that you use a compiler that has decent documentation). It
should in enough detail address everything that is not standard C -- for
example, how it handles bits, ports, stack, variable banks, recursion,
pointers etc.

Don't go yell at the vendor before having read the docs... :)

Gerhar

2011\05\27@185624 by William \Chops\ Westfield

face picon face

On May 27, 2011, at 2:47 PM, Gerhard Fiedler wrote:

>> PORTB |= 2 had better compile to a single BSF instruction when  
>> possible (for example), or you go yell at the compiler vendor.)
>
> [compiler documentation] should in enough detail address everything  
> that is not standard C -- for example, how it handles bits, ports,  
> stack, variable banks, recursion, pointers etc.
>
> Don't go yell at the vendor before having read the docs... :)

Current philosophy seems to be that a compiler should produce good  code from STANDARD C constructs, without having to resort to non- standard bit-set macros. avr-gcc had deprecated sbi/cbi "functions" in  favor of "just use var |=/&=~ bit", for example.

After all, part of the point of using a C compiler is portability.   Non-standard architecture-specific features should be avoided whenever  possible.

BillW

2011\05\28@174737 by cdb

flavicon
face
On Fri, 27 May 2011 12:04:25 -0300, Gerhard Fiedler wrote:
:::: and explanations of how to do a few of the things that seem so
:::: trivial in assembler but have no obvious solution in C18.
::::
:: Like what? There's always inline assembly if you really need it.

In my experience different ANSI 'C' compilers for the PIC aren't equal either in the assembler they produce or the way in which the syntax is used. There are some things in assembler that just can't be produced by a C compiler with reliability.

Structs seem to have slightly different implementations between compilers, and as yet I've found no compiler that will test if bit 3 is set in a loop variable as a short cut for looping 7 times.

The only book I can think of that has some Microchip and Hitech 'C' code in it is John Peatman's Pic 18F452 book, and even then it is an add on at the end of the book. Code is available for download from his website (http://www.picbook.com).

Colin

--
cdb, .....colinKILLspamspam@spam@btech-online.co.uk on 29/05/2011
Web presence: http://www.btech-online.co.uk   Hosted by:  http://www.justhost.com.au
 

2011\05\28@191400 by Oli Glaser

flavicon
face
On 28/05/2011 22:47, cdb wrote:
> The only book I can think of that has some Microchip and Hitech 'C' code in
> it is John Peatman's Pic 18F452 book, and even then it is an add on at the
> end of the book. Code is available for download from his website
> (http://www.picbook.com).
>

I can't think of any that only deal with C18, but there are a few books that deal with PICs and C in general.
Here are a few I can remember:
Advanced PIC Microcontroller - Projects in C From USB to RTOS with the PIC18F Series (mainly MikroC)
Programming 8-bit PIC Microcontrollers in C (mainly CCS)
Microprocessors From Assembly Language to C Using the PIC18Fxx2 (pretty good and thorough book - Assembly and HI-Tech C)

I wouldn't worry too much about it being specifically C18; one as MC are favouring HI-Tech now anyway and the future of C18 is uncertain, and two as C is C, and it's more important to learn the tricks of applying it to an (often severely memory limited) embedded situation.
The manual will give you the details on any C!8 specifics you need anyway, any deviations from/additions to the standard. I got by for ages with the K&R book and the manual for whatever compiler I was using, but I understand it's nice to have some examples, which the above books do contain.
I would be wary of using the Microchip code in app notes for learning; much of it is just basic functional examples to get you started, rather than advice on how you should write the code.

2011\05\29@103828 by Gerhard Fiedler

picon face
Oli Glaser wrote:

> I got by for ages with the K&R book and the manual for whatever
> compiler I was using,
Ditto, with the addition of the C language standard. It is helpful to
know what parts are standardized -- if you are working with a compiler
that is reasonably compliant (with this I mean that all deviations and
implementation-defined items are documented). Not all PIC compilers are
"reasonably compliant" in this sense.

Gerhar

2011\05\29@212920 by Gerhard Fiedler

picon face
William "Chops" Westfield wrote:

> On May 27, 2011, at 2:47 PM, Gerhard Fiedler wrote:
>
>>> PORTB |= 2 had better compile to a single BSF instruction when
>>> possible (for example), or you go yell at the compiler vendor.)
>>
>> [compiler documentation] should in enough detail address everything
>> that is not standard C -- for example, how it handles bits, ports,
>> stack, variable banks, recursion, pointers etc.
>>
>> Don't go yell at the vendor before having read the docs... :)
>
> Current philosophy seems to be that a compiler should produce good  
> code from STANDARD C constructs, without having to resort to non-
> standard bit-set macros. avr-gcc had deprecated sbi/cbi "functions" in  
> favor of "just use var |=/&=~ bit", for example.

This is probably true, and it is a good thing. However, it is still in
"implementation-defined" land (that is, outside of what is specified in
the C language standard), and if you want to know what your compiler
does here, you have to consult the documentation.
For example, PORTB |= 2; resulting in a BSF instruction on a PIC is
expected, but with PORTB |= 3; things are not so clear anymore.

> After all, part of the point of using a C compiler is portability.
> Non-standard architecture-specific features should be avoided
> whenever possible.

Yes, but so should be architecture-specific expectations -- unless they
are founded in documentation or otherwise acquired knowledge of the
specific compiler :)

Gerhar

2011\05\31@153324 by William Benson

picon face



> Date: Sun, 29 May 2011 00:12:55 +0100
> From: oli.glaserspamKILLspamtalktalk.net
> To: .....piclistKILLspamspam.....mit.edu
> Subject: Re: [PIC] Introductory Book to C18?

> I would be wary of using the Microchip code in app notes for learning;
> much of it is just basic functional examples to get you started, rather
> than advice on how you should write the code.


Where can you find a book "How you Write the CODE?"                                          

2011\05\31@154301 by Oli Glaser

flavicon
face
On 31/05/2011 20:33, William Benson wrote:
>
>> >  Date: Sun, 29 May 2011 00:12:55 +0100
>> >  From:EraseMEoli.glaserspam_OUTspamTakeThisOuTtalktalk.net
>> >  To:piclistspamspam_OUTmit.edu
>> >  Subject: Re: [PIC] Introductory Book to C18?
>> >  I would be wary of using the Microchip code in app notes for learning;
>> >  much of it is just basic functional examples to get you started, rather
>> >  than advice on how you should write the code.
> Where can you find a book "How you Write the CODE?"        

I'm not sure what you mean here?

2011\05\31@155549 by William Benson

picon face



> Date: Tue, 31 May 2011 20:42:51 +0100
> From: @spam@oli.glaserKILLspamspamtalktalk.net
> To: KILLspampiclistKILLspamspammit.edu
> Subject: Re: [PIC] Introductory Book to C18?
>
> On 31/05/2011 20:33, William Benson wrote:
> >
> >> >  Date: Sun, 29 May 2011 00:12:55 +0100
> >> >  From:RemoveMEoli.glaserTakeThisOuTspamtalktalk.net
> >> >  To:spamBeGonepiclistspamBeGonespammit.edu
> >> >  Subject: Re: [PIC] Introductory Book to C18?
> >> >  I would be wary of using the Microchip code in app notes for learning;
> >> >  much of it is just basic functional examples to get you started, rather
> >> >  than advice on how you should write the code.

> > Where can you find a book "How you Write the CODE?"        
>
> I'm not sure what you mean here?
>
TakeThisOuToli.glaserEraseMEspamspam_OUTtalktalk.net said "I would be wary of using the Microchip code in app notes for learning;                                        much of it is just basic functional examples to get you started, rather                                         than advice on how you should write the code."
It looks like it trying to say, the way you write the CODE is the most important the basic code itself?  But not sure what you mean either?  That why I was asking? BEN                                            

2011\05\31@163317 by Oli Glaser

flavicon
face
On 31/05/2011 20:55, William Benson wrote:
{Quote hidden}

Ah I see.
If I understand you correctly, I didn't mean that the way the code "looks" or the style is more important than what it does, no.
What I meant by "write the code" was how you should structure and perform certain tasks efficiently.
For example, there is often several ways to do the same thing, but some ways will be "better" than others as they will be easier to read/change/port and so on.

What I was getting at is a lot of the example code in many app notes is an "isolated" example just to get the point across.
They are not usually concentrating on the code itself, (i.e. whether it could be easily changed, ported, how efficient it is) rather the idea behind it. There will probably be an assumption that you are competent in C and often little explanation of why certain constructs are used or alternative options.
This is why I would say it would be better to learn from a book dedicated to learning good coding practices, that goes into great detail on these things.
I know it's badly explained (rushing) but I hope that makes some sense

2011\05\31@170458 by Jan-Erik Soderholm

face picon face
Oli Glaser wrote 2011-05-31 22:33:
{Quote hidden}

Yes, quite a few mixes learning C, Asm, C++, Java, whatever with
learning *programming*... :-)

That is defenitely not the same thing. C, Java and so on can be
learned with a book, course or whatever. True programming skills
are only leared by time, probably many years. And it is mostly
not language/tool specific.

Jan-Erik.


'[PIC] Introductory Book to C18?'
2011\06\01@100049 by Gerhard Fiedler
picon face
William Benson wrote:

>> Date: Sun, 29 May 2011 00:12:55 +0100
>> From: KILLspamoli.glaserspamBeGonespamtalktalk.net
>> To: EraseMEpiclistspamEraseMEmit.edu
>> Subject: Re: [PIC] Introductory Book to C18?
>
>> I would be wary of using the Microchip code in app notes for learning;
>> much of it is just basic functional examples to get you started, rather
>> than advice on how you should write the code.
>
> Where can you find a book "How you Write the CODE?"

For C, I recommend Kernighan & Ritchie, The C Programming Language. It's
a classic, but still one of the best tutorials around. It's almost a
must if you want to understand C and feel you don't. For general
programming, try Steve McConnell's Code Complete. Also a classic, and
very useful for all languages.

Gerhar

2011\06\01@103853 by William Benson

picon face

Thank you One & All
BEN

{Quote hidden}

> -

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...