Vous êtes sur la page 1sur 20

Program No.

: 4
School of Electronics Engineering
VIT, Vellore

Reg.No 17bec0088

Student Name v.pradyumna mohan rao

L53+L54,
Course Code ECE3003 Slot & Semester
FALL ~2019-20

Course Name Microcontroller and its applications

Program Title Microcontroller and its applications

Date of
Date of Exp. 18/10/2019
Submission

Faculty A.Karthikeyan

Submission:
Mail Id :akece3003e1tt724@gmail.com , akece3003e2tt724@gmail.com
Mail Subject : REG.Number_L__+L__FALL_19_20
File Name and format : Reg.number.docx (doc) - only

MAIL YOUR, DIGITAL ASSIGNMENT , LAB PROGRAMS TO THE ABOVE SAID MAIL ID
And also LOAD YOUR DOCUMENTS BEFORE THE DEAD LINE ON THE INTRANET
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Question
1. Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit
data, one stop bit and observe the transmitted data in the serial window of the
simulator.
2. Write a 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).
Assume that the 8051 serial port is connected to the COM port of IBM PC, P1 and P2 of
the 8051 are connected to LEDs and switches, respectively.
3. Write an 8051 assembly 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.
4. Write an 8051 program to get data from port P0 and send it to port P1 continuously
while an interrupt will do the following: Timer 0 will toggle the P2.1 bit every 100
microseconds.
5. 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.
6. Write a program using interrupts to do the following: (a) Receive data serially and sent
it to P0,(b) Have P1 port read and transmitted serially, and a copy given to P2, (c) Make
timer 0 generate a square wave of 5kHz frequency on P3.2.Assume that XTAL-11.0592.
Set the baud rate at 4800.
Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit data, one
stop bit and observe the transmitted data in the serial window of the simulator
Aim: To write an 8051 ALP TO transfer data serially into the serial window of the simulator,
with a baud rate of 9600 and to observe the transmitted data in the serial window of the
simulator. We use timer 1 mode 2
Tools Required: keil Uvision software
Algorithm:
1. Configure the TMOD register
2. load baud rate into the TH1 register
3. set SCON register
4. get data from ROM
5. set SBUF register
SENSE, VIT Page 2 of
20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

6. jump when transmitt interrupt flag turns’1’

Program:

Memory Label Mnemonics Operands addressing Machine Memory Type of Comments Flags
mode used cycle Byte Instruction getting
Address
Required Required affected by
the
Instruction.

MOV Register Direct 1 1 Data Transfers None


1,registe addresing transfer The data
r2 mode From one
Register
to anothe

SJMP None None 2 2 Branch Performs None


a short
Jump to a
location
Given by
label

SETB Register Direct 2 2 Bit Sets the None


1 addressin manipul Specified
g mode ation Bit as 1

CLR Register Direct 2 1 Bit Sets the None


1 addresing manipul Specified
mode ation Bit as 0

MOVC accumul Indexed 1 2 Data Transfers None


A,@A+DP ator addressin transfer Code byte
TR g mode From ACC
+PC to
ACC

DJNZ accumul None 2 2 Branch Jump if None


ator instructi acc is not
on zero

JNB Register None 3 2 Bit Jump if none


1 manipul register 1

SENSE, VIT Page 3 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

ation is not
zero

INC Register None 1 1 Arthima Incremen None


1 tic t the
instructi specified
on register

Manual Calculation :
Delay time = 16*1.085*10^-6 = 1.736*10^-5 s

Results and Observations


Print Screen of the Program and registers before execution:

SENSE, VIT Page 4 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Print Screen of the Program and registers after execution:

Inferences:
1. The data transferred serially with baud rate 9600 and transmitted data in the serial window of

the simulator is observed.

Result: the 8051 ALP to transfer data serially at baud rate 9600 and the transmitted data in
the serial window of the simulator is examined using KEIL software and results are verified
manually.

SENSE, VIT Page 5 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

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.

Aim: To receive data from single bit p1.2and display it on P1.7 while a serial interrupt receives
data from PC and display it on p2 port.
Tools Required: keil uVision software
Algorithm:
STEP1: organize memory at serial interrupt vector table.
STEP2: organise memory at 30h after the vector table address.
STEP3: make p1.2 as input port to read input.
STEP4: load TMOD value with #20H(timer 1 in mode 2).
STEP5: set baud rate of 9600.
STEP6: load SCON WITH 50H (one stop bit and start bit).
STEP7: load IE register with #10010000B (serial interrupt enabled).
STEP8: start timer 1.
STEP9: copy P1.2 input to carry flag.
STEP10: copy that value from flag to P1.7.
STEP11: end

