Da 4-21bce3214
Da 4-21bce3214
Da 4-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 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.
• 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:
• 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:
• Repeat the character transmission process until the null terminator is encountered.
• After completing the transmission of the message, go back to the start of the message (if
continuous transmission is desired).
Program:
ORG 200H
DATA1: DB "VISHWAS_"
ORG 00H
MOV TMOD,#20H
MOV SCON,#50H
MOV TH1,#-3
SETB TR1
MOV R0,#6
L1: CLR A
MOVC A,@A+DPTR
ACALL TRANS
INC DPTR
DJNZ R0,L1
SJMP L2
TRANS: MOV SBUF,A
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).
• 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.
• Enter an infinite loop to continuously monitor the serial port for incoming data.
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).
• Transfer the data from A to Port P1, where it can be output or displayed.
• Clear the Receive Interrupt Flag (RI) to prepare for the next byte of incoming data.
• 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
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.
• 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 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 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.
• 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
MOV P1,#00H
SETB P2.1
MOV TMOD,#02H
MOV TH0,#0A4H
MOV IE,#82H
SETB TR0
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.
o Port Initialization:
o Timer Initialization:
▪ 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).
▪ 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.
▪ 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.
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.
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
SETB TR0
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 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).
o Timer Initialization:
▪ Load TH1 with -3 to set the baud rate for 2400 bps with an 11.0592 MHz
crystal.
▪ 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).
▪ Moves the data from A to Port P1, outputting the value read from P0 to
P1.
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 Off the Buzzer: Clear P1.4 to turn off the buzzer.
o When the serial interrupt triggers, this ISR executes to transmit a message over
the serial port:
6. Message Definition:
SJMP MAIN
ORG 0013H
SETB P1.4
BUZZER_DELAY:
CLR P1.4
RETI
ORG 0023H
SJMP SERIAL_ISR
MAIN:
SETB TR1
LOOP:
MOV A, P0
MOV P1, A
SJMP LOOP
SERIAL_ISR:
CLR A
MOVC A, @A+DPTR
JZ DONE
MOV SBUF, A
WAIT_TX:
CLR TI
INC DPTR
SJMP SEND_CHAR
DONE:
RETI
MESSAGE:
DB "VISHWAS_", 0
END
Result:
Output:
Copying data from P0 to P1
Serial Transmission
Conclusion:
Successfully performed the desired task using 8051 code.