RFID CR038 and SK40C

RFID reader, Reader/Writer, Tag.....

RFID CR038 and SK40C

Postby konz90 » Tue Nov 19, 2013 11:06 am

hello, i want to know can this CR038 in the programming c have the separate function for reading the card and function for not reading the card.

because my project is, if there is a card - no buzzer alarm will be present, if there is no card detected - the buzzer will be alarm about 30 second and it will start looping again


anybody can help for this programming?

this is my programming :
CODE: SELECT_ALL_CODE
int main(void)
{
   unsigned char value = 0;   // declare a variable to store
   // ensure all the hardware port in zero initially
   PORTA = 0;
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;
   PORTE = 0;

   // Initialize the I/O port direction, this must be configured according to circuit
   // please refer to PTK40A schematic for details
   // TRISX control pin direction, output pin must be configure as '0'
   // while input must be configure as '1'
   TRISA = 0b00010000;
   TRISB = 0b00001111;
   TRISC = 0b10000000;
   TRISD = 0;
   TRISE = 0;
   
   mode=0;

   //initialize UART for using it
   uart_initialize();
      
   //Initialize LCD to be use
   lcd_initialize();
    lcd_putstr("PWD Parking System");  //LCD display
   lcd_goto(0xc4);
   delay_ms(1500);
   lcd_putstr("Begin");
   delay_ms(1500);
   lcd_clear();

   while(1)   // create an infinite loop
   {
      if(m_sensor==1)
      {
         lcd_putstr("3:Starting    ");
         led_oren=1;

         if(ir_sensor==0)   //waktu nak scan card
         {   
            while(m_sensor==1)
            {
               lcd_clear();
               lcd_putstr(" Scan the Card  ");
               delay_ms(1500);
               lcd_clear();
               lcd_putstr("ERROR Try again ");
               Get_NUID();
               lcd_clear();
               lcd_putstr("   NUID Card    ");
               lcd_2ndline();
               LCD_HextoASCII(reply[12]);
               LCD_HextoASCII(reply[11]);
               LCD_HextoASCII(reply[10]);
               LCD_HextoASCII(reply[9]);
               led_oren=0;
               led_green=1;
               while(m_sensor==1);
            }
         }
      
         n++;
         if(n>5)   
         {
            while(m_sensor==1)
            {
               led_oren=0;
               led_red=1;
               __delay_ms(500);
               led_oren=0;
               __delay_ms(500);
               n=0;
               led_green=0;
               bz=1;
            }
         }
         __delay_ms(1000);
      }

      else
      {
         lcd_clear();
         n=0;
         led_red=0;
         led_green=0;
         led_oren=0;
         bz=0;
      }
   }
}
konz90
Freshie
 
Posts: 5
Joined: Tue Nov 19, 2013 11:00 am

Re: RFID CR038 and SK40C

Postby yonghui » Wed Nov 20, 2013 3:32 pm

Not sure what you want to do with the code.u can program it as what u like. The code u shown not working?
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: RFID CR038 and SK40C

Postby konz90 » Wed Nov 20, 2013 3:40 pm

yep .. it seem it not working only at the part when there are no mifare card detect.. if it been detect it will go well
konz90
Freshie
 
Posts: 5
Joined: Tue Nov 19, 2013 11:00 am

Re: RFID CR038 and SK40C

Postby konz90 » Wed Nov 20, 2013 3:42 pm

this is my project :

Im making a project based on RFID CR038 and PIC SK40C, using PIC16F877A..
this project is to detect the card when people entering into the parking slot.. and if the card detect it will turn green light on, if the card is not detect it will turn red led on and the buzzer will alarm. i want to ask sir about how can i make the programming that can automatically function that when user enter the parking slot it will auto find the card and if the user leave the slot it will restart automatically
right now im only have the problem at when the card is not been detect it will turn to red led on and buzzer sounded but when people leave the slot it still cannot stop or restart back the program..


thank you for helping..
konz90
Freshie
 
Posts: 5
Joined: Tue Nov 19, 2013 11:00 am

Re: RFID CR038 and SK40C