Program:

Memory Label Mnemonic Operands addressing mode Memory Byte Time taken
s used Required
Address

ORG 0000H

MAIN LJMP MAIN 3 2

ORG 0023H

SERIAL LJMP SERIAL 3 2

SENSE, VIT Page 6 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

ORG 0030H

MAIN SETB P1.2 2 2

MOV TMOD,#20H Immediate 2 1

MOV TH1,#-3 Immediate 2 1

MOV SCON,#50H Immediate 2 1

MOV IE,#10010000B Immediate 2 1

SETB TR1 2 2

BACK MOV C,P1.2 Direct byte to 3 2


direct byte

MOV P1.7,C Direct byte to 3 2


byte

BACK SJMP BACK 2 2

MOV A,SBUF Direct byte to 2 1


byte

MOV P2,A Direct 2 1

CLR RI 2 1

RETI 1 2

TRANS CLR TI 2 1

RETI 1 2

END

Manual Calculation :
Delay time = 26*1.085*10^-6 = 2.821*10^-5
SENSE, VIT Page 7 of
20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Results and Observations

Print Screen of the Program and registers before execution:

Print Screen of the Program and registers after execution:

SENSE, VIT Page 8 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
1. We observe that data is serially transferring from PC to P2 and p1.7 changes its according to the

change in p1.2

Result: we are serially receiving information from pc and display it on P2 and copying data from
P1.2 to P1.7 is executed using keil software.

4.Write an 8051 program to get data from port P0 and send it to port P1 continuously while an
interrupt will do the following: Timer 0 will toggle the P2.1 bit every 100 microseconds.

Aim: To write an assembly program that generates a square wave with 100usec duration
and to receive data from p0 and send it to p1 using interrupts
Tools Required: keil uVision software
Algorithm:
STEP1: write the interrupt code to toggle P2.1 in the interrupt vector table.
STEP2: organise memory at 30h after the vector table address.
STEP3: load TMOD value with #02H(timer 0 in mode 2).

SENSE, VIT Page 9 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

STEP4: make P0 as an input port.


STEP5: load TH with -92.
STEP6: start the timer.
STEP7: move input from P0 to A.
STEP8: copy values of A to P1.
STEP9: End

Program:

Memory Label Mnemonics Operands addressing mode Machine cycle Time taken
used Required
Address

ORG 0000H

MAIN LJMP MAIN 3 2

ORG 000BH

CPL P2.1 2 1

RETI 1 2

ORG 0030H

MAIN MOV TMOD,#20H Immediate 2 1

MOV P0,#OFFH Immideate 2 1

MOV TH0,#-92 Immediate 2 1

MOV IE,#100000 immediate 2 1


010B

SETB TR0 2 2

BACK MOV A,P0 2 1

MOV P1,A 2 1

SENSE, VIT Page 10 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Manual Calculation :
Delay time = 12*1.085*10^-6 = 1.302*10^-5 s

Results and Observations


Print Screen of the Program and registers before execution:

Print Screen of the Program and registers after execution:

SENSE, VIT Page 11 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
1.We can observe in the logic analyser that a square wave is generated by toggling p2.1 and the data

from port P0 is send to port P1 continuously

Result: we toggled the P2.1 as an interrupt program while data is transferred from p0 to p1 is
observed in the keil software.

Write a program using interrupts to do the following: (a) Receive data serially and sent it to P0,(b)
Have P1 port read and transmitted serially, and a copy given to P2, (c) Make timer 0 generate a
square wave of 5kHz frequency on P3.2.Assume that XTAL-11.0592. Set the baud rate at 4800.

Aim: To receive data serially and send it to P0 and generate a square wave of frequency of 5kz
and also make P1 read port and copy to P2.
Tools Required: keiluVision software

Algorithm:
STEP1: write code for timer0 interrupt vector table.
STEP2: organise memory at serial interrupt vector table.
STEP3: organise memory at 30h after the vector table address.
STEP4: make P1 as input ports.
SENSE, VIT Page 12 of
20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

STEP5: load TMOD value with #20H(timer 1 in mode 2). STEP6: set baud rate of 4800.
STEP7: load SCON WITH 50H (one stop bit and start bit).
STEP8: load IE register with #10010010B (serial interrupt enabled).
STEP9: load TH0 with #66H
STEP10: start timer 1 and start timer 0.
STEP11: read P1 and transform serially.
STEP12: return interrupt
STEP13:end

Program:

S.NO Label Mnemonics Operands addressing mode used Machine Memory


cycle Byte
Required Required

