Da 4-21bce3214

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

MPMC - LAB DA 4

Name: Vishwas Arora


Reg. No: 21BCE3214

Q1
AIM: Write an 8051-assembly program to transfer your
name serially at baud rate 9600 with 8 bit data, one stop
bit and observe the transmitted data in the serial window
of the simulator.
Tools Required: Keil Microvision Software
Algorithm:
1. Initialize Timer and Serial Port for Baud Rate:

• Set Timer 1 in Mode 2 (Auto-Reload Mode) by loading TMOD with 20H.

• Set the Serial Control Register (SCON) to 50H to enable 8-bit UART mode with the
Receive Enable (REN) bit set.

• Load TH1 with -3 to set the baud rate to 2400 for an 11.0592 MHz crystal.

• Start Timer 1 by setting TR1.

2. Main Loop - Continuously Transmit Message:

• Load the starting address of the message DATA1 (stored at memory location 200H) into
the Data Pointer Register (DPTR).

• Begin a loop to read each character from DATA1 and transmit it via the serial port.

3.Character-by-Character Transmission:

• Clear the Accumulator (A).

• Read the character at the address pointed by DPTR and store it in A.

• Check if the character is a null terminator (0):

o If it is a null terminator, jump to END_TRANSMIT to stop transmission of the


current message.
o Otherwise, proceed to the transmission subroutine.

4.Transmit Character Subroutine (TRANS):

• Load the character from A into the Serial Buffer Register (SBUF) to initiate transmission.

• Wait for the transmission to complete by checking the Transmit Interrupt (TI) flag:

o If TI is not set, keep waiting.

o Once TI is set, clear TI to prepare for the next character.

• Return to the main loop.

5.Increment Address and Continue Loop:

• Increment DPTR to point to the next character in DATA1.

• Repeat the character transmission process until the null terminator is encountered.

6.Loop to Retransmit Message:

• After completing the transmission of the message, go back to the start of the message (if
continuous transmission is desired).

• Repeat the transmission process from Step 2.

Program:
ORG 200H

DATA1: DB "VISHWAS_"

ORG 00H

MOV TMOD,#20H

MOV SCON,#50H

MOV TH1,#-3

SETB TR1

L2: MOV DPTR,#DATA1

MOV R0,#6

L1: CLR A

MOVC A,@A+DPTR

ACALL TRANS

INC DPTR

DJNZ R0,L1

SJMP L2
TRANS: MOV SBUF,A

L3: JNB TI,L3

CLR TI

RET

END

Results:

Output:

Conclusion:
Successfully transmitted VISHWAS at 9600 baud rate using 8051
code.
Q2
AIM: Write an 8051 Assembly Language program to get
data from the PC and display it on P1. Assume 8051 is
connected to PC and observe the incoming characters. As
you press a key on the PC's keyboard, the character is sent
to the 8051 serially at 4800 baud rate and is displayed on
LEDs. The characters displayed on LEDs are in ASCII
(binary).
Tools Required: Keil Microvision Software
Algorithm:
1.Initialize Port and Timer:

• Set Port P1 to 00H, which clears any existing data on the port (sets all bits to 0).

• Set Timer 1 in Mode 2 (Auto-Reload Mode) by loading TMOD with 20H.

• Load TH1 with -6 to set the baud rate for the serial communication.

• Set the Serial Control Register (SCON) to 50H to configure 8-bit UART mode with the
Receive Enable (REN) bit set.

• Start Timer 1 by setting TR1 to begin baud rate generation.

2.Wait for Data Reception (Main Loop):

• Enter an infinite loop to continuously monitor the serial port for incoming data.

• Check the Receive Interrupt Flag (RI):

o If RI is clear, remain in the loop (L1) and keep checking until data is received.

o When RI is set, it indicates that a byte has been received in the Serial Buffer
(SBUF).

3. Process Received Data:

• Move the received data from SBUF to the Accumulator (A).

• Transfer the data from A to Port P1, where it can be output or displayed.

4. Clear the Receive Flag:

• Clear the Receive Interrupt Flag (RI) to prepare for the next byte of incoming data.

5.Repeat the Loop:

• Jump back to the start of the loop (L1) to wait for the next byte of data.
Program:
ORG 00H

MOV P1,#00H

MOV TMOD,#20H

MOV TH1,#-6

MOV SCON,#50H

SETB TR1

L1: JNB RI,L1

MOV A,SBUF

MOV P1,A

CLR RI

SJMP L1

END

Results:
Output:

