View previous topic :: View next topic |
Author |
Message |
rvwills
Joined: 20 Dec 2014 Posts: 10
|
END OF MAIN AND END OF WHILE |
Posted: Thu Jan 01, 2015 3:49 pm |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Thu Jan 01, 2015 3:54 pm |
|
|
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
|
|
Posted: Thu Jan 01, 2015 8:57 pm |
|
|
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
|
|
Posted: Fri Jan 02, 2015 12:46 am |
|
|
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: 1358
|
|
Posted: Fri Jan 02, 2015 9:26 pm |
|
|
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: 19552
|
|
Posted: Sat Jan 03, 2015 5:07 am |
|
|
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. |
|
|
|