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'm using c51. i get an error"not in formal parameter list" and cannot find a way to solve it,so i'm here to ask for ur help,please. Here is my code: #include <stdio.h> #include <absacc.h> #include <reg51.h> #define uchar unsigned char void serial() interrupt 4 using 1 uchar time[6],date[6]; uchar latitude[9],longitude[9]; uchar semisphere_f,semisphere_s; uchar input_data="GPRMC"; uchar data_in; int numbercomma; bit flag; if(SBUF==0x24) { if(SBUF==input_data) { flag=1; numbercomma=0; } else flag=0; } if(flag==1) { if(SBUF==0x2c) { numbercomma++; } }
if(numbercomma==2) { data_in=SBUF; } if (data_in=A) { swith(numbercomma) { case 1:time[6]=SBUF; case 3:latitude[9]=SBUF; case 4:semisphere_f=SBUF; case 5:longitude[9]=BUF; case 6:semisphere_s=SBUF; case 9:date[6]=SBUF; default:;break; } }
main() { TMOD=0x21; TH1=0xfa; TL1=0xfa; SCON=0x50; ES=1; EA=1; } Thank you!
. . . if(numbercomma==2) { data_in=SBUF; } if (data_in=A) { swith (numbercomma) { case 1: time[6]=SBUF; case 3: latitude[9]=SBUF; case 4: semisphere_f=SBUF; case 5: longitude[9]=BUF; case 6: semisphere_s=SBUF; case 9: date[6]=SBUF; default: ; break; } }
But also ... did you copy/paste your code or did you re-type it into the message?
The 'swith' should surely be 'switch' (unless you've done something crazy like define swith as switch).
I very much doubt that you intend to have the case statements fall through like you've coded - So 'breaks' would be required.
i noticed that error and had correted it.i intend to use that "switch" to copy datas inputing by a device,it's continous,so i decided not to use the "break".
this is my new code
#include <stdio.h> #include <absacc.h> #include <reg51.h> #define uchar unsigned char void serial() interrupt 4 using 1 { uchar time[6],date[6]; uchar latitude[9],longitude[9]; uchar semisphere_f,semisphere_s; uchar input_data="GPRMC"; uchar data_in; int numbercomma; bit flag; if(SBUF==0x24) { if(SBUF==input_data) { flag=1; numbercomma=0; } else flag=0; } if(flag==1) { if(SBUF==0x2c) { numbercomma++; } } if(numbercomma==2) { data_in=SBUF; } if (data_in="A") { switch(numbercomma) { case 1:time[6]=SBUF; case 3:latitude[9]=SBUF; case 4:semisphere_f=SBUF; case 5:longitude[9]=SBUF; case 6:semisphere_s=SBUF; case 9:date[6]=SBUF; default:;break; } } } main() { TMOD=0x21; TH1=0xfa; TL1=0xfa; SCON=0x50; ES=1; EA=1; }
how do you think about it,will it work? Waiting for your reply,thanks.
I'm not going to make comments on the overall functionality, but breaks in the switch statement are surely going to be necessary.
You'll get an interrupt when a single character is received, but you will potentially read SBUF into six variables. Are you expecting to receive up to six successive characters? or are you expecting to set all six variables to the same value?
I'll leave you to consider it.
The way to think about it is this:
First, gain an understanding of how the underlying hardware works;
Then write code to work with that.
To understand how the 8051 architecture works, you will need to study the so-called "bible" for the 8051 - links here: www.8052.com/.../120112
There's also a tutorial here: http://www.8052.com/tutorial
And booklists here: http://www.keil.com/books/8051books.asp http://www.8052.com/book/ www.8052.com/.../174564
I think you might also want to brush-up on your 'C' ?