This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

help!!!!

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!

Parents Reply Children
  • The instructions are quite clearly stated:

    www.danlhenry.com/.../keil_code.png

    aren't they?

  • Thanks for ur help,it is so important.it's my first time posting message here, i didn't notice that note,sorry for
    the inconvenience.i will remember it the next time.

  • .
    .
    .
      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' ?

  • "case 1:time[6]=SBUF;"

    Note that besides the missing breaks, SBUF contains a single character. It loos from your code like you think that you are assigning six characters to time array. You are not. You are only assigning to the index 6 (the seven'th position in the array).

    But time[] only contains 6 entries, accessible as index 0 to 5.

    And who assigns values to time[0], time[1], time[2], time[3], time[4] and time[5]? Are you happy with having these positions constantly zero-filled from the memory clear on startup?