0% found this document useful (0 votes)
43 views16 pages

22bce0161 VL2023240505539 Ast05

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views16 pages

22bce0161 VL2023240505539 Ast05

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Course Name: Microprocessors and Microcontrollers Lab

Course Code: BECE204P

Dr Vishal Gupta
Assistant Professor
School of Electronics Engineering
Vellore Institute of Technology, Vellore, Tamil Nadu, India

1
Lab Notebook
Your notebook must be clearly labelled on the cover with the
following information:
Course Name: Microcontroller and Microprocessor

Course Code: BECE204P

Name:

Sheriff singh

Register
No:22BCE0161

Slot/Batch Timing:

Lab faculty Name:

2
Lab Record
 Aim
 Tool Required
 Relevant Theory or Diagram if require
 Assembly language program (ALP) Code
 Output{Screen Shot}(Result)
 Conclusion

3
Lab Assessment -
5
1. Program to receive bytes of data serially, and put them in P2, set the
baud rate at 9600, 8-bit data, and 1 stop bit ?

2. Assume that the 8051 serial port is connected to the communication port
of PC. P1 and P2 of the 8051 are connected to LEDs and switches,
respectively. Write an Assembly language program to (a) send to PC the
message “We Are Ready”, (b) receive any data send by PC and put it on
LEDs connected to P1, and (c) get data on switches connected to P2 and
send it to PC serially. The program should perform part (a) once, but
parts (b) and (c) continuously, use 4800 baud rate.
4
5
1-

AIM: Program to receive bytes of data serially, and put them in P2, set the baud rate at 9600, 8-
bit data, and 1 stop bit

TOOLS-KEIL UVISION SOFTWARE

THEORY-

To receive data serially, follow these steps:

1-Configure the baud rate by setting the TMOD register to 20H, which selects
Timer 1 operating in mode 2 (8-bit auto-reload) for baud rate generation.
2-Set the appropriate values in the TH1 register to establish the desired baud
6
rate.
3-Configure the SCON register with the value 50H, specifying serial mode 1,
which frames data with an 8-bit format including start and stop bits.
4-Start Timer 1 by setting TR1 to 1.
5-Clear the Receive Interrupt (RI) flag using the CLR RI instruction.
6-Monitor the RI flag using the JNB (Jump if Bit Not Set) instruction to check if
a complete character has been received.
7-Upon detecting that RI is set, transfer the byte from the Serial Buffer (SBUF)
to a designated location for storage.
8-Repeat steps 5 to 7 to continue receiving subsequent characters.

7
CODE-

MOV TMOD, #20H ; timer 1,mode 2(auto reload)

MOV TH1, #-3 ; 9600 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 P2, A ; send to port 1

CLR RI ; get ready to receive next byte

8
SJMP HERE ; keep getting data

OUTPUT:

9
1
0
2-
1. AIM: Assume that the 8051 serial port is connected to the
communication port of PC. P1 and P2 of the 8051 are connected to LEDs
and switches, respectively. Write an Assembly language program to (a)
send to PC the message “We Are Ready”, (b) receive any data send by
PC and put it on LEDs connected to P1, and (c) get data on switches
connected to P2 and send it to PC serially. The program should perform
part (a) once, but parts (b) and (c) continuously, use 4800 baud rate.

TOOLS-KEIL UVISION SOFTWARE

1
1
THEORY:
 This code is written in assembly language and it appears to be for a microcontroller.

 The first line, "ORG 0000H", sets the origin of the program to address 0000H, which is where the
program will start executing.
 The next line, "MOV P2, #0FFH", moves the value FF (in binary) into register P2.
 This could potentially be setting up some pins on the microcontroller as outputs.
 The following lines set up various registers and bits for serial communication.
 TMOD is used to set up timer modes, TH1 sets a timer value, SCON configures serial port control
bits, TR1 enables Timer 1 (which may be used for timing in serial communication), DPTR points to an
address in memory that will be used later on in the program.
 Next there is a label called H_1 followed by CLR A which clears register A. MOVC A,@A+DPTR
moves data from memory at address DPTR + A into register A using indirect addressing mode.
 JZ B_1 checks if register A contains zero and jumps to label B_1 if it does.
 ACALL SEND calls subroutine SEND which sends data out through a serial port using SBUF
(serial buffer).

1
2
 INC DPTR increments the value stored in DPTR by one so that it points to the next location in
memory.
 SJMP H_1 jumps back to label H_1 and repeats this process until all data has been sent out
 The code is a program written in assembly language that sets up the necessary registers and
instructions for communication between two devices.
 It initializes the ports, sets up the timer and serial communication, and then continuously sends
and receives data between the two devices until a specific condition is met.
 The purpose is to establish successful communication between the two devices and display the
message "We Are READY" on one of them.

1
3
CODE-

ORG 0
MOV P2, #0FFH ; make P2 an input port
MOV TMOD,#20H ;timer 1, mode 2
MOV TH1, #0FAH ;4800 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; start timer 1
MOV DPTR, #MYDATA ; load pointer for message
H_1: CLR A
MOV A,@A+DPTR ;get the character
JZ B_1 ;if last character get out
ACALL SEND ;otherwise call transfer
INC DPTR ;next one
1
4
SJMP H_1 ;stay in loop
B_1: MOV a,P2 ;read data on P2
ACALL SEND ;transfer it serially
ACALL RECV ;get the serial data

MOV P1,A ;display it on LEDs


SJMP B_1 ;stay in loop indefinitely ;
---------serial data transfer. ACC has the data-------------
SEND: MOV SBUF,A ;load the data
H_2: JNB TI,H_2 ;stay here until last bit gone
CLR TI ; get ready for next char
RET ;return to caller
; ----------Receive data serially in ACC----------------
RECV: JNB RI, RECV ; wait here for char
MOV A, SBUF ; save it in ACC
CLR RI ; get ready for next char
RET ; return to caller
1
5
; ------------The message---------------
MYDATA: DB “We Are Ready”, 0
END

OUTPUT: Desired output is achieved

1
6

You might also like