Conclusion:
Successfully performed the desired task using 8051 code.
Q3
AIM:
Write an 8051 program to get data from port P0 and send it
to port P1continuously while an interrupt will do the
following: Timer 0 will toggle the P2.1 bit every 100
microseconds.
Tools Required: Keil Microvision Software
Algorithm:
1.Initialize the Program:

• Start at address 00H and use a long jump (LJMP MAIN) to jump to the MAIN program at
address 50H.

2.Set Up Ports and Timer:

• Port Initialization:

o Set all bits of Port P0 to 1 by loading 0FFH into P0. This configures P0 as an input
port.

o Set all bits of Port P1 to 0 by loading 00H into P1. This clears P1, which will be
used as an output port.

o Set Port P2.1 to 1 by setting P2.1 to high. This initializes P2.1, which will toggle
with the timer interrupt.

• Timer 0 Initialization:

o Set Timer 0 to Mode 2 (Auto-Reload Mode) by loading 02H into TMOD.

o Load TH0 with 0A4H, which sets the reload value for Timer 0.

• Interrupt Setup:

o Load IE with 82H to enable Timer 0 Interrupt (ET0) and Global Interrupt Enable
(EA).

• Start Timer 0:

o Set TR0 to 1 to start Timer 0.

3.Main Loop - Data Transfer from P0 to P1:

• Enter an infinite loop (L1) that continuously:

o Reads the data from Port P0 into the Accumulator (A).

o Writes the data from Accumulator (A) to Port P1, outputting the value read from
P0 to P1.
4. Timer 0 Interrupt Service Routine (ISR):

• When Timer 0 overflows, the interrupt is triggered, and the following steps are executed:

o Toggle the bit P2.1 (complement P2.1). This changes the state of P2.1 from high
to low or low to high, creating a blinking effect.

• Return from Interrupt (RETI) to go back to the main program.

5.Repeat the Main Loop:

• Continue looping back to L1 to read data from P0 and write it to P1 while the timer
interrupt toggles P2.1 periodically.

Program:
ORG 00H

LJMP MAIN

ORG 50H

MAIN: MOV P0,#0FFH

MOV P1,#00H

SETB P2.1

MOV TMOD,#02H

MOV TH0,#0A4H

MOV IE,#82H

SETB TR0

L1: MOV A,P0

MOV P1,A

SJMP L1

ORG 0BH

CPL P2.1

RETI

END
Result:

Output:
Transferring data from Port 0 to Port 1
Toggling Port 2.1

Conclusion:
Successfully performed the desired task using 8051 code.
Q4
AIM:
Write an 8051 program to get data from a single bit of P1.2
and send it to P1.7 continuously while an interrupt will do
the following: A serial interrupt service routine will receive
data from a PC and display it on P2 ports.
Tools Required: Keil Microvision Software
Algorithm:
1. Program Initialization:

o Start at address 00H and use a long jump (LJMP MAIN) to jump to the main
program at address 50H.

2. Set Up Ports and Serial Communication:

o Port Initialization:

▪ Set P1.2 to 1 (high) and P1.7 to 0 (low).

▪ Clear Port P2 by loading 00H into it, setting it as an output port.

o Timer Initialization:

▪ Set Timer 0 to Mode 2 (Auto-Reload Mode) by loading 02H into TMOD.

▪ Load TH0 with -3 to set the timer reload value, establishing a specific
timer interval.

o Interrupt Setup:

▪ Load IE with 90H to enable serial interrupt (ES) and global interrupt
enable (EA).

o Serial Communication Setup:

▪ Set SCON to 50H to configure the UART for 8-bit variable baud rate
mode.

o Start Timer 0:

▪ Set TR0 to 1 to start Timer 0, enabling it to maintain the baud rate for
serial communication.

3. Main Loop - Mirror Bit from P1.2 to P1.7:

o Enter an infinite loop (L1) that continuously:

▪ Reads the bit value of P1.2 and stores it in the carry flag (C).
▪ Moves the carry flag value to P1.7, mirroring the state of P1.2 to P1.7.

4. Serial Interrupt Service Routine (ISR):

o When data is received over the serial port, the serial interrupt is triggered,
executing the following steps:

▪ Load the received data from the Serial Buffer (SBUF) into the
Accumulator (A).

▪ Move the data from the Accumulator (A) to Port P2, outputting the
received data on P2.

▪ Clear the Receive Interrupt Flag (RI) to prepare for the next byte of data.

5. Repeat the Main Loop:

o Return to the main loop at L1 after servicing the serial interrupt and continue
mirroring P1.2 to P1.7.

Program:
ORG 00H

LJMP MAIN

ORG 50H

MAIN:

SETB P1.2

CLR P1.7

MOV P2,#00H

MOV TMOD,#02H

MOV TH0,#-3

MOV IE,#90H

