CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

END OF MAIN AND END OF WHILE

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rvwills



Joined: 20 Dec 2014
Posts: 10

View user's profile Send private message

END OF MAIN AND END OF WHILE
PostPosted: Thu Jan 01, 2015 3:49 pm     Reply with quote

Forum Members:

I am new to ANSI C and have purchased the CCS PCWH/PIC18F4520 Development Kit to begin my study of ANSI C.

The first program in the PIC18F4520 Exercise Book (#3) is as follows.

Code:
#include <18f4520.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#define GREEN_LED PIN_A5


void main () {
      while (TRUE) {
            output_low (GREEN_LED);
            delay_ms (1000);
            output_high (GREEN_LED);
            delay_ms (1000);

           // Target = FC18F4520
           // Compiler = PCH 16 BIT

This neither compiles nor programs the PIC18F4520.

I questioned if there there should an 'end of while' brace and also an 'end of main' brace. So I added an 'end of while' brace and an 'end of main' brace as follows.

Code:
#include <18f4520.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#define GREEN_LED PIN_A5


void main () {
      while (TRUE) {
            output_low (GREEN_LED);
            delay_ms (1000);
            output_high (GREEN_LED);
            delay_ms (1000);
                         }
                   }

           // Target = FC18F4520
           // Compiler = PCH 16 BIT

This program now compiles, programs and runs as expected.

Question: What am I missing?

Thanks,

Bob Wills
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Jan 01, 2015 3:54 pm     Reply with quote

Hi Bob,
You haven't missed a thing.
Actually it seems they missed the ending braces in the book.
You are correct.

When translating from the actual to print it seems that maybe the printer (then the proof reader) missed this.

Virtually every computer book I have read or owned has this kind of translation errors..
_________________
Google and Forum Search are some of your best tools!!!!
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Thu Jan 01, 2015 8:57 pm     Reply with quote

I think that is covered by our favorite phrase when I was in college "it is left as an exercise for the student". Some editors will show you matching parens, braces, brackets etc. ( I date myself here) in the Unix "vi" editor, you turned on "show match" and it would blink the matching brace when you entered the second one. Simple text editors don't do it, but many "language aware" editors do show you the matches like that. I always found it handy.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
rvwills



Joined: 20 Dec 2014
Posts: 10

View user's profile Send private message

PostPosted: Fri Jan 02, 2015 12:46 am     Reply with quote

dyeatman:
gpsmikey:

Thank you both for your comments -- I'm looking forward to my ANSI C studies.

Yes mikey, I also remember a college, particularly a professor who stated that our weekly quizzes '...will include the content of all of the class member's weekly assignments, the textbook and what I think you should have read..."

I also date myself by stating that I used Unix about 35 years ago before retiring from 'The Bell System'

Cheers -- time to freshen my coffee,

Bob
jeremiah



Joined: 20 Jul 2010
Posts: 1328

View user's profile Send private message

PostPosted: Fri Jan 02, 2015 9:26 pm     Reply with quote

I thought I might point out that the CCS compiler isn't really ANSI C. There is an ANSI mode, but I don't recall if it is fully ANSI compliant. If I remember correctly, it is more like K & R with modifications + some C++ stuff.
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Sat Jan 03, 2015 5:07 am     Reply with quote

It's 98%. Where CCS generally falls down is with complex structures and data formats, but it is very close the ANSI C89 or C90. Note the C89/90 though.
If you go through the second edition of K&R, the first 'ANSI C' edition, just about everything there works 'as is', except (of course) for the stuff involving a file system.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group