Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Name: Kamalanayana S

18BEC0838

TASK - 4
Serial Communication

Name: Kamalanayana S
Reg no.- 18BEC0838
Slot- L31+L32

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

05-09-2020

1. Write a program for the 8051 to transfer letter “A” serially at 4800 baud,
continuously.

Calculation:
Step1: The machine cycle frequency of 8051= 11.0592/12 =921.6 kHz
Step 2: 921.6kHz/32= 28800 Hz is frequency of UART to timer 1 to set baud rate
Step 3: 28800/4800= 6

Code:
MOV TMOD, #20H ; Timer 1, Mode 2
MOV TH1, #-6 ; 4800 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; Start timer 1
AGAIN: MOV SBUF, #'A' ; Letter “A” to transfer
HERE: JNB TI, HERE ; Wait for the last bit
CLR TI ; Clear TI for next char
SJMP AGAIN
END

Output:

Observation:
We can observe that by using SBUF register we are able to communicate with outside world.

05-09-2020

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

2. Write a program for the 8051 to transfer “YES” serially at 9600 baud, 8-bit data, 1
stop bit, do this continuously.

Calculation:
Step1: The machine cycle frequency of 8051= 11.0592/12 =921.6 kHz
Step2: 921.6kHz/32= 28800 Hz is frequency of UART to timer 1 to set baud rate
Step3: 28800/9600= 3

Code:
MOV TMOD, #20H ; Timer 1, Mode 2
MOV TH1, #-3 ; 9600 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; Start timer 1
AGAIN: MOV A, #’Y’ ; Transfer “Y”
ACALL TRANS
MOV A, #’E’ ; Transfer “E”
ACALL TRANS
MOV A, #’S’ ; Transfer “S”
ACALL TRANS
SJMP AGAIN ; Keep doing it
; Serial data transfer subroutine
TRANS: MOV SBUF, A ; Load SBUF
HERE: JNB TI, HERE ; Wait for the last bit
CLR TI ; Get ready for next byte
RET
END

Output:

Observation:
We observed that we are able to use same SBUF register for multiple data communication.

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

07-09-2020

3. Write a program for the 8051 to receive bytes of data serially, and put them in P1,
set the baud rate at 4800, 8-bit data, and 1 stop bit.

Calculation:
Step1: The machine cycle frequency of 8051= 11.0592/12 =921.6 kHz
Step2: 921.6kHz/32= 28800 Hz is frequency of UART to timer 1 to set baud rate
Step3: 28800/4800= 6

Code:
MOV TMOD, #20H ; Timer 1, mode 2
MOV TH1, #-6 ; 4800 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; Start timer 1
HERE: JNB RI, HERE ; Wait for char to come in
MOV A, SBUF ; Saving incoming byte in A
MOV P1, A ; Send to port 1
CLR RI ; Get ready to receive next byte
SJMP HERE ; Keep getting data
END

Output:

Observation:

We are able to use SBUF register for reception also from the user.

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

Task:

1. Develop an 8051 ALP to implement the serial communication as per the following :
a. If the Microcontroller receives a number “1” then generate a square wave for 1 KHz.
b. If the Microcontroller receives a number “2” then generate a square wave for 2 KHz.
c. If the Microcontroller receives a number “3” then generate a square wave for 3 KHz.

Calculation:
Step1: The machine cycle frequency of 8051= 11.0592/12 =921.6 kHz
Step2: 921.6kHz/32= 28800 Hz is frequency of UART to timer 1 to set baud rate
Step3: 28800/9600= 3

a) F= 1 kHz
T= 1/1kHz = 1 ms
T/2= 0.5 ms
0.5ms/1.085us= 460.8= 461
65536-461= (65075)10= (FE33)16

b) F= 2 kHz
T= 1/2kHz = 0.5 ms
T/2= 0.25 ms
0.25ms/1.085us= 230.414= 231
65536-231= (65305)10= (FF19)16

