getting problem in code showing lot of error - Page 1
Forum section: electronics / general

author: ect_09
author_rank: Contributor
timestamp: October 18, 2014, 07:30:21 am
content: am using MPLAB 8.90 and Hi-Tech compiler for PIC18F452i write this code but getting lot of error.its seems OK from my side. kindly check it.Code:#include<htc.h>__CONFIG(1, OSCSDIS & HSPLL);__CONFIG(2, BORDIS & PWRTDIS & WDTDIS);__CONFIG(3, CCP2RC1);__CONFIG(4, LVPEN & STVREN);__CONFIG(5, UNPROTECT);__CONFIG(6, WRTEN);__CONFIG(7, TRU);void sevenseg(char ch);void main(){TRISB=0;PORTB=0x00;sevenseg(ch);__delay_ms(1000);switch(ch){case'0': ch'0'; break;case'1': ch'1'; break;case'2': ch'2'; break;case'3': ch'3'; break;case'4': ch'4'; break;case'5': ch'5'; break;case'6': ch'6'; break;case'7': ch'7'; break;case'8': ch'8'; break;case'9': ch'9'; break;case'A': ch'A'; break;case'B': ch'B'; break;default ch'0': break;}void sevenseg(char ch){switch(ch){case'0': PORTB=0x3F; break;case'1': PORTB=0x06; break;case'2': PORTB=0x5B; break;case'3': PORTB=0x4F; break;case'4': PORTB=0x66; break;case'5': PORTB=0x6D; break;case'6': PORTB=0x7D; break;case'7': PORTB=0x07; break;case'8': PORTB=0x7F; break;case'9': PORTB=0x6F; break;case'A': PORTB=0x77; break;default: PORTB=0x3F;}}

author: Codemonkey
author_rank: Regular Contributor
timestamp: October 18, 2014, 07:50:10 am
content: You're missing a colon from this line:default ch'0': break;

author: Codemonkey
author_rank: Regular Contributor
timestamp: October 18, 2014, 07:53:15 am
content: Also, I'm not sure if writing ch'0' etc is valid. Certainly isn't with compilers I use. You should just replace all those instances with '0' for example.

author: mikerj
author_rank: Super Contributor
timestamp: October 18, 2014, 10:51:40 am
content: Firstly you are using a variable 'ch' in main() but you haven't defined any such variable, and you are passing this non-existant variable to your sevenseg() function before you have assigned it any value.What are you trying to do in the switch statement in main? ch'0', ch'1' etc. makes no sense at all. If you are simply trying to loop through all the seven segment characters then just use a for() loop and send the loop variable to the sevenseg() function.

author: miguelvp
author_rank: Super Contributor
timestamp: October 19, 2014, 01:16:46 am
content: Quote from: ect_09 on October 18, 2014, 07:30:21 amIf your intention is to display all of the digits counting from 0 to A incrementing once a second and repeating when A is reached, this will do such a thing:Code:#include<htc.h>__CONFIG(1, OSCSDIS & HSPLL);__CONFIG(2, BORDIS & PWRTDIS & WDTDIS);__CONFIG(3, CCP2RC1);__CONFIG(4, LVPEN & STVREN);__CONFIG(5, UNPROTECT);__CONFIG(6, WRTEN);__CONFIG(7, TRU);void sevenseg(char ch);void main(){TRISB=0;PORTB=0x00;char ch = 0;for(;;) {sevenseg(ch++); // post increment.__delay_ms(1000);// if we have reached 0x0a then reset to 0if (ch > 0x0a)ch = 0;}}void sevenseg(char ch){switch(ch) {case'0': PORTB=0x3F; break;case'1': PORTB=0x06; break;case'2': PORTB=0x5B; break;case'3': PORTB=0x4F; break;case'4': PORTB=0x66; break;case'5': PORTB=0x6D; break;case'6': PORTB=0x7D; break;case'7': PORTB=0x07; break;case'8': PORTB=0x7F; break;case'9': PORTB=0x6F; break;case'A': PORTB=0x77; break;default: PORTB=0x3F;}}But I'm not sure what you want to do, so I'm just guessing.Edit: to make it a bit more readable (the code that is)

author: Brutte
author_rank: Frequent Contributor
timestamp: October 19, 2014, 09:02:20 am
content: Quote from: ect_09 on October 18, 2014, 07:30:21 amam using google (..) kindly do not cross-post.

author: tggzzz
author_rank: Super Contributor
timestamp: October 19, 2014, 09:56:07 am
content: Quote from: ect_09 on October 18, 2014, 07:30:21 amTechniques you can and should use to find the problem yourself...Use a code-reformatter - sometimes if the re-formatted code looks strange, the strangeness can indirectly indicate where the problem is.Comment out complete functions, and recompile. If the only remaining error is that the function is undefined, then the error may be in the function.Create a new file and copy a small bit of the code across, and recompile. If that compiles as expected (i.e. you understand why the error messages are there), the copy a bit more across. Repeat.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 19, 2014, 11:12:11 am
content: When you have a lot of errors but things look ok, it is often a missing/extra scope bracket. { or } in c languages.The other important thing for tricky errors is to ignore the errors marked red in the ide and look at thefirsterror or warning in the compiler output.The compiler output is normally a view or window in an ide, and also it often in a log file.Find it and use it.

author: dannyf
author_rank: Super Contributor
timestamp: October 19, 2014, 01:09:52 pm
content: QuoteTake a good class in C.

author: SL4P
author_rank: Super Contributor
timestamp: October 20, 2014, 03:01:11 am
content: Always nice to see the OP appreciates the effort others have put in to his work.

author: glatocha
author_rank: Regular Contributor
timestamp: October 24, 2014, 10:15:36 am
content: Quote from: ect_09 on October 18, 2014, 07:30:21 amJust for curiosity, why don't you use the MPLABX with XC8 compiler?Does Microchip support MPLAB still?