Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
59 views

Microcontroller

The document contains an 8051 assembly language program written by a student named ashish kumar with registration number 21BEC2017. The program transfers data serially at a baud rate of 19200 by setting the SMOD bit to enable a faster divide ratio. It initializes the serial port and timer registers, then loops through moving each byte of the string "ASHISH" stored in memory location 0200H to the serial output buffer to transmit the data. The transmitted data is observed in the simulator's serial window.

Uploaded by

Clips HUB
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Microcontroller

The document contains an 8051 assembly language program written by a student named ashish kumar with registration number 21BEC2017. The program transfers data serially at a baud rate of 19200 by setting the SMOD bit to enable a faster divide ratio. It initializes the serial port and timer registers, then loops through moving each byte of the string "ASHISH" stored in memory location 0200H to the serial output buffer to transmit the data. The transmitted data is observed in the simulator's serial window.

Uploaded by

Clips HUB
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

NAME : ashish KUMAR

REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

DIGITAL ASSIGNMENT 04

TITLE : SERIAL COMMUNICATION & INTERRUPT

NAME : ashish KUMAR


REGISTRATION NO. : 21BEC2017
SLOT : L33+L34
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS


RETI
END

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

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

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

CJNE A, #31H, TWO ; ASCII 31 = 1


ONE: MOV TH0, #0FEH
MOV TL0, #34H
CPL P1.1
SETB TR0
YY: JNB TF0, YY
CLR TR0
CLR TF0
SJMP ONE

TWO: CJNE A, #32H, THREE


AGAIN: MOV TH0, #0FFH
MOV TL0, #1AH
CPL P1.1
SETB TR0
ZZ: JNB TF0, ZZ
CLR TR0
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS


CLR TF0
SJMP AGAIN

THREE: CJNE A, #33H, XX


AGAIN1: MOV TH0, #0FFH
MOV TL0, #67H
CPL P1.1
SETB TR0
XY: JNB TF0, XY
CLR TR0
CLR TF0
SJMP AGAIN1
END

SIMULATION:
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS


NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

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

MICROPROCESSORS AND MICROCONTROLLERS

QUESTION_02: Assume your name (string of data) is available in ROM address at


200H.Write an 8051 assembly program to transfer data serially at baud rate 19200 with 8 bit
data, one stop bit and observe the transmitted data in the serial window of the simulator.

CALCULATION:
Given, Baud rate = 19200

PROGRAM: ORG 0000H


MOV A,PCON
SETB ACC.7
MOV PCON,A
ZZ: MOV DPTR,#0200H
MOV TMOD,#20H ; Timer 1 Mode 2
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV R1,#09H
YY: CLR A
MOVC A,@A+DPTR
MOV SBUF,A
XX: JNB TI,XX
CLR TI
INC DPTR
DJNZ R1,YY
SJMP ZZ
ORG 0200H
DB ' ASHISH '
END
NAME : ashish KUMAR
REGISTRATION NO. : 21BEC2017

MICROPROCESSORS AND MICROCONTROLLERS

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.

You might also like