Showing posts with label Microcontrollers. Show all posts
Showing posts with label Microcontrollers. Show all posts

Monday, August 11, 2014

The Walking man on a LCD using 8051 microcontroller. Trailer








This is a video on "The walking man on a LCD" which has been done using 8051 Microcontroller. We would like to know if anybody is interested in making this project. ? If yes, we will make a tutorial or two on  "How to make a walking man on 16*2 LCD using 8051 Microcontroller"? . 

Wednesday, July 23, 2014

How to print data on second line of 16*2 LCD using Microcontroller (8051)

Let us see how to print on the second line of 16*2 using  8051.

Prerequisite: Knowledge about lcdcmd() and lcddata() functions.

                                              Circuit diagram.



Here is the DDRAM address of 16*2 LCD



                                  For 16*2 LCD

                       ROW1 : 0x80 0x81 0x82 0x83 0x84 ...... 0x8F
                       ROW2 : 0XC0 0XC1 0XC2 0XC3 0xC4......0xCF

The Display data RAM is the set of addresses where the cursor moves. The data will be written on the position where cursor is. The cursor position(address) can be changed by sending various commands to LCD. For ex: lcdcmd(0x80+02) means Cursor points to 1st row, 3rd column.

Suppose the data is "welcome". On executing 0x82 command,the cursor points to the 1st row, 3rd column. If we start sending data to the LCD. 'w' will be printed on the third position. By default, the address will be incremented for new alphabet. Hence 'welcome' will occupy 03 to 09 address in the above figure.

To use second row, first column of the 16*2 LCD. We should point the cursor to that position. This can be done by using lcdcmd(0x80+0x40) .To use second row, second column(0x80+0x41) and so on. After pointing the cursor to that position. We can write the respective data using lcddata() function.

Using these basic commands, we can print the data on second line of 16*2 LCD.



Many animations can be done by playing with  the addresses of DDRAM. Here is a simple demonstration!

Here in the second row, we started printing values from (0x80+0x4D) address and decremented the initial address till the whole array is print. If anyone needs the code and simulation, please use the comment box :).

Saturday, July 19, 2014

Create a frequency using 8051 Microcontroller. Timer 0 Mode 1. Proteus simulation

8051 has two timers. Timers can be used to generate delay. So, we can create pulse of various frequencies using 8051. Let's see as how to create a frequency on particular pin of microcontroller, 8051. We will use proteus simulation to demonstrate the same.

                                                         Circuit diagram


Here is the code, which generates a frequency of 10Hz on pin  P2.7.

Code :
#include "reg52.h"
#define Baud_rate 0xFD  // BAUD RATE 9600                     
void delay(void);
sbit App = P2^7;


void main()
{ 
while(1)
 {
 App=~App; //To generate a pulse(ON/OFF)
 delay();
 }
}

void delay(void)
{
  TMOD=0x01;      //Timer 0 mode 1
  TL0=0xFD; 
  TR0=0x4B;
  TR1=1;         //start timer
  while(TF1==0); //Timer flag
  TR1=0;         //reset timer
  TF1=0;
}


The Microcontroller used here has a crystal frequency of 11.0592MHz. 
In order to generate a Frequency of  10Hz, we need to use timer registers.
The steps to load values into TH and TL registers which generate delay are as follows
1) Divide the desired time delay by 1.085us. Here delay is 1/10=100ms. So, 100ms/2=50ms/1.085us=46083
2) Perform 65536-delay=65536-46083=19453
3)Convert the value obtained in the above step to Hex.  19453 is in decimal, in Hex, the value is 4BFD.
4)Load TH=4B
5)Load TL=FD
when you start the timer, the timer registers will count till FFFF generating the desired delay. Thus generating a pulse of required frequency/delay.

Friday, July 18, 2014

Send data from 8051 to Hyperterminal (PC/Computer)

My first post here was http://www.hobbyprojects.in/2013/03/serial-communication-between-pc-and-8051.html which went  viral. I had also made a video on sending data from 8051 to Hyperterminal(which will be present in PC). The video  was missing in the website. We will see in detail , the serial communication between Microcontroller and Hyperterminal.

How to send data from Microcontroler to Hyperterminal ?

Detailed Circuit diagram
The circuit consists of Microcontroller, Max232, COMPIM, inverters and virtual terminal as shown in the figure. We have used Free virtual serial ports emulator so that we can connect two or three communication ports together.

 Make the port of COMPIM as COM4. The data sent from Microcontroller will flow via COM4.

 Since, the Hyperterminal doesn't have many ports inbuilt, we will use virtual ports emulator to get the ports. Here we have connected COM2 and COM4 in pair. The data sent from COM4 will also flow through COM2 as they are connected.
 

