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 / Bit Banging

Bit Banging

|

Microcontroller › 8051 › Bit Banging

  • This topic has 0 replies, 1 voice, and was last updated 12 years, 5 months ago by sanket joshi.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • July 16, 2013 at 9:06 am #2541
    sanket joshi
    Participant

    i want to interface rf-id module using any two pins of 8051(Bit Banging)…

    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=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
    !='')
    {
    dis_data(data0
    );
    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);
    }
    }
    }

    but i m getting no character on lcd…

    can you please figure out the mistake?

    kindly help me…its urgent…

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

RSS Recent Posts

  • Please confirm monostable does not need reset? December 15, 2025
  • Multiple photodiodes for single ADC read December 15, 2025
  • Bringing a Siemens W-48 and Ericsson Model 1951 back to life December 15, 2025
  • Hitachi SuperScan Elite 802 CRT Monitor Issues (Model CM802U) December 15, 2025
  • Sound not working on Laptop December 15, 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