Microcontroller
Microcontroller
DIGITAL ASSIGNMENT 04
SERIAL COMMUNICATION
QUESTION: Write an 8051 assembly program to transfer data serially at baud rate 9600
with 8 bit data, one stop bit and observer the transmitted data in the serial window of the
simulator.
CALCULATION:
Given, Baud rate = 9600
PROGRAM:
ORG 0000H
XX: MOV DPTR, #MYDATA
MOV TMOD, #20H ; Timer 1 Mode 2
MOV TH1, #-3
MOV SCON, #50H
SETB TR1
MOV R1, #15H
AGAIN: CLR A
MOVC A, @A+DPTR
MOV SBUF, A
HERE: JNB TI, HERE
CLR TI
INC DPTR
DJNZ R1, AGAIN
SJMP XX
MYDATA: DB „VIT UNIVERSITY‟
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
SIMULATION:
OBSERVATION:
In the above program we transferred the data from ROM serially using serial transmission
method. To check whether the transmission is completed or not, we use the JNB with TI.
Once the transmission is completed the TI becomes 1. Serial communication always uses
Timer 1 Mode 2.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
QUESTION: 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.
CALCULATION:
Given, Baud rate = 4800
PROGRAM:
ORG 0000H
MOV TMOD, #20H ; Timer 1 Mode 2
MOV TH1, #-6
MOV SCON, #50H
SETB TR1
HERE: JNB RI, HERE
MOV A, SBUF
MOV P1, A
CLR RI
SJMP HERE
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
SIMULATION:
OBSERVATION:
In the above program we received the data from Keyboard serially using serial reception
method. To check whether the reception is completed or not, we use the JNB with RI. Once
the reception is completed the RI becomes 1. Serial communication always uses Timer 1
Mode 2.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
INTERRUPTS
QUESTION: Write an ALP/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.
CALCULATION:
Given, Delay
( ) ( ) ( )
PROGRAM:
ORG 0000H
LJMP MAIN
ORG 000BH
CPL P2.1
RETI
ORG 003H
MAIN: MOV TMOD, #02H ;Timer 0 Mode 1
MOV P0, #0FFH
MOV TH0, #-92
MOV IE, #10000010B
SETB TR0
BACK: MOV A, P0
MOV P1, A
SJMP BACK
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
SIMULATION:
OBSERVATION:
In the above program, we used interrupt for Timer 0. We continuously send the data from
port P0 to P1, while when the interrupt occurs, the program control moves to the respective
ISR and perform the complement action, thus creating a square wave in P2.1.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
QUESTION: 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 at 9600 baud rate.
CALCULATION:
Given, Baud rate = 9600
PROGRAM:
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP SERIAL
ORG 0030H
MAIN: SETB P1.2
MOV TMOD, #20H ;Timer 1 Mode 2
MOV TH1, #-3
MOV SCON, #50H
MOV IE, #10010000B
SETB TR1
BACK: MOV C, P1.2
MOV P1.7, C
SJMP BACK
SERIAL: JB TI, TRANS
MOV A, SBUF
MOV P2, A
CLR RI
RETI
TRANS: CLR TI
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
SIMULATION:
OBSERVATIONS:
In the above program, we transferred the data from P1.2 to P1.7 continuously and when the
interrupt occurs, we check whether the data is transmitted or received. The received data is
displayed on port P2.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
QUESTION_01: 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:
Given, Baud rate = 9600
a) Given,
Time period,
Therefore,
Delay =
( ) ( )
b) Given,
Time period,
Therefore,
Delay =
( ) ( )
c) Given,
Time period,
Therefore,
Delay =
( ) ( )
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
PROGRAM:
ORG 0000H
MOV TMOD, #00100001B; Timer 1 Mode 2, Timer 0 Mode 1
MOV TH1, #-3
MOV SCON, #50H
SETB TR1
XX: JNB RI, XX
MOV A, SBUF
MOV P2,A ; To display received value
CLR RI
SIMULATION:
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
OBSERVATIONS:
In the above program, we serially received the data from the keyboard. The received data is
always in ASCII value. We check the received value, if it is equal to 1 then we generate 1kHz
square wave in P1.1, else if it is equal to 2 then we generate 2kHz square wave in P1.1, else if
it is equal to 3 then we generate 3kHz square wave in P1.1 and the received value is also
displayed in P2.
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017
CALCULATION:
Given, Baud rate = 19200
SIMULATION:
OBSERVATIONS:
In the above program, the string stored in 200H location is accessed and it is then serially
transmitted at the baud rate of 19200. The achieve the baud rate of 19200, the (SMOD) 8th bit
of PCON register is set to 1, which enables the divided by 16 circuit instead of divide by 32
circuit. Thus, we send the data at the faster speed.