1 ORG 0000H

2 MAIN LJMP MAIN 3 2

3 ORG 0023H

4 SERIAL LJMP SERIAL 3 2

5 ORG 0030H

6 MAIN SETB P1.2 2 2

7 MOV TMOD,#20H Immediate 2 1

8 MOV TH1,#-6 Immediate 2 1

9 MOV SCON,#50H Immediate 2 1

10 MOV IE,#10010010B Immediate 2 1

11 SETB TR1 2 2

12 SETB TR0 2 1

13 BACK MOV A,P1 Direct byte to byte 2 1

14 MOV SBUF,A Direct byte to byte 2 1


SENSE, VIT Page 13 of
20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

15 MOV P2,A Direct 3 2

16 BACK SJMP BACK 2 2

17 SERIAL JB TI,TRANS 3 2

18 MOV A,SBUF 2 1

19 MOV P0,A Direct byte to byte 2 1

20 CLR RI 2 1

21 RETI 1 2

22 TRANS CLR TI 2 1

23 RETI 1 2

24 END

Manual Calculation :
Delay time = 35*1.085*10^-6 = 3.7975*10^-5 s

Results and Observations

SENSE, VIT Page 14 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Print Screen of the Program and registers before execution:

Print Screen of the Program and registers after execution:

SENSE, VIT Page 15 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
1. We can observe the 5khz square wave generated by continuously toggling of P3.2 using interrupt

programing and data is transmitted serially from PC to P0 and P2 changes it values according to p1

Result: The 8051 ALP to perform all the above tasks in one program is executed using keil
software and the results are verified manually.

Write an 8051 assembly 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
Aim: to send the PC data and send by pc to led connected to p1 and switches to p2 and pc serially
Tools Required
Algorithm:
1. Configure the TMOD register
2. Load baud rate into the TH1 register
3. Set SCON register
4. Start the timer
5. Get data from ROM
6. Set SBUF register
7. Jump when Transmit interrupt flag turns ‘1’
8. Reset the baud rate into the TH1 register
9. Set SCON register
10. Start the timer
11. Jump when receive interrupt is ‘1’
12. Move data from SBUF to P1
13. Clear receive interrupt
14. Reset the baud rate into the TH1 register
15. Set SCON register
16. Start the timer

SENSE, VIT Page 16 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

17. Turn P1.2 into an input port and receive the data
18. Move the data to SBUF register
19. Jump when transfer interrupt is ‘1’

Program:

Label Mnemonics Operands addressing Machine Memory Type of Comments Flags


mode used cycle Byte Instruction getting
Required Required affected by
the
Instruction.

None MOV Register Direct 1 1 Data Transfers None


1,2 addressin transfer data from
g mode one to
another
reg

Send, ACALL None None 2 2 Branch Call a None


subroutin
Recv
e

L1,L2 SJMP None None 2 2 Branch Performs None


short
jump

TR1 SETB Register Direct 2 2 Bit Sets None


1 manipul specified
ation bit as 1

RI,TI, CLR Register Direct 2 1 Bit Sets None


A 1 manipul specified
ation bit as0

A MOVC accumul Indexed 1 2 Data Transfers None


A,@A+DP ator transfer code byte
TR

L2 LZ accumul None 2 2 Branch Jump if None


ator acc in not
0

SENSE, VIT Page 17 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

L3,RE JNB Register None 3 2 Bit Jump if None


CV 1 manipul register 1
ation is not 0

DPTR INC Register none 1 1 Arithma Incremen None


1 tic t the
specified
reg

Manual Calculation :
Delay time = 0.000066081 sec

Results and Observations


Print Screen of the Program and registers after execution:

SENSE, VIT Page 18 of


20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Inferences:
The message was sent to the PC and observed in the UART. The 8051 received data from the PC and

displayed the output in the P1 port

Result: The 8051 alp to send message to the PC and to receive data from PC and to put it on P1 is
executed by keil software and results are verified manually.

2…Write a 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).
Assume that the 8051 serial port is connected to the COM port of IBM PC, P1 and P2 of the
8051 are connected to LEDs and switches, respectively.

Aim: to perform that the 8051 serial port is connected to the COM port of IBM PC, P1 and
P2 of the 8051 are connected to LEDs and switches, respectively.

Tools Required: keil uVision software


Program:

Results and Observations

Print Screen of the Program and registers before execution:


SENSE, VIT Page 19 of
20
Reg no: Fall 2019-20 ECE3003 - 𝜇C and its applications

Print Screen of the Program and registers after execution:

SENSE, VIT Page 20 of


20

Vous aimerez peut-être aussi