Shopping Cart

0 item(s) - Rs.0.00
Your shopping cart is empty!
Please update your Flash Player to view content.

. . . FOLLOW  US







 
 
BIT BANGING
Tutorial - 8051 Tutorial
Written by Amol Shah   

Serial Communication is one of the most widely used methods of communications is microcontrollers. It provides a low cost solution for interfacing with the PC. Most of the micro controllers have one UART port, some have two UART ports but some lower end microcontrollers do not have a single UART port. Serial communication is also used for interfacing modules like GSM modems, GPS modules, RFID reader etc so what if you are using 8051 based controller and has just one UART port and want to serially interface more than one device to the same controller?

You can use a method called as “BIT BANGING”. Bit Banging basically uses Software for communication instead of a dedicated hardware. In this method Transmitting is done by alternating the Transmit Pin after specific interval, this time interval depends on the Baud rate for serial communication. In same way Receive function is performed by sampling the pin at regular interval. This is quite a tedious process and puts too much load the Micro controller processing.

Over here I will be explaining how to send and receive a byte using this method. This polling interval is decided by the communication Baud rate e.g. if the baud rate is 9600 bps then the polling interval will be 1/9600 seconds i.e.104µS.

Serial Communication
Figure 1
Figure 1 shows the basic Frame for serial communication. You can see the basic frame consists of Start Bit which is followed by the Data and end of transmission is indicated by a Stop Bit.

ALGORITHM for Sending Byte:-

  1. Start.
  2. Make Tx pin Low (Stop Bit).
  3. Wait for duration corresponding to baud rate.
  4. Send data bit.
  5. Wait for duration corresponding to baud rate.
  6. Go to 4 till all eight data bits haven’t been sent.
  7. Send Stop Bit
  8. Wait for duration corresponding to baud rate.
  9. Make Tx pin High
  10. Stop
Receiving a byte is more difficult than sending it. Since it is not possible to continuously poll the Rx pin we will be using external interrupt function for detecting the START bit of serial communication. Once this START bit has been detected we poll the Rx pin at regular interval.
We will be using P3.2 (INT0) as the Rx pin so that we can use the External Interrupt 0 to detect the Start Bit. Normally the Rx pin is high so when the pin becomes low i.e. Start Bit is received an interrupt is generated. The controller then deactivates the External Interrupts and starts polling the Rx pin at regular interval after getting next eight bits we confirm the receiving of the Stop bit and the External Interrupt 0 is activated again for receiving the next byte.

ALGORITHM for Receiving Byte:-

  1. Start.
  2. Turn ON External Interrupt 0.
  3. Wait for External Interrupt 0.
  4. Confirm Rx Pin is Low (Start Bit).
  5. Wait for duration corresponding to baud rate.
  6. Get Rx pins status.
  7. Go to 5 till eight bits haven’t been read.
  8. Wait for duration corresponding to baud rate.
  9. Check for stop bit.
  10. Stop
 
 

Featured

 
 
 
.
 TUTORIALS
.
  8051 Tutorial
 
  Power Supply
 
CODE LIBRARY
.

  8051 Assembly
 
  C Code Library
 

.
 PROJECTS
.
  Project List
 
  Synopsis and Abstract
 
DOWNLOADS
.

  Datasheets
 
  Download
 

.
 POPULAR
.
  About Us
 
  DNA Shop
 
  Totorial
 
  Code Library
 
  Download
 

.
CONTACT US
.

Mr. Amol Shah

DNA Technology Nashik,

Maharashtra 422009 India

Phone : 0253-3023939

Mobile : 09225145135

Email : contact@dnatechindia.com