Hyperterminal will be in the following in the computer. Start->All programs--> Accessories-->Communications-->Hyperterminal
 Here the port via which the hyperterminal makes communication with microcontroller is COM2.
Set the properties. Baud Rate should be as defined in 8051

Click on Echo typed characters locally
The data sent from Microcontroller will be displayed on Hyperterminal. Start the simulation, you can see the output in virtual terminal as shown below.


 The actual data, "Hello" which is transferred from Microcontroller (8051) to PC/Computer will be displayed in the hyperterminal. Thus, the data is successfully transmitted from 8051 to Hyperterminal.



 I have made a video too. Please watch here. The code is simple, if anyone needs the code. Please use the comment box. Thanks.



Thursday, July 25, 2013

8051 code for Calculator(Keil)

#include<reg51.h>
void delay(void)
void main(void)
{
unsigned char i,j,value,flag,a[2];
unsigned char r0[4]={0xEE,0xDE,0xBE,0x7E};
unsigned char r1[4]={0xED,0xDD,0xBD,0x7D};
unsigned char r2[4]={0xEB,0xDB,0xBB,0x7B};
unsigned char r3[4]={0xE7,0xD7,0xB7,0x77};
j=0;
a[0]=0;
a[1]=0;
while(1)
{
P0=0xFE;
delay();
value=P0;
for(i=0;i<4;i++)
{
if(value==r0[i])
{
flag=i+1;
delay();
}
}
P0=0xFD;
delay();
value=P0;
for(i=0;i<4;i++)
{
if(value==r1[i])
{
P2=i;
a[j]=P2;
j=j+1;
delay();
}
}
P0=0xFB;
value=P0;
for(i=0;i<4;i++)
{
if(value==r2[i])
{
P2=i+4;
a[j]=P2;
j=j+1;
delay();
}
}
P0=0xF7;
value=P0;
for(i=0;i<12;i++)
{
if(value==r3[i])
{
P2=i+8;
a[j]=P2;
j=j+1;
delay();
}
}
if (flag==1)
P2=a[0]+a[1];
else if(flag==2)
P2=a[0]-a[1];
else if(flag==3)
P2=a[0]*a[1];
else if(flag==4)
P2=a[0]/a[1];
else
P2=P2;
}
}
void delay(void)
{
unsigned int i;
for(i=0;i<20000;i++);
}

Saturday, March 23, 2013

Serial communication between PC and 8051

Serial communication is widely used when the control system has to be actuated from the computer(PC).I will show you as how to send data from PC to 8051. In return, 8051 will acknowledge the data which we sent. So basic component  required in serial communication is MAX232 IC. It is used to convert Rs232 voltage levels to TTL and vice versa. Read more here. Max232.

I have used Matlab to send data serially from PC, and used 8051 to receive the serial data and display appropriately. Simulation is done in Proteus.
Serial communication between PC and 8051


We have used Virtual serial port emulator. Connect two ports in pair. I have connected COM2 and COM3.  Edit  COMPIM as COM3. Next, write a serial code which travels through COM2 in  MATLAB.Since both com ports are in pair, if you write in COM2 data will get through COM2 and through rest of circuitry.



I have used compim. So that matlab and proteus are connected.I have used 2 inverters in the main circuit before max232 because, MAX232 inverts the data.These inverters are very important.Otherwise you'll not be able to send the serial data and serial communication fails.
Here is the Simple Matlab code for serial communication, shown below
fprintf(s,'2') will send 2 to the 8051..  In the code I have written such that, if i send '2' from PC to 8051 serially. 8051 will receive the serial data and checks if it received correctly and acknowledges by displaying "got2" in the virtual terminal.
Serial communication Proteus simulation


Set the circuit as shown in the figure. And if anyone needs project code and simulation. Let me know!

Tuesday, February 26, 2013

Serial communication through virtual ports and Matlab

Steps to follow
1) Go to proteus ISIS Professional
2) Pick devices->Miscellaneous->select COMPIN device
3)Go to virtual instruments mode and select virtual terminal


Here is the proteus image with connections

4).  We need Virtual Serial port emulator. go to google and download it .It is free



So COM2 and COM4 are connected virtually.
We need to write a program in MATLAB to check how the data is being transmitted.
Edit properties in COMPIN and set the port to COMP 4 and set the baud rates to 9600.
Set the Baud rate of Virtual terminal to 9600.

The Output is as shown below.


Thank you very much!