Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Bit banging for RF-ID reader

Status
Not open for further replies.

sanket.joshi

Member level 3
Member level 3
Joined
Jun 27, 2013
Messages
65
Helped
8
Reputation
16
Reaction score
8
Trophy points
8
Location
Mumbai,India
Visit site
Activity points
386
i want to interface RF-ID module using any two pins of 8051...
i have written following code...
Code:
include<reg51f.h>
#include<string.h>

#define _XTAL_FREQ   11059200    
#define Baudrate     9600
#define OneBitDelay  (100000000/Baudrate)

#define port P0            
#define lcdport P1  //14,13,12,11 pins of lcd and 1.7,1.6,1.5,1.4 of controller

sbit rs=port^0;        //Register select 
sbit rw=port^1;        //Read/Write 
sbit en=port^2;        //Enable pin

sbit  UART_RX=P2^0;
sbit  UART_TX=P2^1;

unsigned char d[12]=0,i,l;
unsigned char card_id[12];

void delay(unsigned int count)    //Function to provide delay
{
    int i,j;
     for(i=0;i<count;i++)
     for(j=0;j<1100;j++);
}

void lcdcmd(char cmdout)
{
lcdport=cmdout;
rs=0;
rw=0;
en=1;
delay(10);
en=0;
}
 
void lcddata(char dataout)
{
	lcdport=dataout;
rs=1;
rw=0;
en=1;
delay(10);
en=0;
}

void dis_cmd(char cmd_value)
{
	char cmd_value1;
	
		cmd_value1 = cmd_value & 0xF0;		//mask lower nibble because PA4-PA7 pins are used. 
	lcdcmd(cmd_value1);			// send to LCD
 
	cmd_value1 = ((cmd_value<<4) & 0xF0);	//shift 4-bit and mask
	lcdcmd(cmd_value1);			// send to LCD
}						
 
 
void dis_data(char data_value)
{
	char data_value1;
	
	data_value1=data_value&0xF0;
	lcddata(data_value1);
 
	data_value1=((data_value<<4)&0xF0);
	lcddata(data_value1);
}
void __delay_us(unsigned int d)
{
   unsigned int i, limit;
   limit = d/15;

   for(i=0;i<limit;i++);
}


void lcd_init()	// fuction for intialize 
{
	dis_cmd(0x02);		// to initialize LCD in 4-bit mode.
	dis_cmd(0x28);		//to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
	dis_cmd(0x80);
}

void initialize_serialcommunication(void)
{
SCON  = 0x50;
TMOD  = 0x20;
TH1   = 0xFD;
TL1   = 0xFD;
TR1   = 1;
TI    = 1;		          
}

void init(void)
{
UART_RX = 1;  //set as i/p
UART_TX = 0;  //set as o/p
}

unsigned char receive(void)
{
unsigned char DataValue = 0,i;

	//wait for start bit
	while(UART_RX==1);

	__delay_us(OneBitDelay);
	__delay_us(OneBitDelay/2);   // Take sample value in the mid of bit duration

	for (  i = 0; i < 8; i++ )
	{
		if ( UART_RX == 1 )   //if received bit is high
		{
			DataValue += (1<<i);
		}

		__delay_us(OneBitDelay);
	}

	// Check for stop bit
	if ( UART_RX == 1 )       //Stop bit should be high
	{
		__delay_us(OneBitDelay/2);

		return DataValue;
	}
	else                      //some error occurred !
	{
		__delay_us(OneBitDelay/2);
		return 0x000;
	}
}

void rfid_data(void)
{
for(i=0;i<12;i++)
{
card_id[i]=receive();

}
}

void main(void)
{
//unsigned char ch;
unsigned char data0[]="CARD ID:";
lcdport=0;
init();
//initialize_serialcommunication();
lcd_init();
dis_cmd(0x81);        //Place cursor to second position of first line 
    while(data0[i]!='\0')
   {
dis_data(data0[i]);
delay(20);
i++;
}
while(1)
{
rfid_data();
dis_cmd(0xC1);        //Place cursor to second position of second line
         for(l=0;l<12;l++)
         { 
              dis_data(card_id[l]);
			  delay(20);
          }
}
}

since RF-ID only transmit data i have written code for receiving...
but i m getting nothing on the LCD except statement(CARD ID:)..
what is the mistake in this program?
kindly help me...
its urgent friends...please help me
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top