Home
Microcontrollers
Abbreviations
Useful Tools
Hot Links
Gallery
Feedback

Abbreviations

A B C D
E F G H
I J K L
M N O P
Q R S T
U V W X
  Y Z  

Microcontrollers
Interfacing LED's
Interfacing 7 segment
Multiplexing 7 segments
PWM Basics
Interfacing Relays
Interfacing 4x4 keypad
8051 Serial port

       The only one communication hardware present in atmel 89S52 version of 8051 microcontroller is the serial port. The serial port or UART transfers data bit by bit. In mode 1, 8 bits can be sent with one start and stop bit in a frame.

Communicating with the PC:

We can communicate with PC by using the serial port available in 8051. In order to communicate with the PC, we need a level converter because the serial port of the pc uses RS232 voltage levels which is much higher voltage than the TTL logic used by the microcontroller (+12v for logic 0 and -12v for logic 1). A dedicated IC from MAXIM i.e. Max232 is readily available in the market. It converts the TTL signals from the microcontroller to RS232 level and the other way round. Max232 contains 2 channels, works with single 5V supply and uses the principle of charge pump to convert the voltage levels.

The schematic :

 

Configuring HyperTerminal:

HyperTerminal is the tool usually used to test and communicate with the PC's serial port. To set up HyperTerminal follow the steps given below.

1. Open HyperTerminal.

Start > All programs > Accessories > Communications > Hyper Terminal

2.Specify a name for the connection

Click OK

3.Configure the connection parameters

Select the port of your PC i.e.COM1, COM2 etc., click OK

Set baud rate as required, and change Flow control to none

The connected in the bottom shows the status of the connection.

    Now your HyperTerminal is ready to communicate. You can disconnect or connect the connection by clicking on the icons shown in the image.

HyperTerminal displays only the character or data received, not the one you typed to send.

Testing the Level converter:

   You are ready with level converter hardware and HyperTerminal, now its time for testing your level converter hardware. For testing purpose, just interconnect the Tx and Rx pins of the level converter, and type something in the HyperTerminal, you will see the echo.

Programming the 8051:

    8051 USART uses dedicated buffer register SBUF, the mode and other settings of the serial port such as number of stop bits etc. is determined by the contents of SCON register. Timer 1 should be initialized to 8-bit auto reload, and its content determines the Baud rate of the 8051 serial port. Read datasheet to know more about different modes of UART.

Connecting the Microcontroller:

    Connect the Tx and Rx pins of the 8051 (pin no. 10 and 11 i.e. P3.0 and P3.1 in 89S52)microcontroller to the level converter. Provide power for the 8051 microcontroller target board.

 

;*************************************************
;
;Program: UART_test
;Author: Srikanth
;Website: http://shree-electronics.com/
;Description: Prints string on the hyperterminal window
;
;*************************************************

org 0000h
  ljmp main

main:
  mov tmod,#20h      ;Timer 1 configured to 8 bit
                     ;auto reload
  mov th1,#-6        ;Baud rate set to 9600
  mov scon,#50h      ;UART configure as 8 data bits
  setb tr1           ;with 1 start and stop bit
up:
  mov sbuf,#'s'      ;Store the char to be
                     ;transmitted in SBUF refister
  acall transmit     ;call transmit subroutine
  mov sbuf,#'h'
  acall transmit
  mov sbuf,#'r'
  acall transmit
  mov sbuf,#'e'
  acall transmit
  mov sbuf,#'e'
  acall transmit
  mov sbuf,#'-'
  acall transmit
  mov sbuf,#'e'
  acall transmit
  mov sbuf,#'l'
  acall transmit
  mov sbuf,#'e'
  acall transmit
  mov sbuf,#'c'
  acall transmit
  mov sbuf,#'t'
  acall transmit
  mov sbuf,#'r'
  acall transmit
  mov sbuf,#'o'
  acall transmit
  mov sbuf,#'n'
  acall transmit
  mov sbuf,#'i'
  acall transmit
  mov sbuf,#'c'
  acall transmit
  mov sbuf,#'s'
  acall transmit
  mov sbuf,#'.'
  acall transmit
  mov sbuf,#'c'
  acall transmit
  mov sbuf,#'o'
  acall transmit
  mov sbuf,#'m'
  acall transmit

up1:
  ajmp up1           ;Loop here

transmit:            ;Transmit subroutine
  jnb ti, transmit   ;Wait for completion of
                     ;transmission
  clr ti             ;Clear transmit flag
  ret

end

 

 

;*************************************************
;
;Program: UART_test_1
;Author: Srikanth
;Website: http://shree-electronics.com/
;Description: Prints the next char of the typed
; character on the hyperterminal window
;
;*************************************************

org 0000h
  ljmp main


main:
 mov tmod,#20h      ;Timer 1 configured to 8 bit
                    ;auto reload
  mov th1,#-6       ;Baud rate set to 9600
  mov scon,#50h     ;UART configure as 8 data bits
  setb tr1          ;with 1 start and stop bit
up:
  acall recieve     ;First recieve the char typed on
                    ;hyperterminal
  cjne a,#'z',next  ;If typed char is not Z, then
  mov a,#'a'-1      ;send next char of the typed one
next:
  inc a
  acall transmit
  sjmp up           ;Loop

transmit:           ;Transmit subroutine
  mov sbuf,a        ;Move the char to be transmitted
                    ;into SBUF reg
  jnb ti,$          ;Wait for transmission to be
                    ;complete
  clr ti            ;clear transmit flag
  ret

recieve:            ;Recieve subroutine
  jnb ri,$          ;wait for a char to be recieved
  mov a,sbuf        ;save the recieved char
  clr ri            ;clear recieve flag
  ret

end

 

BACK

Custom Search

  

 

Home | Microcontrollers | Abbreviations | Useful Tools | Hot Links | Gallery | Feedback

Microcontrollers | Interfacing LED's | Interfacing 7 segment | Multiplexing 7 segments | PWM Basics | Interfacing Relays | Interfacing 4x4 keypad | 8051 Serial port

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

Email: feedback@shree-electronics.com, Feel free to link to this site.

Disclaimer : I have taken utmost care while composing this site. But neither the author himself nor any of the linked sites can be held responsible for any missing or inaccurate information.

© copyright Srikanth 2008.