#Microcontrollers Serial Communication (UART) using 8051

/*------------------Serial Communication--------------------*/
/*
=============================================================================
Program in ASM Language to Demonstrate the Serial Communication on 8051 development Platform
-----------------------------------------------------------------------------
Interfacing Pins :
                    P3.0 ----> RxD
                    P3.1 ----> TxD
-----------------------------------------------------------------------------
Jumper Settings:
No Jumper Setting
=============================================================================
*/
org 0x00
ljmp start ;jump to start on reset

;String lookup table
str: DB ' ','h','e','l','l','o',' ','w','o','r','l','d',0x0a,0x0d

serial_init:  ;Initialize UART at 600baud rate
mov SCON,#0x50
mov a,TMOD
orl a,#0x20
mov TMOD,a
mov TH1,#0xFD ;Count for 9600 baud rate
setb TR1
setb TI
ret

Xmit_char: ;routine to transmit single character
mov sbuf,a
c1: jnb ti,c1
clr TI
ret

Rcv_char:    ;Routing to recieve the character
c2: jnb ri,c2    ;wait till char is recieved
mov r0,sbuf
clr RI
mov P2,R0 ;Print the bit pattern on lES
ret

start:   ;main program
lcall serial_init
l1:   ;Code to display the string
mov r7,#0x0C
mov dpl,#str
l2:
mov a,#0x00
movc a,@a+dptr
lcall Xmit_char
inc dptr
djnz r7,l2
l3:   ;Loop to print the recieved character
lcall Rcv_char
mov a ,r0
lcall Xmit_char
sjmp l3

end

Comments