8051 MICROCONTROLLER TUTORIALS
 

8051 AND HYPERTERMINAL

Debugging 8051 Code with Serial Terminal
Debugging of 8051 application can be very easy if we able to send debug information to serial port of PC. And its output can be seen on HyperTerminal (in Windows ) or Minicom ( in Linux ). We can display content of any variable, memory location etc. We can also print other useful information on serial terminal which could replicate the flow of the code.

Such messages can be displayed like “Entering into function A”, “Existing from function B” , “Data is send” etc. So this is very cost effective solution because we do not need any In Circuit Emulator or any other debugging device.  In this tutorial circuit and working code is shown.

Circuit description


Circuit is quite simple in any project we can add this facility to do serial communication with computer.

For that UART section of 8051 microcontroller is used. Rx and Tx line of microcontroller are connected to the computer’s serial port via MAX232. MAX232 is used to reverse the logic. Because RS232 works on negative logic and 8051 work on positive logic.

8051 is programmed in such a way that serial communication will take place at the speed of 9600 bps.

The circuit diagram is given below…



List of Components

1.8051 microcontroller (any variant)-one
2.MAX232 - one
3.LEDs -Two
4.Resistor 330 Ohm - two
5.Electrolytic disc capacitor 1uF/20V - four
6.Electrolytic disc capacitor 10uF/20V - four
7.Ceramic capacitor - 33 pf- two
8.DB9 9  Pin connector

For making of cable between 8051 circuit and PC serial port always use shielded cable.
Program

Program is divided into modules.

Serial port function is used to initialize the UART of 8051 microcontroller.

Speed of serial communication is et to 9600 bps.



SerialPrint (long int arg)
{
unsigned char NumArray[10];
// Convert number into string
sprintf (NumArray, "%d", arg);
// Send string to HyperTerminal
StringToTerminal (NumArray);
} // End of SerialPrint

void SerialInit()
{
EA=0;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
RI=0;
TI=0;
ES=1;
TMOD = 0x26;
EA = 1;
}// End of SerialInit

Void StringToTerminal (unsigned char *temp)
{
while (*temp)
{
SBUF = *temp;
DelayMs (10);
temp++ ;
}
SBUF = LF;
   DelayMs(10);
SBUF = CR;
   DelayMs(10);
} // End of StringToTerminal

After that StringToTerminal() is used the string to the serial port of computer. SerialPrint() is used to send any integer variable to the serial port. These two function can be used in any project.

StringToTerminal() = to send any string to PC.

SerialPrint() = to send content of any variable to PC.

StringToTerminal function is most important. Here we are sending characters one by one. instead of checking flags we are giving 10 msec delay. our assumption is that within this time communication will take place.

Sending complete string, Line feed and carriage return characters are also send so that curser at hyper terminal will come to next line.

This is Keil Project and can be open directly in Keil IDE. If you do not have KEIL IDE, then you can download it from following link at free of cost.

http://www.keil.com/c51/

At this page click on the Evaluation Software Link. This software is free of cost for evaluation purpose only.

Setup of HyperTerminal

Go To:

1. Start Menu>> Programs >> Accessories >> Communications >> Hyper Terminal
After that HyperTerminal window will open. If it prompt for checking of default program as shown in fig, then say yes to it.



2. Click Yes

3. Type Connection Name as 8051 (or as per your Choice)




4. Select COM PORT (1, 2, 3 etc) which ever is available.     (NOTE: Very Less USB- TO Serial Converters as Reliable)
So use Standard Serial  Port



5. Do Port Setting as Given Below.




Then Click Apply and OK.


6. Now you See Bottom Left side It shows “Connected”.



7.  Now burn the Hex File (Given) and Switch on the Circuit after Connecting Specified  Serial Port .You will see output as Follows:



If every thing works fine you will see Hello World on the screen. Otherwise check your setup.
EmbeddedCraft : Last Modified: 1-Dec-2018   |   Feedback: For any feedback please write to us at embeddedcraft_at_gmail_dot_com