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.
Compiling Error C:141 syntax error near 'void'
Please help me to compile this file. Need to create a Hex code of it finally. Also it seems a bigger fie and cannot be compiled with free versin ??? help me converting to hex code
/* Automated tap n flush system code- */ #include <regx51.h> #define MAXLINE 250 /* ----------------------- led on/off -------------------------------- */ #define l1_on P3_0 = 0 #define l1_off P3_0 = 1 #define l2_on P1_1 = 0 #define l2_off P1_1 = 1 #define IR_on P3_1 = 0; P3_2 = 0 #define IR_off P3_1 = 1; P3_2 = 1 /*-------------------- solenoid on/off ------------------------------*/ #define solenoid_on P3_0 = 0 #define solenoid_off P3_0 = 1 /*------------------- assign pins to switches -----------------------*/ #define sw1 |P1_7 #define sw2 |P1_6 #define sw3 |P1_5 #define sw4 |P1_4 #define sw5 |P1_3 #define sw6 |P1_2 #define sw7 |P3_4 #define sw8 |P3_5 #define sensor |P3_3 /*------------------- global status variables -----------------------*/ volatile char sensor_delay = 0; /* sensor detect hysterisis delay */ volatile char solenoid_delay = 0; /* solenoid start delay */ volatile char solenoid_duration = 0; /* solenoid duration */ volatile char start_mode = 0; /* '0' means solenoid starts after sensor gaining detection, '1' means after sensor losing detection */ volatile char stop_mode= 0; /* '0' means solenoid duration counts from its start, '1' means counts after sensor losing detection */ /* ------------------- delay options in seconds ---------------------- */ volatile char sensor_delay_s[] = {1,3,5,7}; /* sensor detect hysterisis delay */ volatile char solenoid_delay_s[] = {1,2,3,5}; /* solenoid start delay */ volatile char solenoid_duration_s[] = {1,5,8,10}; /* solenoid duration ----------------- 'x'seconds delay function ----------------------- */ void delay_s(char x) { char y; /* temporary variable */
TR0 = 1; /* start the timer */ while(x) /* loops for 'x' seconds */ {y = 0x64; /* loops 100 times */ while(y) /* loops for approx 'x/100' secs */ {if(TF0) /* check timer overflow */ {y--; TF0 = 0; /* reset overflow flag */ } x--; /* reduce number of seconds to go */ } TR0 = 0;TL0 = 0;TH0 = 0;TF0 = 0; /* stop & reset the timer */ } /*---------------- 'x/10'seconds delay function --------------------- */ void delay_ss(char x) { char y; // temporary variable TR0 = 1; // start the timer while(x) // loops for 'x/10' seconds { y = 0x0A; // loops 10 times while(y) /* loops for approx 'x/100' secs */ { if(TF0) /* check timer overflow */ { y--; TF0 = 0; /* reset overflow flag */ } } x--; /* reduce number of seconds to go */ } TR0 = 0;TL0 = 0;TH0 = 0;TF0 = 0; /* stop & reset the timer */ } /*------------------- sensor detect function ------------------------ */ void check_sensor_detect() { char x,y; /* temporary variables */ TMOD = T1_M1; /* set timer mode */ TL1 = 256-12; /* set timer frequency to 76.8kHz making IR led frequency as 38.4kHz at 50% duty cycle */ TR1 = 1; /* start the timer */
x = sensor_delay_s[sensor_delay]; y = 0; while(x+1) /* loops till 'x+1' consecutive detects */ { if(TF1) /* check timer overflow */ { TR1 = 0; /* stop the timer */ TF1 = 0; /* reset overflow flag */ TL1 = 256-12; /* reset timer frequency */ if(y<60) /* run IR led at 38kHz in bursts of 30 cycles once every second */ { TR1 = 1; /* start timer */
if(P3_1) { IR_on; } else { IR_off; } if(y==40) /* check sensor at end of 20 cycles */ { if(P3_3) { l2_on; x--; } else { l2_off; x = sensor_delay_s[sensor_delay]; } } y++; } else { y = 0; if (x == sensor_delay_s[sensor_delay]) {l2_on; delay_ss(1); l2_off; } delay_s(1); TR1=1; } } } TR1 = 0; /* stop the timer */ l2_off; x=3; while(x) /* blinking of led 3 times to denote sensor detect */ { l2_on; delay_ss(1); l2_off; delay_ss(1); x--; } } /* ------------------- sensor release function ------------------------ */ void check_sensor_release() { char x,y; /* temporary variables */ TMOD = T1_M1; /* set timer mode */ TL1 = 256-12; /* set timer frequency to 76.8kHz making IR led frequency as 38.4kHz at 50% duty cycle */ TR1 = 1; /* start the timer */ x = sensor_delay_s[sensor_delay]; y = 0;
while(x+1) /* loops till 'x+1' consecutive detects */ { if(TF1) /* check timer overflow */ { TR1 = 0; /* stop the timer */ TF1 = 0; /* reset overflow flag */ TL1 = 256-12; /* reset timer frequency */
if(y<60) { TR1 = 1; /* start timer */ if(P3_1) { IR_on; } else { IR_off; } if(y==40) { if(sensor) { l2_off; x--; } else { l2_on; x = sensor_delay_s[sensor_delay]; } }
y++; } else { y = 0; if (x == sensor_delay_s[sensor_delay]) {l2_off; delay_ss(1); l2_on; } delay_s(1); TR1=1; } } } TR1 = 0; /* stop the timer */ l2_off;
x=3; while(x) /* blinking of led 3 times to denote sensor release */ { l2_on; delay_ss(1); l2_off; delay_ss(1); x--; } } /* ---------------------- main function ------------------------------ */ void main (void) { char x=4; /* temporary variable */ P1 = 0xFF; /* set all pins of port 1 */ P3 = 0xFF; /* set all pins of port 3 */ delay_s(2); } while(x) /* startup blinking of led x times */ { l2_on; delay_ss(1); l2_off; delay_ss(1); x--; } while(1) /* infinite loop */ { /* setting configuration from switch positions */ if(sw1) sensor_delay = 1; if(sw2) sensor_delay = 1<<1;
if(sw3) solenoid_delay = 1; if(sw4) solenoid_delay = 1<<1;
if(sw5) solenoid_duration = 1; if(sw6) solenoid_duration = 1<<1;
if(sw7) start_mode = 1; else start_mode = 0;
if(sw8) stop_mode = 1; else stop_mode = 0;
delay_s(2); x = 5; } while(x) /* blinking of led 5 times to denote configuration complete */ { l2_on; delay_ss(1); l2_off; delay_ss(1); x--; } delay_s(1); check_sensor_detect(); if(start_mode) check_sensor_release(); delay_s(solenoid_delay_s[solenoid_delay]); solenoid_on; if(stop_mode) check_sensor_release(); delay_s(solenoid_duration_s[solenoid_duration]); solenoid_off; x = 20; sensor_delay = 0; solenoid_delay = 0; solenoid_duration = 0; start_mode = 0; stop_mode = 0; } }
I am not able to post it within 'pre' as it is exceeding 7000 characters... ... and you want help with "syntax error near void" when nobody can relate it to a line number you've got to be kidding.
BTW reading your original post "it does not fit with the eval" how did you get to here?
Erik
Thank you all who replied to me. My appology, I was in a bit hurry to get quick answers. I am planning to re-write the program in basic (.bas) and speding a little more time as I need to keep the program output (hex/binary) within 2KB. I realised that the chip doesnt allow more than 2KB. Regards,
And you think the program will be smaller if written in BASIC?
And you think the program will be smaller if written in BASIC? The guy doesn't really know about tool chains. And is also not interested in learning C.
Use assembly efficiently to build a code smaller in size.
And you think this guy is going to know how to write assembly at all - let alone efficiently...?!
The poor guy is in trouble. Let he not be demotivated to an extent that he may change the career.
But he doesnt even seem to show the signs of willingness to learn.
listen kid, you may Working hard and seriously, but surely not in the right direction.
You only need to post up to the point at which the error occurs.
If (but only if) you really need to post the whole thing, you could divide it between two (or more) posts.
When you post code, be sure to use only spaces for indentation - TAB characters will (almost) certainly not display as intended...
Let he not be demotivated to an extent that he may change the career.
show how silly the post is
I, personally will do everything I can to 'demotivate to change career' everyone that "doesnt even seem to show the signs of willingness to learn".
Or, to put it positively, motivate to change career...
sometimes people dont seem to know the nomenclatures of embedded world, especially the newbies (thats why they are asking for help).
I, personally will do everything I can to 'demotivate to change career' Gives a wrong impression about the people who reply on the forums to newbies. we are not here to decide the careers of others. we are not Career Counselors.
my opinions...
It's not about what they know - it's about whether they're willing to learn...