MOV SCON ,#50H

SETB TR0

L1: MOV C,P1.2

MOV P1.7, C

SJMP L1

ORG 23H

MOV A,SBUF
MOV P2,A

CLR RI

RETI

END

Result:

Output:
P1.2 AND P1.7 always having the same value

Conclusion:
Successfully performed the desired task using 8051 code.
Q5
AIM:
Write an 8051-assembly language program to get the data
from Port P0 and send it to Port P1 continuously, while the
interrupts will do the following, assume XTAL = 11.0592
MHz (a) Keep transmitting YOUR NAME continuously
through the serial COM port with 2400 baud rate. (b)
Whenever there is a falling edge at P3.3 (INT1 pin), turn on
the buzzer at P1.4 for some time.
Tools Required: Keil Microvision Software
Algorithm:
1. Set Up Interrupt Vector Table:

o At address 0000H, jump to the main program using SJMP MAIN.

o At address 0013H, set up the external interrupt vector (for a buzzer) by jumping
to its handler.

o At address 0023H, set up the serial interrupt vector by jumping to its handler
(SERIAL_ISR).

2. Initialize Timer and Serial Communication (Main Program):

o Timer Initialization:

▪ Set Timer 1 in Mode 2 (Auto-Reload Mode) by loading TMOD with 20H.

▪ Load TH1 with -3 to set the baud rate for 2400 bps with an 11.0592 MHz
crystal.

o Serial Communication Setup:

▪ Set SCON to 50H to configure the UART for 8-bit variable baud rate mode
with receive enabled (REN).

▪ Start Timer 1 by setting TR1 to 1, which enables baud rate generation for
the serial port.

o Interrupt Setup:

▪ Set the Interrupt Enable (IE) register to 10010100B to enable serial and
external interrupts and the global interrupt enable (EA).

3. Main Loop - Continuously Transfer Data from P0 to P1:


o Enter an infinite loop (LOOP) that:

▪ Reads data from Port P0 into the Accumulator (A).

▪ Moves the data from A to Port P1, outputting the value read from P0 to
P1.

o This loop continues indefinitely to transfer data from P0 to P1.

4. External Interrupt 1 ISR (Buzzer Control):

o When a falling edge on the external interrupt pin (e.g., P3.3) triggers External
Interrupt 1, this interrupt service routine (ISR) executes:

▪ Turn On the Buzzer: Set P1.4 high to activate the buzzer.

▪ Delay Loop: Use a delay loop (BUZZER_DELAY) with R0 set to 50 to keep


the buzzer on for a set duration.

▪ Turn Off the Buzzer: Clear P1.4 to turn off the buzzer.

o Return from Interrupt (RETI) to go back to the main program.

5. Serial Interrupt ISR (Serial Transmission):

o When the serial interrupt triggers, this ISR executes to transmit a message over
the serial port:

▪ Load the address of MESSAGE into the Data Pointer (DPTR).

o Character Transmission Loop:

▪ Clear A and load the character at DPTR into A.

▪ Check if the character is a null terminator (0):

▪ If yes, the transmission ends (DONE).

▪ If no, move the character from A to SBUF to initiate serial


transmission.

▪ Wait for transmission completion by checking the Transmit Interrupt (TI)


flag:

▪ When TI is set, clear TI and increment DPTR to the next


character.

▪ Repeat the transmission for all characters in MESSAGE.

o Return from Interrupt (RETI) after completing the message transmission.

6. Message Definition:

o The message "VISHWAS_" is stored in memory, followed by a null terminator (0)


to signal the end of the message.
Program:
ORG 0000H

SJMP MAIN

ORG 0013H

SETB P1.4

MOV R0, #50

BUZZER_DELAY:

DJNZ R0, BUZZER_DELAY

CLR P1.4

RETI

ORG 0023H

SJMP SERIAL_ISR

MAIN:

MOV TMOD, #20H

MOV TH1, #-3

MOV SCON, #50H

SETB TR1

MOV IE, #10010100B

LOOP:

MOV A, P0

MOV P1, A

SJMP LOOP

SERIAL_ISR:

MOV DPTR, #MESSAGE


SEND_CHAR:

CLR A

MOVC A, @A+DPTR

JZ DONE

MOV SBUF, A

WAIT_TX:

JNB TI, WAIT_TX

CLR TI

INC DPTR

SJMP SEND_CHAR

DONE:

RETI

MESSAGE:

DB "VISHWAS_", 0

END

Result:
Output:
Copying data from P0 to P1

Turning on buzzer at P1.4 when P3.3 is triggered

Serial Transmission

Conclusion:
Successfully performed the desired task using 8051 code.

You might also like