This is unique, decent very useful and interesting application. It can generate desire bit pattern of 8-bit of 1 and 0. Bit pattern is entered as sequence of 1’s and 0’s. Bit time is also selected between 100 us to 1 ms. This bit pattern is generated as series of high and low pulses as per bit pattern – means high pulse is generated for 1 and low pulse is generated for 0. It can be better understood with the help of following figure.
Fig. 1: Image representing typical bit pattern
As shown in figure the bit pattern is 10110101. So for every 1 in the sequence a high pulse for the bit period (time) is generated and for 0 the output remains low for bit time. With every bit pattern, a start bit (10) and stop bit (1010) are also added at the starting and at the end of 8-bit pattern.
The circuit uses 8 bit micro controller AT89C51 to generate this programmable bit pattern. The desired bit pattern is entered using buttons and bit time is also selected. Bit pattern, bit time etc are displayed on LCD. This circuit can be used in
· Testing of serial 8 bit data receiver
· 8 bit parallel to serial data converter
· Parallel to serial data transmitter
Its major features are
· Highly programmable and customizable due to micro controller used
· Can be easily extended to generate 16 bit or 32 bit pattern without single hardware modification
· LCD panel to display various messages, bit time, bit pattern etc
· Programmable start bit and stop bit can be set according to requirement
· LED indications
· Configurable bit time from 100 us to 1 ms (in steps of 100 us)
So let us understand circuit diagram, operation and software program one by one.
Circuit description:
As shown in figure the circuit is built using micro controller AT89C51, LCD and few other components like push buttons, resistors, capacitors crystal etc.
· Five push buttons are connected to port P1 pins P1.0 to P1.4 that connects pins to ground when pressed. They will give logic 0 input to respective pin when pressed
· Port P0 drives data pins D0 – D7 of LCD. Two control pins Rs and En of LCD are connected to P2.7 and P2.6 respectively. Third control pin RW is connected to ground that makes LCD write always enable. Pot R3 is connected to VEE pin as shown to vary the brightness of LCD
· Port 2 pins P2.0 – P2.2 drives 3 LEDs in current sinking mode.
· Bit pattern output is generated from P2.3 pin. It can be connected to CRO or DSO to observe generated pattern
· A 12MHz crystal with two 33 pF capacitors is connected to crystal input pins as shown. It provides required clock to micro controller for its working and all internal operation
· The circuit works on 5 V supply that is given from external power supply source
Working and operation:
Five push buttons are connected to port P1 pins for following different functions
Fig. 2: Table showing functions of different switches used in generating bit pattern
· The user can select desire bit time by pressing inc or dec button. User can select 100 us to 1 ms time in step of 100 (means 100, 200, 300, …..)
· After selecting the bit time, user has to press ent button.
· Next it ask to enter desire 8 bit pattern
· User has to press button 1 and button 2 to enter 1 and 0 to enter complete pattern. A red LED blinks when 1 is entered and green LED blinks when 0 is entered
· When complete 8 bit pattern is entered blue LED lits ON
· Now as enter is pressed, the bit pattern is generated on P2.3 pin that can be observed on CRO / DSO and also the message on LCD is displayed as “pattern generated Press Reset ”
Software program:
The software program embedded in to internal memory (FLASH) of micro controller takes care of all the following tasks
· Takes user inputs through buttons
· Handles LCD and displays messages and values
· Calculates the count to be loaded into timers to generate desire bit time
· Generates bit pattern with start bit and stop bit
The program is written in embedded C language and compiled using KEIL software. When it is compiled the hex file is generated. This hex file is loaded in to internal FLASH of AT89C51 using EEPROM programmer that is HW and SW tools.
Project Source Code
###
#include<reg51.h> // header file
#include <string.h>
#define lcd_data_bus P0 // port for LCD data pins
sbit rs = P2^7; // set port pins
sbit en = P2^6;
sbit led = P2^0;
sbit led1 = P2^1;
sbit led2 = P2^2;
sbit op = P2^3;
unsigned int byte[8],time=1,p=0,q=0;
void lcddly() // delay for LCD busy
{
int x;
for(x=0;x<1500;x++);
}
void lcd_send_cmd(unsigned char a) // send command to LCD
{
lcddly();
rs = 0;
lcd_data_bus = a;
en = 1;
en = 0;
}
void lcd_send_data(unsigned char b) // send data to LCD
{
lcddly();
rs = 1;
lcd_data_bus = b;
en = 1;
en = 0;
}
void lcd_print(unsigned char *s) // print message on LCD
{
unsigned char l,i;
l = strlen(s);
for(i=1;i<=l;i++)
{
lcd_send_data(*s);
s++;
}
}
void dly() // key debounce delay
{
int a,b;
for(b=0;b<20;b++)
for(a=0;a<2000;a++);
}
void timedly(int t) // bit time delay
{
int a;
TR0=1;
for(a=0;a<t;a++)
{
while(TF0==0);
TF0=0;
}
TR0=0;
}
void delay() // start bit and stop bit delay
{
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
void generate_bit_pattern() // generate bit pattern
{
int x=0;
op=1; // start bit 10
delay();
op=0;
delay();
for(x=0;x<8;x++) // generate 8 bit pattern
{
if(byte[x]==1) op=1; // if bit is 1 then output pin is 1
else op=0; // else output pin is 0
timedly(time); // delay for bit time
}
op=1; // stop bit 1010
delay();
op=0;
delay();
op=1;
delay();
op=0;
led=1;
lcd_send_cmd(0x01); // display message
lcd_print("pattrn generated");
lcd_send_cmd(0xC0);
lcd_print("press Reset");
}
void inc_time_delay() // increase bit time
{
char w;
if(time<10) time++; // increment time by 1 till its 1 ms
w=0x30+time;
lcd_send_cmd(0xC0);
if(time==10) lcd_print("1 mili sec "); // display it
else
{
lcd_send_data(w);
lcd_print("00 micro sec");
}
}
void dec_time_delay() // decrease bit time
{
char z;
if(time>=2) time--; // decrement it by 1 till its 100 us
z=0x30+time;
lcd_send_cmd(0xC0);
lcd_send_data(z);
lcd_print("00 micro sec");
}
void initialize() // initialize timer and ports
{
P0 = 0x00;
P2 = 0x00;
P2 = 0x0F;
P1 = 0xFF;
TMOD=0x22;
TH0=155;
TL0=155;
TH1=205;
TL1=205;
}
void main()
{
int i=0,j=0,f=0,f2=0;
initialize(); // initialize ports and timer
lcd_send_cmd(0x3C); // initialize LCD
lcd_send_cmd(0x0E);
lcd_send_cmd(0x01);
lcd_print("set bit time"); // display message
lcd_send_cmd(0xC0);
lcd_print("100 micro sec");
back: if(f==1) // if time is set
{
lcd_send_cmd(0x01);
lcd_print("Enter bit pattrn"); // display message to enter
lcd_send_cmd(0xC0); // bit pattern
lcd_print("(8-bit):");
f=0;
f2=1;
}
P1=0xFF;
while(P1==0xFF); // wait for button press
switch(P1)
{
case 0xFE: // for button 1
led1=0;
dly();
if(i<8 && f2==1)
{
byte[i]=1; // enter 1 and
lcd_send_data(0x31); // display 1 on LCD
i++;
}
led1=1;
break;
case 0xFD: // for button 2
led2=0;
dly();
if(i<8 && f2==1)
{
byte[i]=0; // enter 0 and
lcd_send_data(0x30); // display 0 on LCD
i++;
}
led2=1;
break;
case 0xFB: // for button 3
inc_time_delay(); // increase bit time
dly();
break;
case 0xF7: // for button 4
dec_time_delay(); // decrease bit time
dly();
break;
case 0xEF: // for button 5
dly();
j++;
if((j%2)==1) f=1; // first time do nothing
else generate_bit_pattern(); // second time generate bit pattern
}
if(i==8) led=0;
goto back;
}
###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.