Postby yonghui » Thu Nov 21, 2013 11:37 am

I think u will need at least show us ur schematic and flowchart . now I still confuse how many input and output u have.seems like got it sensor also?
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: RFID CR038 and SK40C

Postby konz90 » Thu Nov 21, 2013 1:06 pm

yes got the sensor also.. there are picture sir can see it..
Attachments
smua.jpg
konz90
Freshie
 
Posts: 5
Joined: Tue Nov 19, 2013 11:00 am

Re: RFID CR038 and SK40C

Postby robosang » Thu Nov 21, 2013 5:57 pm

So you are saying when there is RFID card, the reader is working, but not working when there is no RFID card, right?

If so, it must be your program, you write code to process when there is card, but when there is no card, the reader send back something different, UART will still take it. So did your program check it?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: RFID CR038 and SK40C

Postby konz90 » Thu Nov 21, 2013 7:38 pm

i dont really understand about how to separate the funtion , because in the program in the CR038 is like this
CODE: SELECT_ALL_CODE
void ON_ANTENNA(void)
{
   for(a=0;a<10;a++)
   {
   uart_transmit(ANTENNA_ON[a]);//TX DATA FROM PIC
   }
   for(a=0;a<10;a++)      
   {   
   reply[a]=uc_uart_receive();//RECEIVE DATA FROM CR038
   }
}


CODE: SELECT_ALL_CODE
void card_type(void)
{
   for(a=0;a<10;a++)
   {
   uart_transmit(Card_Type[a]);
   }
   for(a=0;a<12;a++)      
   {   
   reply[a]=uc_uart_receive();
   }
}


CODE: SELECT_ALL_CODE
void Anti_Col(void)
{
   for(a=0;a<10;a++)
   {
   uart_transmit(Anti_Collision[a]);
   }
   for(a=0;a<14;a++)      
   {   
   reply[a]=uc_uart_receive();
   }
   for(a=0;a<4;a++)      
   {   
   NUID[a]=reply[a+9];
   }
}


CODE: SELECT_ALL_CODE
void Get_NUID(void)
{
   //if(SW1==1)goto Start;
   ON_ANTENNA();
   //if(SW1==1)goto Start;
   card_type();
   //if(SW1==1)goto Start;
   Anti_Col();
   //if(SW1==1)goto Start;
}


CODE: SELECT_ALL_CODE
void uart_initialize(void)
{
   unsigned char dummy = 0;
   BRGH = 1;                           // Select high speed baud rate.
   SPBRG = (_XTAL_FREQ / 16 / UART_BAUD) - 1;   // Configure the baud rate.
   SPEN = 1;                           // Enable serial port.
   CREN = 1;                           // Enable reception.
   TXEN = 1;                           // Enable transmission.
   dummy = RCREG;      // dummy read, to clear the receive buffer
   dummy = RCREG;
}


CODE: SELECT_ALL_CODE
void uart_transmit(unsigned char uc_data)
{
   // Wait until the transmit buffer is ready for new data.
   while (TXIF == 0);
   
   // Transmit the data.
   TXREG = uc_data;
}


CODE: SELECT_ALL_CODE
unsigned char uc_uart_receive(void)
{
   // If there is overrun error...
   if (OERR == 1) {
      // Clear the flag by disable and enable back the reception.
      CREN = 0;
      CREN = 1;
   }   
   
   // Wait until there is data available in the receive buffer.
   while (RCIF == 0); ------------- this is been try to change into IF condition
   
   // Return the received data.
   return RCREG;
}


so here i dont know how to separate the function
if the card is been detect it call the function get_nuid()
if not detect it will Wait until there is data available in the receive buffer.. so the program will hank or frost or stuck at there because it waiting the data available.

im also try

if (RCIF == 0); ------------- this is been try to change into IF condition

// Return the received data.
return RCREG;

else
{ ...}
}

but the result is still same...
konz90
Freshie
 
Posts: 5
Joined: Tue Nov 19, 2013 11:00 am


Return to RFID

Who is online

Users browsing this forum: No registered users and 5 guests

cron