c) F= 3 kHz
T= 1/3kHz = 0.33 ms
T/2= 0.1667 ms
0.1667ms/1.085us= 153.64= 154
65536-154= (65382)10= (FF66)16
Code:
ORG 0000H
MOV TMOD, #21H ; Timer 1 mode 2 and timer 0 mode 1
MOV TH1, #-3 ; Baud rate 9600
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; Start timer 1
HERE: JNB RI, HERE ; Wait for char to come in
MOV A, SBUF ; Saving incoming byte in A
CJNE A, #31H, OR23 ; Checking if value of A is equal to 31 as ascii value of 1 is 31
CLR P1.1
ACALL DEL1 ; Call for delay of 1 kHz
SETB P1.1
ACALL DEL1 ; Call for delay of 1 kHz
CLR RI ; Get ready to receive next byte
SJMP HERE ; Keep getting data
OR23: CJNE A, #32H, OR3 ; Checking if value of A is equal to 32 as ascii value of 2 is 32
CLR P1.2
ACALL DEL2 ; Call for delay of 2 kHz
SETB P1.2

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

ACALL DEL2 ; Call for delay of 2 kHz


CLR RI ; Get ready to receive next byte
SJMP HERE ; Keep getting data
OR3: CLR P1.3 ; Case for A equal to 3 which have ascii value of 33
ACALL DEL3 ; Call for delay of 3 kHz
SETB P1.3
ACALL DEL3 ; Call for delay of 3 kHz
CLR RI ; Get ready to receive next byte
SJMP HERE ; Keep getting data
DEL1: MOV TH0, #0FEH ; Higher byte of timer 0
MOV TL0, #33H ; Lower byte of timer 0
SETB TR0 ; Start timer 0
HERE1: JNB TF0, HERE1 ; Wait till timer flag changes to 1
CLR TR0 ; Stop timer
CLR TF0 ; Clear timer flag
RET
DEL2:MOV TH0, #0FFH ; Higher byte of timer 0
MOV TL0, #019H ; Lower byte of timer 0
SETB TR0 ; Start timer 0
HERE2: JNB TF0, HERE2 ; Wait till timer flag changes to 1
CLR TR0 ; Stop timer
CLR TF0 ; Clear timer flag
RET
DEL3:MOV TH0, #0FFH ; Higher byte of timer 0
MOV TL0, #066H ; Lower byte of timer 0
SETB TR0 ; Start timer 0
HERE3: JNB TF0, HERE3 ; Wait till timer flag changes to 1
CLR TR0 ; Stop timer
CLR TF0 ; Clear timer flag
RET
END

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

Output:
When we receive 1 as input:

When we receive 2 as input:

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

When we receive 3 as input:

Observation:
We can observe when we enter 1, 2 and 3 we are able to get a square waveform of 1 kHz, 2
kHz and 3 kHz respectively.

2. Assume your name (string of data) is available in ROM address at 200H.Write an 8051-
assembly program to transfer data serially at baud rate 19200 with 8-bit data, one stop
bit and observe the transmitted data in the serial window of the simulator.

Calculation:
The machine cycle frequency of 8051= 11.0592/12 =921.6 kHz

921.6kHz/16= 57600 Hz is frequency of UART to timer 1 to set baud rate

57600/19200= 3

Code:
ORG 0000H
MOV A, PCON ; A=PCON
SETB ACC.7 ; Make D7=1
MOV PCON, A ; SMOD=1, double baud rate with same XTAL freq.
XX: MOV DPTR, #200H ; Set DPTR to 200H ROM location
MOV TMOD, #20H ; Timer 1 mode 2
MOV TH1, #-3 ; Baud rate of 19200
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; Start timer 1

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Name: Kamalanayana S
18BEC0838

MOV R1, #15 ; 15 is total number of characters at 200H


AGAIN: CLR A
MOVC A, @A+DPTR ; Load data at A from 200H
MOV SBUF, A ; Load SBUF
HERE: JNB TI, HERE ; Wait for the last bit
CLR TI ; Clear TI for next char
INC DPTR
DJNZ R1, AGAIN ; Decrement R1 after one character
SJMP XX ; Keep doing it
ORG 200H
DB 'KAMALANAYANA S '
END

Output:

Observation:
We observe that we are able to transmit data which is stored at some ROM location.

This study source was downloaded by 100000824197276 from CourseHero.com on 10-25-2022 08:19:54 GMT -05:00

https://www.coursehero.com/file/69931580/task4-micropdf/
Powered by TCPDF (www.tcpdf.org)

You might also like