#include<reg51.h> #include<lcd.h> #include<uart.h>
sbit lamp=P2^0; sbit motor=P2^1; //NOTES:
//1: This code may be distributed and modified freely . //2: External Crystal of 11.0592 MHz is assumed. //3. 16x2 lcd Modules is being operated in Nibble Mode. //4: Connections to the lcd are assumed as followed:
// RS -> P1.0 // RW -> P1.1 // E -> P1.2 // D4,D5,D6,D7 -> P1.4,P1.5,P1.6,P1.7
#define lcd_DATA P1
sbit lcd_rs = P1^0;
sbit lcd_rw = P1^1; //Must Always be low to allow data to be sent to lcd
sbit lcd_en = P1^2;
void delay_ms(unsigned int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<124;j++); }
void lcd_enable() { lcd_en = 1; //High to low transition delay_ms(1); lcd_en = 0; }
void lcd_cmd(unsigned char cmd) { lcd_rs = 0; //cmd Mode lcd_DATA = ((cmd & 0xF0)|0x04); lcd_enable(); lcd_DATA = (((cmd<<4) & 0xF0)|0x04); lcd_enable(); delay_ms(1); }
void lcd_data(unsigned char ascii) { lcd_rs = 1; //Data Mode lcd_DATA = ((ascii & 0xF0)|0x05); lcd_enable(); lcd_DATA = (((ascii<<4) & 0xF0)|0x05); lcd_enable(); delay_ms(1); }
void lcd_init() { P0=0x00;
lcd_cmd(0x02); //Enable 4 bit mode
lcd_cmd(0x28); //Set interface 4 bit 2 line
lcd_cmd(0x08); //Enable display/cursor
lcd_cmd(0x06); //Set cursor move, Move cursor right
lcd_cmd(0X0C); //Turn on display
}
void lcd_gotoxy(unsigned char row,unsigned char column) //move cursor to the specified position { if(row==0) { lcd_cmd(0x80+column); } else if(row==1) { lcd_cmd(0xC0+column); } } void lcd_number(int val,unsigned int field_length) // Function to display number { char str[5]={0,0,0,0,0}; int i=4,j=0; while(val) { str[i]=val%10; val=val/10; i--; } if(field_length==-1) while(str[j]==0) j++; else j=5-field_length;
if(val<0) lcd_data('-'); for(i=j;i<5;i++) { lcd_data(48+str[i]); } }
void lcd_string(unsigned char *str) {
while(*str!='\0') //Till null character is encountered { lcd_data(*str); str++; } }
void lcd_stringxy(unsigned char row, unsigned char col, unsigned char *lcd_string) { lcd_gotoxy(row,col); while (*lcd_string) { lcd_data(*lcd_string++); } } void lcd_numberxy(unsigned char row, unsigned char col,int val,unsigned int field_length) { char str[5]={0,0,0,0,0}; int i=4,j=0;
lcd_gotoxy(row,col);
while(val) { str[i]=val%10; val=val/10; i--; } if(field_length==-1) while(str[j]==0) j++; else j=5-field_length;
if(val<0) lcd_data('-'); for(i=j;i<5;i++) { lcd_data(48+str[i]); }
void uart_init(void) // INITIALIZE SERIAL PORT { TMOD = 0x20; // Timer 1 IN MODE 2-AUTO RELOAD TO GENERATE BAUD RATE TH1 = 0xFD; // LOAD BAUDRATE TO TIMER REGISTER SCON = 0x50; // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT, REN ENABLED TR1 = 1; // START TIMER } void tx_data(unsigned char serialdata) { SBUF = serialdata; // LOAD DATA TO SERIAL BUFFER REGISTER while(TI == 0); // WAIT UNTIL TRANSMISSION TO COMPLETE TI = 0; // CLEAR TRANSMISSION INTERRUPT FLAG } unsigned rx_data(void) { while(RI == 0); // WAIT UNTIL DATA IS RECEIVED RI = 0; // CLEAR FLAG return SBUF; // RETURN SERIAL DATA } void tx_string(unsigned char *str) { while(*str) { tx_data(*str); str++; }
} // END OF PROGRAM
void main() { unsigned char read[4],bulb[4]="abcd",fan[4]="bcde"; unsigned char i,count1,count2,j=0,k=0; motor=lamp=0; lcd_init(); uart_init(); delay_ms(50); lcd_stringxy(0,0,"Password based"); lcd_stringxy(1,0,"Load control"); delay_ms(5000); lcd_cmd(0x01); while(1) { count1=count2=0; lcd_cmd(0x80); for(i=0;i<4;i++) { read[i]=rx_data(); }
for(i=0;i<4;i++) { lcd_data(read[i]); } for(i=0;i<4;i++) { if(read[i]==bulb[i]) count1++; if(read[i]==fan[i]) count2++; }
if(count1==4) { j++; if(j%2==1) lcd_stringxy(0,6,"Bulb on "); else lcd_stringxy(0,6,"Bulb off"); motor=~motor; } else if(count2==4) { k++; if(k%2==1) lcd_stringxy(1,0,"Fan on "); else lcd_stringxy(1,0,"Fan off"); lamp=~lamp; } else { lcd_stringxy("pwd is wrong "); }
} }
getting error- syntax error near 'void'... pls help....
Learn how to read the posting instuctions for source code. Identify the line where the syntax error occurs. Use something like /* here */ rather than just a number. Above all think and read carefully, the compiler tells you what it is objecting too.
"syntax error near 'void'"
That is not the complete information the compiler gave you.
Why do you strip away much of the useful information and expect others to help you with less information available than you, yourself has?
Would you want to manually count line numbers when locating which line the error relates to? You, on your side, has an editor that can enumerate the individual source lines. And the tool can jump from error to line.
What help would we have to locate the specific source code line - if we ignore the 'tiny' issue that you somehow didn't think the line number was an important part of the error message...
this is the part of the program.... void uart_init(void) // INITIALIZE SERIAL PORT { TMOD = 0x20; // Timer 1 IN MODE 2-AUTO RELOAD TO GENERATE BAUD RATE TH1 = 0xFD; // LOAD BAUDRATE TO TIMER REGISTER SCON = 0x50; // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT, REN ENABLED TR1 = 1; // START TIMER } and we are getting error for the very first line.. and the error is..
syntax error near 'void'
You still haven't considered the meaning of: "Learn how to read the posting instuctions for source code."
And you post only code from _after_ the error. Haven't you considered that many errors actually are caused by something being wrong on a line just before the line where the compiler gets stuck?
Did you consider to count the number of } in the function directly before the error?
void lcd_numberxy(unsigned char row, unsigned char col,int val,unsigned int field_length) { char str[5]={0,0,0,0,0}; int i=4,j=0; lcd_gotoxy(row,col); while(val) { str[i]=val%10; val=val/10; i--; } if(field_length==-1) while(str[j]==0) j++; else j=5-field_length; if(val<0) lcd_data('-'); for(i=j;i<5;i++) { lcd_data(48+str[i]); } void uart_init(void) // INITIALIZE SERIAL PORT { TMOD = 0x20; // Timer 1 IN MODE 2-AUTO RELOAD TO GENERATE BAUD RATE ...
Don't you think - if you use proper indentation - that it looks really, really strange where you try to start your uart_init() function?
And don't you think that proper indentation and following the posting instructions makes it so very much more obvious what is wrong?
That just might be a reason why people do use indentation when coding...