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

I am doing project on rfreader, door locking system

RFreader reads the input fron the ID-card and sends it to microcontroller. mcu compares the same no with the available no's. If no. is matched then generates output pin high. Plz help in me in implementing the code in c.Total there are 250 different IDs available.

Parents Reply Children
  • ya I am sure, there is no order or series. please give me some clue.. there are a total of 200 no... rfreader reads the no and sends it yo mcu through rs232. how to compare the received no with other 200 nos?

    main()
    {
    unsigned char a[10];
    a[10]=serial_receive();
    switch(a)
    {
     case 9481300500: open_door();
                      break;
     case 9980428098: open_door();
                      break;
      .
      .
      .
      .
      .
     default:don't_open();
    }
    

  • I have already given you a clue (aka "hint")

  • unsigned char a[10];
    

    So 'a' is an array

    switch(a)
    


    Do you think that the 'C' switch statement work that way with arrays?

    What does your 'C' Textbook say...?

  • do you want me to take a as a string i.e a="9481300500" and compare this with the other string of nos?

  • I want you to think!

    You should know what the definition of a "string" is in the 'C' programming language; if not, get back to that textbook...

    Is the "number" that you receive actually suitable for use as a 'C' string?

  • I don't know. I think the output of rs232 is group of characters not exactly string...
    give me some topics that I need to study related to this project...

  • => give me some topics that I need to study related to this project...

    www.exforsys.com/.../c-arrays.html
    www.exforsys.com/.../handling-of-character-strings-in-c.html

    and

    '1' is not equal to 1

    "1" is not equal to '1'

    11 is not equal to 0x11

     case 9481300500: open_door();
                      break;
     case 9980428098: open_door();
                      break;
    


    and you also need to well define the data type of 9481300500, 9980428098.

    www.exforsys.com/.../c-programming-language-data-types.html
    www.exforsys.com/.../c-programming-data-types-part-2.html

  • unsigned char a[10];
    a[10]=serial_receive();
    

    The above is incorrect either.

    Maybe start from:

    void main(void)
    {
      unsigned char rx_data;
    
      for(;;)
      {
        rx_data = serial_receive();
    
        switch(rx_data)
        {
          case '1': open_door();
       // case  1 : open_door();
            break;
          case '9': open_door();
       // case  9 : open_door();
            break;
           .
           .
           .
           .
           .
          default: dont_open();
        }
    
        proper_delay();
      }
    }
    

  • will you plz tell me how rfreader reads? whether it reads the no as string, as constant or, as char... when tested I am getting $9481300500 as output on the hyperterminal.

  • #include<reg51.h>
    void boud_rate()
    {
            SCON = 0x50;
            TMOD = 0x20;                /* timer 1, mode 2, 8-bit reload */
            TH1  = 0xFD;                /* reload value for 2400 baud */
            TR1  = 1;
            TI   = 1;
    }
    char serial_receive()
    {
        char chr;        /* variable to hold the new character */
            while (RI != 1) {;}
            chr = SBUF;
            RI = 0;
            return(chr);
    }
    
    void main(void)
    {
    
            boud_rate();
      unsigned char rx_data;
    
      for(;;)
      {
        rx_data = serial_receive();
    
        switch(rx_data)
        {
    //      case '1': open_door();
              case 0067892341 : open_door();
            break;
    //      case '9': open_door();
           case 0045780034 : open_door();
            break;
    
          default: dont_open();
        }
    
        proper_delay();
      }
    }
    

    errors

    'rx_data':undefined identifier
     illigal octal digit
    

    please tell me how to overcum these errors

  • #include<reg51.h>
    void boud_rate()
    {
            SCON = 0x50;
            TMOD = 0x20;                /* timer 1, mode 2, 8-bit reload */
            TH1  = 0xFD;                /* reload value for 2400 baud */
            TR1  = 1;
            TI   = 1;
    }
    char serial_receive()
    {
        char chr;        /* variable to hold the new character */
            while (RI != 1) {;}
            chr = SBUF;
            RI = 0;
            return(chr);
    }
    
    void main(void)
    {
    
            boud_rate();
      unsigned char rx_data;
    
      for(;;)
      {
        rx_data = serial_receive();
    
        switch(rx_data)
        {
    //      case '1': open_door();
              case 0067892341 : open_door();
            break;
    //      case '9': open_door();
           case 0045780034 : open_door();
            break;
    
          default: dont_open();
        }
    
        proper_delay();
      }
    }
    

    errors

    'rx_data':undefined identifier
     illigal octal digit
    

    please tell me how to overcum these errors

  • #include<reg51.h>
    void boud_rate()
    {
            SCON = 0x50;
            TMOD = 0x20;                /* timer 1, mode 2, 8-bit reload */
            TH1  = 0xFD;                /* reload value for 2400 baud */
            TR1  = 1;
            TI   = 1;
    }
    char serial_receive()
    {
        char chr;        /* variable to hold the new character */
            while (RI != 1) {;}
            chr = SBUF;
            RI = 0;
            return(chr);
    }
    
    void main(void)
    {
    
            boud_rate();
      unsigned char rx_data;
    
      for(;;)
      {
        rx_data = serial_receive();
    
        switch(rx_data)
        {
    //      case '1': open_door();
              case 0067892341 : open_door();
            break;
    //      case '9': open_door();
           case 0045780034 : open_door();
            break;
    
          default: dont_open();
        }
    
        proper_delay();
      }
    }
    

    errors

    'rx_data':undefined identifier
     illigal octal digit
    

    please tell me how to overcum these errors

  • #include<reg51.h>
    void boud_rate()
    {
            SCON = 0x50;
            TMOD = 0x20;                /* timer 1, mode 2, 8-bit reload */
            TH1  = 0xFD;                /* reload value for 2400 baud */
            TR1  = 1;
            TI   = 1;
    }
    char serial_receive()
    {
        char chr;        /* variable to hold the new character */
            while (RI != 1) {;}
            chr = SBUF;
            RI = 0;
            return(chr);
    }
    
    void main(void)
    {
    
            boud_rate();
      unsigned char rx_data;
    
      for(;;)
      {
        rx_data = serial_receive();
    
        switch(rx_data)
        {
    //      case '1': open_door();
              case 0067892341 : open_door();
            break;
    //      case '9': open_door();
           case 0045780034 : open_door();
            break;
    
          default: dont_open();
        }
    
        proper_delay();
      }
    }
    

    errors

    'rx_data':undefined identifier
     illigal octal digit
    

    please tell me how to overcum these errors

  • #include<reg51.h>
    void baud_rate()
    {
            SCON = 0x50;
            TMOD = 0x20;                /* timer 1, mode 2, 8-bit reload */
            TH1  = 0xFD;                /* reload value for 2400 baud */
            TR1  = 1;
            TI   = 1;
    }
    char serial_receive()
    {
        char chr;        /* variable to hold the new character */
            while (RI != 1) {;}
            chr = SBUF;
            RI = 0;
            return(chr);
    }
    
    void main(void)
    {
    #include<reg51.h>
    void boud_rate()
    {
            SCON = 0x50;
            TMOD = 0x20;                /* timer 1, mode 2, 8-bit reload */
            TH1  = 0xFD;                /* reload value for 2400 baud */
            TR1  = 1;
            TI   = 1;
    }
    char serial_receive()
    {
        char chr;        /* variable to hold the new character */
            while (RI != 1) {;}
            chr = SBUF;
            RI = 0;
            return(chr);
    }
    
    void main(void)
    {
    
            boud_rate();
      unsigned char rx_data;
    
      for(;;)
      {
        rx_data = serial_receive();
    
        switch(rx_data)
        {
            case 0067892341 : open_door();
                          break;
            case 0045780034 : open_door();
                           break;
    
                     default: dont_open();
        }
    
        proper_delay();
      }
    }