EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / copying rfid tag no in an array for comparision

copying rfid tag no in an array for comparision

|

Microcontroller › AVR › copying rfid tag no in an array for comparision

  • This topic has 11 replies, 4 voices, and was last updated 14 years ago by vamshi.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • February 22, 2011 at 8:01 am #741
    ajay
    Participant

    hello friends

    i am doing project on atmega16.

    my object is to copy RFID tag no in a array to compare its first char .

    so i can set pins of port A .

    i took ref from projec

    RFID interfacing with AVR microcontroller (ATmega16) using interrupts 

    project code  – AVR011

     

    the rfid tag nos are

    3E009341E60A card 1

    3E0093521CE3 card 2

    3E0093491BFF card3

     

    my problem is reader reads card bu pin related to that card is not get set.

     

    here is my code please help me

    thank you.

     

     

    code : –

     

    #define F_CPU 16000000UL
     
    #include<avr/io.h>
    #include<util/delay.h>
    #include<avr/interrupt.h>
    #define USART_BAUDRATE 9600
    #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
    #define  LED PORTA
    #define  LED0 PA0;                         
    #define  LED1 PA1;
    #define  LED2 PA2;
    unsigned char mybyte[13];

    void usart_init()
        {
             UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);         // Turn on the transmission and..

                                                                    // reception circuitry

            UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);    // Use 8-bit character sizes

            UBRRL = BAUD_PRESCALE;                                     // Load lower 8-bits of the baud rate value..
        
                                                                                                        // into the low byte of the UBRR register
            UBRRH = (BAUD_PRESCALE >> 8);                             // Load upper 8-bits of the baud rate

           
                                                                    // into the high byte of the UBRR register
        }
     
     
        int main(void)
           {
           
           
                DDRA=0xff;                             // LED_DATA port as output port
                cli();   
               usart_init();
           
               while(1);
              

               sei();
               return 0;
          }
     

     ISR (USART_RXC_vect)
        {
           
             i++;
            if(i = =13)
            {
                if( mybyte[0] ==65)                   //comper 12th character for identification
                {
                    PORTA=0x01;

                    LED = (1<<PA0);

                    _delay_ms(50);

                    PORTA=0x00;

                    LED=(0<<PA0);
                   
                }
                           
                else if( mybyte[0] == 70)                //comper 12th character for identification
                {
                    PORTA=0x02;

                    LED = (1<<PA1);

                    _delay_ms(50);

                    PORTA=0x02;

                    LED=(0<<PA1);
                   
                               
                }
                else if(mybyte[0] == 51)
                {
                    PORTA=0x04;

                    LED = (1<<PA2);

                    _delay_ms(50);

                    PORTA=0x04;

                    LED=(0<<PA2);
                   
                           
                }
               
          }
            mybyte = UDR; // Put the received byte value into the variable “

     

    }

    February 22, 2011 at 11:16 am #5579
    dagakshay
    Participant

    hello ljajay…

     

    in ISR

     

    1)

    PORTA=0x01;

    LED=(1<<PA0);

     

    both are same statments according to your program… why you writing the same statment twice??

     

    2)

    similarly you have done for PORTA=0x02 and LED=(1<<PA1);

     

    3)

    when you want to turn off your LED you wrote

    PORTA=0x02;

    LED=(0<<PA1);

     

    the first statment says you want to send a high signal on 1st pin of PORTA {PORTA=0x02} and the nest statment itself you turned it off {LED=(0<<PA1);} 

     

    4)

    i think you are bit confuse between PORTx and DDRx…

    PORTx is used to send the value on that port named “x”.

    and DDRx is used to set the direction of that port.

    refer to the link for more information about PORT and DDR syntax..

    http://www.engineersgarage.com/embedded/avr-microcontroller-projects/led-interface-circuit

     

    5)

    in starting of ISR u had done i++ mean the incoming byte will go to next array block..and you havn’t delcared the varialbe i any where in your code.

    let me make it more clear..

    i must be global variable according to your code 

    when you started the program the value of i will be zero but as soon you enter the ISR the value of variable i is incremented by one so here i becomes 1 then i checks all the if and else condition you wrote and at last the UDR value goes to

    mybyte=UDR;

    and here i=1, not zero;

    when i reaches thirteen you are compairing mybyte[0] which doesn’t make any sense…

     

    go through all the points and let me know your progress

    February 22, 2011 at 11:17 am #5580
    dagakshay
    Participant

    also refer to the link which might help you lot in some other way round

     

    http://www.engineersgarage.com/embedded/avr-microcontroller-projects/setting-input-pin-circuit 

    February 22, 2011 at 11:31 am #5582
    dagakshay
    Participant

    here i am writing the ISR for your code which might help you out check it

     

    uchar i; // declare i as a gloabl unsigned char


    ISR(USART_RXC_vect) 

     {

     i++;

    if(i = =13)

      {

       mybyte=UDR;

       if(mybyte[1]= = 65`)

           LED=(1<<LED0);

       if(mybyte[1]= =70)

           LED=(1<<LED1);

       if(mybyte[1]= = 51)

           LED=(1<<LED3);

       _delay_ms(1000);

      LED=0;

      i=0;

      }

    else

    mybyte=UDR;

    } /* end of ISR*/

     

    checkout and let me know weather it has worked???

    February 23, 2011 at 6:50 am #5594
    ajay
    Participant

    thank you dagakshay sir for your help .

     

    i am working with your ref isr.

     

    i want to know about rfid tag no.

     

    i have three tag

     

    3E009341E60A card 1

    3E0093521CE3 card 2

    3E0093491BFF card3

     

    these are ascii values seen on realterm

     

    their hex valuies are

     

    03 33 45 30 30 39 33 34 31 45 36 30 41 0A 0D  card 1

     

    03 33 45 30 30 39 33 35 32 31 43 45 33 0A 0D  card 2

     

    03 33 45 30 30 39 33 34 39 31 42 46 46 0A 0D  card 3

     

    now can you tell me  please about start bit stop bit & how much should be my array size and which element i should copare if i want to conpare A or F or 3 i.e. last charactor of tag no.

    i have modified code as follows.

     

    thanks again;   

     

    //Program to receive a 12 byte string from RFID and display it on LCD using serial interrupt

     
    #define F_CPU 16000000UL
     
    #include<avr/io.h>
    #include<util/delay.h>
    #include<avr/interrupt.h>
    #define USART_BAUDRATE 9600
    #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
    #define  LED PORTA
    #define  LED0 PA0;                         
    #define  LED1 PA1;
    #define  LED2 PA2;
    #define unsigned char mybyte[14], i=0;

    void usart_init()
        {
             UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);         // Turn on the transmission and..

                                                                                                                // reception circuitry

            UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);    // Use 8-bit character sizes

            UBRRL = BAUD_PRESCALE;                                     // Load lower 8-bits of the baud rate value..
        
                                                                    // into the low byte of the UBRR register
            UBRRH = (BAUD_PRESCALE >> 8);                             // Load upper 8-bits of the baud rate value..

           
                                                                    // into the high byte of the UBRR register
        }
     
     
    int main(void)
        {
           
           
            DDRA=0xff;                             // LED_DATA port as output port
            cli();   
            usart_init();
            _delay_ms(50);                // delay of 50 mili seconds
            sei();
            while(1);
            return 0;
        }
     

     ISR (USART_RXC_vect)
        {
           
                                   
               
                for(i=0;i<=13;i++)                   
                {
                    mybyte=UDR;
                }   
                if(mybyte[1]= = ‘A’)

                       LED=(1<<LED0);

                   if(mybyte[1]= =’F’)

                       LED=(1<<LED1);

                   if(mybyte[1]= = ‘3’)

                       LED=(1<<LED3);

                       _delay_ms(1000);

                  LED=0;
        }
     

     

    February 23, 2011 at 7:51 am #5595
    dagakshay
    Participant

    again you went wrong with ISR again….

     

     for(i=0;i<=13;i++)            

    {

    mybyte=UDR;

    }

     

     

    try to think more and tell me what thta loop will do……

     

     

     

    February 23, 2011 at 7:54 am #5596
    dagakshay
    Participant

    use the ISR i wrote before…

    instead of comparing mybyte[1] compair by mybyte[13]….. it will work out….

     

    do apply a bit of common sense… try to think out of box…..

     

    all the best 

    February 23, 2011 at 8:29 am #5599
    ajay
    Participant

     

    THANK YOU again sir

     

    i tried your isr directly it gives error for

     

     

            LED=(1<<LED0); this statement.

     

    ../LED.c:68: error: expected ‘)’ before ‘;’ token

     

    plese help.

     

    regards.

     

    February 23, 2011 at 1:11 pm #5602
    dagakshay
    Participant

    see the just above line… compairing 65 by mistake i wrote 65′ remore ‘ sign…. 

    March 23, 2011 at 6:59 am #5803
    sudhakar
    Participant

    can u give me the code for atmega16 interface with cc2500 2.4ghz transreceiver. The project is actually communicating the two atmega16 nodes.

    March 23, 2011 at 8:53 am #5805
    dagakshay
    Participant

    hello sudhakar,
    you could have made this post as a separate (new) topic….

    July 5, 2011 at 5:03 am #6422
    vamshi
    Participant

    hi frnds gud discussion going on

    frnds i got a program of rfid system on which iam doing mini project

    so frnds pls help in clearing my doubt…

    frnds

    > is the no. displayed on the tag v buy in rfid system is the only ID od that tag

    > i think i hav a confined code which give access to only saperate TAG the program is shown below

     

    #include<reg51.h>
    sbit RS=P3^7;
    sbit EN=P3^6;
    sbit R=P3^2;    // for relay
    sbit bz=P1^7;    // for piezo buzzer
    void Rxmsg(void);
    void lcdinit(void);
    void lcdData(unsigned char l);
    void lcdcmd(unsigned char k);
    void DelayMs(unsigned int count);
    void sucessRx(void);
    void unknown(void);
    void display(unsigned char s, t);
    void welcome(void);
    void main()
    {
    unsigned char i=0;
    unsigned int j=0;
    unsigned char c[15];
    TMOD=0x20;    // Configure the serial port to 9600 baud rate
    TH1=0xFD;
    SCON=0X50;
    TR1=1;
    R=0;
    lcdinit();
    welcome();
    bz=1;
    while(1)
    {
    back:
    for(i=0;i<15;i++)
    // command to recv data
    {
    c=0xFF;
    }
    while(RI==0);
    for(i=0;i<15;i++) //command to recv data
    {
    j=0;
    while(RI==0)
    {
    if(j>=1000)
    goto timeout;
    j++;
    }
    c
    =SBUF;
    RI=0;
    }
    timeout:
    for(i=0;i<15;i++)
    {
    if(c
    ==’1′ && c[i+1]==’E’ && c[i+2]==’0′ && c[i+3]==’0′ && c[i+4]==’7′ && c[i+5]==’C’ && c[i+6]==’A’ && c[i+7]==’0′ && c[i+8]==’3′ && c[i+9]==’C’)
    //RFID code
    {
    sucessRx();
    DelayMs(1000);
    R=1;
    bz=0;
    DelayMs(1000);
    R=0;
    bz=1;
    DelayMs(1000);
    lcdinit();
    DelayMs(100);
    welcome();
    goto back;
    }
    }
    unknown();
    DelayMs(2000);
    bz=0;
    DelayMs(2000);
    bz=1;
    DelayMs(1000);
    lcdinit();
    DelayMs(100);
    welcome();
    }
    }
    void sucessRx()
    {
    unsigned int i=0;
    unsigned char c[]=”ACCESS GRANTED “;
    lcdcmd(0x01);
    DelayMs(10);
    lcdcmd(0x80);
    DelayMs(10);
    while(c
    !=’’)
    {
    lcdData(c
    );
    i++;
    }
    }
    void unknown(void)
    {
    unsigned int i=0;
    unsigned char c[]=”ACCESS DENIED”;
    lcdcmd(0x80);
    DelayMs(10);
    while(c
    !=’’)
    {
    lcdData(c
    );
    i++;
    }
    }
    //



    // Lcd intialization subroutine
    //



    void lcdinit(void)
    {
    lcdcmd(0x38);
    DelayMs(250);
    lcdcmd(0x0E);
    DelayMs(250);
    lcdcmd(0x01);
    DelayMs(250);
    lcdcmd(0x06);
    DelayMs(250);
    lcdcmd(0x80);
    DelayMs(250);
    }
    //



    // Lcd data display
    //



    void lcdData(unsigned char l)
    {
    P2=1;
    RS=1;
    EN=1;
    DelayMs(1);
    EN=0;
    return;
    }
    //



    // lcd command
    //



    void lcdcmd(unsigned char k)
    {
    P2=k;
    RS=0;
    EN=1;
    DelayMs(1);
    EN=0;
    return;
    }
    //



    // Delay mS function
    //



    void DelayMs(unsigned int count)
    {  // mSec DelayMs 11.0592 Mhz
        unsigned int i;
    //  Keil v7.5a
    while(count){
    i=115;   // 115 exact value
    while(i>0)
    i–;
    count–;
    }
    }
    void welcome(void)
    {
    unsigned int i=0;
    unsigned char c[]=”WELCOME TO RFID”;
    unsigned char d[]=”SECURITY SYSTEM”;
    lcdcmd(0x01);
    DelayMs(10);
    lcdcmd(0x80);
    DelayMs(10);
    while(c!=’’)
    {
    lcdData(c
    );
    i++;
    }
    lcdcmd(0xc0);
    i=0;
    while(d
    !=’’)
    {
    lcdData(d
    );
    i++;
    }
    }

     

    >frnds please xplain me this working

    i think this code isconfined to tag no. “1E007CA03C”

    frnds help me to re design the prgrm so it can access my system

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Pic18f25q10 osccon1 settings swordfish basic July 18, 2025
  • Sump pit water alarm - Kicad 9 July 18, 2025
  • Anyone jumped from Easyeda std to Easyeda pro? July 17, 2025
  • turbo jet fan - feedback appreciated. July 17, 2025
  • More fun with ws2812 this time XC8 and CLC July 17, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise