Getting Error C141: syntax error near 'void' HELP
HERE IS THE CODE---
#include <reg51.h> void MSDelay (unsigned int); sbit input=P0^0; sbit input2=P0^1; sbit LLight=P1^1; sbit RLight=P1^2; sbit Bell=P1^3; void main(void) { unsigned int i; input=0xFF; //'input' Input Port// input2=0xFF; //'input2' Input Port// LLight=0x00; //'LLight' As Output Port// RLight=0x00; //'RLight' As Output Port// Bell=0x00; //'Bell' As Output Port// { LLight=00; RLight=00; Bell=00; while (1) { { Bell=1; LLight=1; RLight=0; MSDelay (2500); } { Bell=1; LLight=0; RLight=1; MSDelay (2500); } } } void MSDelay (unsigned int itime) { unsigned int i, j; for (i=0;i<itime;i++) for (j=0;j<1275;j++); }
So why didn't you post a properly indented source code, making use of the very clearly presented information how to post source code?
Would that have made it too easy to spot the compilation error?
#include <reg51.h> void MSDelay (unsigned int); sbit input=P0^0; sbit input2=P0^1; sbit LLight=P1^1; sbit RLight=P1^2; sbit Bell=P1^3; void main(void) { unsigned int i; input=0xFF; //'input' Input Port// input2=0xFF; //'input2' Input Port// LLight=0x00; //'LLight' As Output Port// RLight=0x00; //'RLight' As Output Port// Bell=0x00; //'Bell' As Output Port// { LLight=00; RLight=00; Bell=00; while (1) { { Bell=1; LLight=1; RLight=0; MSDelay (2500); } { Bell=1; LLight=0; RLight=1; MSDelay (2500); } } } <=== this is not the end of main() !!! void MSDelay (unsigned int itime) { <=== a function inside a function? unsigned int i, j; for (i=0;i<itime;i++) for (j=0;j<1275;j++); } <=== strange that your braces didnt' allow you to return back to the left margin when you consumed your last right brace...
Indentation really do help to keep track of { and } and what part of the code that is included in a while loop.
By the way - having two loops for a delay isn't exactly a good way. You call your function MSDelay which could be thought to mean milliseconds of delay or maybe megaseconds of delay. But without binding the delay to some real hardware, you have no way of knowing what actual delay you get. That's a reason why your processor got timer support.
And one more thing: Comments starting with // continues to the end of the line - so no need for any extra // at the end.
Unfortunately, one of the problems in not posting correctly is that it is not always possible to rebuild the code.
input=0xFF; //'input' Input Port// input2=0xFF; //'input2' Input Port// LLight=0x00; //'LLight' As Output Port// RLight=0x00; //'RLight' As Output Port// Bell=0x00; //'Bell' As Output Port// {
Might be this.
input=0xFF; //'input' Input Port // input2=0xFF; //'input2' Input Port // LLight=0x00; //'LLight' As Output Port // RLight=0x00; //'RLight' As Output Port // Bell=0x00; //'Bell' As Output Port // {
Or it might be a combination of the two. Someone might make an educated guess, but it's still basically a guess.
Yes.
What we do know is that the OP likes to assign 8-bit values to 1-bit variables:
sbit input=P0^0; ... input=0xFF;
And sometimes surprise by switching to octal numbers:
LLight=00;
im sorry ill try with the code again
#include <reg51.h> void MSDelay (unsigned int); sbit input = P0^0; sbit input2 = P0^1; sbit LLight = P1^1; sbit RLight = P1^2; sbit Bell = P1^3; void main(void) { unsigned int i; input = 0xFF; //'input' Input Port// input2 = 0xFF; //'input2' Input Port// LLight = 0x00; //'LLight' As Output Port// RLight = 0x00; //'RLight' As Output Port// Bell = 0x00; //'Bell' As Output Port// { LLight = 00; RLight = 00; Bell = 00; while (1) { { Bell = 1; LLight = 1; RLight = 0; MSDelay (2500); } { Bell = 1; LLight = 0; RLight = 1; MSDelay (2500); } } } void MSDelay (unsigned int itime) { unsigned int i, j; for (i = 0; i < itime; i++) for(j = 0; j < 1275; j++); }
what my attempt here was to assign P0^0 to be an input (input=P0^0) and (LLight=00;)...reset it before it enters the while loop.
Why did you repost the source code (now with tags) without having fixed the issue I pointed out in my first post? Didn't my "arrow" and indenting clearly indicate your brace mismatch issue?
That was just me posting the original code in the right format, like requested...
In this code I fixed the issue of the void() bracket, and also fixed a missing closing bracket right before the while loop, and doing all this solved my syntax error.
#include <reg51.h> void MSDelay (unsigned int); sbit input = P0^0; sbit input2 = P0^1; sbit LLight = P1^1; sbit RLight = P1^2; sbit Bell = P1^3; void main(void) { unsigned int i; input = 0xFF; //'input' Input Port// input2 = 0xFF; //'input2' Input Port// LLight = 0x00; //'LLight' As Output Port// RLight = 0x00; //'RLight' As Output Port// Bell = 0x00; //'Bell' As Output Port// { LLight = 0; RLight = 0; Bell = 0; i=0; } <================Missed This Closing Bracket while (1) { { Bell = 1; LLight = 1; RLight = 0; MSDelay (2500); } { Bell = 1; LLight = 0; RLight = 1; MSDelay (2500); } } } <=============End Of Main Bracket void MSDelay (unsigned int itime) { unsigned int i, j; for (i = 0; i < itime; i++) for(j = 0; j < 1275; j++); }
Don't you find it easier to read the code if you make sure the indentation level follows the number of open braces?
Yes I do. Thank You.
To begin with, I had the formatting right when i pasted the code in, but because i forgot the 'pre' and '/pre' it posted all messed up.
I appreciate the help, and I hope it works the way I want it to, this while loop was a main concern of mine.
I plan on making the while loop run off of two inputs (input, and input2)...which are hook up to a sensor similar to what you would find in a garage...and when either one of them is positive/tripped, it will run through the while loop, making the either the LLight (Left Light), or the RLight (Right Light)...dependant on the loop, with the bell going off the whole time.