We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am a hardware system/circuit designer attempting to utilize a c8051f330 MCU to save a bunch of hardware in the design of some special test equipment. In an attepmt to learn how to design and implement C code I am using some small test programs. I have been unsuccesful in understanding and clearing a syntax error encountered in my attempt to program an interrupt service routine which uses the overflow of timer0 to generate interrupt 1. The section of the program listing whic has the error is: 69 void timer0_ISR (void) interrupt 1 70 { 71 1 72 1 LED = ~LED 73 1 } *** ERROR C141 IN LINE 73 OF SPECIAL_FLASH_PROGRAM.C: syntax error near '}' 74 75/*------------End of ALL STUFF---------------------*/ Thanks in advance for your help!! It's greatly appreciated. Dennis
how about a semicolon? what is LED defined as? Erik
Eric, The LED was defined earlier in the listing as "sbit LED = P1^3;" I'll try a semicolon after the interrupt fucntion, Then I'll reply as to the results first thing tomorrow as I've got to get to a meeting about 50 miles fron here in about an hour. I wrote this particular code exactly as it was used in an example program included with my Silicon Labs IDE stuff, what I mean to say is that I stole it. Thanks
Eric, I tried a semicolon at the end of the interrupt statement. The effect was to create a bunch more errors, associated with that statement. I've removed the semicolon. Why do you suppose that the error that I'm seeing is associated with the "end" brace of the statement? Does this mean that something is missing either before or after the brace?
"I am a hardware system/circuit designer ... attepmt to learn how to design and implement C code I am using some small test programs." Would you give a hardware design project to a software designer, and expect him to learn hardware design by just throwing together a few test circuits?! You really need to sit down with a good 'C' textbook, and begin at first principles! Here are some book lists: http://www.keil.com/books/8051books.asp http://www.8052.com/books.phtml It sounds like this is for your day job? If so, you should certainly do a 'C' course. If you say where you are, people may be able to recommend one.
void timer0_ISR (void) interrupt 1 { LED = ~LED; }
69 void timer0_ISR (void) interrupt 1 70 { 71 1 72 1 LED = ~LED 73 1 } *** ERROR C141 IN LINE 73 OF SPECIAL_FLASH_PROGRAM.C: syntax error near '}'
Andy, You're absolutely right on all counts. I currently have a couple of "C" books "C and the 8051" by Thomas Shultz and Embedded Programming with field programmable Mixed Signal uControllers" I realize that I need some classromm training in C Language programming and have registered for a course at the local community college (Bakersfield College, Bakersfield, CA). Unfortunately the next class does'nt begin until next Fall. In the meantime I'm attempting to get a head start. Thanks for your suggestions for books. I'll definitely pick up at least one of the two, probably the one from Keil, which you recommended. Thanks Again! Dennis
Do not make the mistake of buying another "C and '51" book. Those books do NOT teach you C, they are "the 51' for programmers already versed in C". A good self-teach book would be Kochan: "Programming in ANSI C". It is so much easier to learn the C fundamentals on the PC than on a '51. PS: there are posts here or on 8052.com about free Borland C compilers for the PC which will allow you to work through the examples Erik
Thanks for the tip. Dennis
Hey guys, I found my error. When I added the semicolon, as suggested earlier, I placed it incorrectly. When I corrected that I got 0 Warnings and 0 Errors. Thanks for your help, I'll probably be back for more. Dennis-
It is typical with programming languages (not just 'C') that one small mistake (eg, a misplaced semicolon) will cause very many error messages. This is because the compiler just loses sync with the source code - so nothing makes sense to it any more! Therefore, your general approach should be to fix the first reported error first; if subsequent error reports aren't immediately obvious, just rebuild and see if they go away!