0% found this document useful (0 votes)
9 views

MPMC Lab Manual-4

Uploaded by

Deeksha Mekala
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MPMC Lab Manual-4

Uploaded by

Deeksha Mekala
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

16.

7 Segment Display to 8051


Aim: To interface 7 segment display to 8051
Apparatus: 8051 trainer kit, 7 segment display kit
Program:
ORG 000H //initial starting address
START: MOV A,#00001001B // initial value of accumulator
MOV B,A
MOV R0,#0AH //Register R0 initialized as counter which counts from
10 to 0
LABEL: MOV A,B
INC A
MOV B,A
MOVC A,@A+PC // adds the byte in A to the program counters
address
MOV P1,A
ACALL DELAY // calls the delay of the timer
DEC R0 //Counter R0 decremented by 1
MOV A,R0 // R0 moved to accumulator to check if it is zero in next
instruction.
JZ START //Checks accumulator for zero and jumps to START. Done
to check if
counting has been finished.
SJMP LABEL
DB 3FH // digit drive pattern for 0
DB 06H // digit drive pattern for 1
DB 5BH // digit drive pattern for 2
DB 4FH // digit drive pattern for 3
DB 66H // digit drive pattern for 4
DB 6DH // digit drive pattern for 5
DB 7DH // digit drive pattern for 6
DB 07H // digit drive pattern for 7
DB 7FH // digit drive pattern for 8
DB 6FH // digit drive pattern for 9
DELAY: MOV R4,#05H // subroutine for delay
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END
Result: 7 segment display is interfaced with 8051 and executed.
17.MATRIX KEYPAD TO 8051
Aim: To interface Matrix keypad to 8051
Apparatus: 8051 trainer kit, Matrix keypad kit
Program :
CNTRL EQU 2043H

PORTA EQU 2040H

PORTB EQU 2041H

PORTC EQU 2042H

MOV A,#90H

MOV DPTR,#CNTRL

MOVX @DPTR,A

MOV B,#20H

BLINK2 : MOV DPTR,#PORTB

MOV A,#FFH

MOVX@DPTR,A

MOV DPTR,#PORTC

MOV A,#00H

MOVX@DPTR,A

MOV A,#F0H

MOVX@DPTR,A

DJNZ B,BLNK2

BACK: MOV A,#FEH

MOV B,#21H

BLINK1: MOV DPTR,#PORTB

MOVX@DPTR,A

MOV DPTR,#PORTC

MOV A,#00H

MOVX@DPTR,A

MOV A,#F0H

MOVX@DPTR,A

LCALL DELAY
RL A

DJNZ B,BLNK1

SJMP BACK

DELAY: MOV R0,#F7H

OLOOP: MOV R1,#FFH

ILOOP: DJNZ R1,ILOOP

DJNZ R0,OLOOP

RET

Result: Program for interfacing a keyboard to 8051 microcontroller performed.


18.LCD interface to 8051
Aim: To interface LCD to 8051 to display character ‘A’ on LCD display
Apparatus: 8051 trainer kit, LCD kit
Program :
ORG 7850H
START: mov A, #80H ;8255 control word to set all ports as O/P in mode 0
mov DPTR, #CONTROL_ADDR_8255 ; Load 8255 address (Control word
register) in DPTR
movx @DPTR, A ;Send control word to 8255
mov A, #38H ;LCD function set (8bit interface, 2line, 5x7 font)
lcall SendLCDCMD ;Send the command (code in A) to LCD
mov A, #0CH ;LCD on, Cursor off, blink off
lcall SendLCDCMD;Send the command (code in A) to LCD
mov A, #01H ;Clear display and return cursor to home position
lcall SendLCDCMD ;Send the command (code in A) to LCD
mov A, #80H ;LCD DDRAM address set to 1st line 1st char
lcall SendLCDCMD ;Send the command (code in A) to LCD
mov A, #DISP_CHAR ;Get the data to be displayed
lcall SendLCDDAT ;Send the data (in A ) to LCD
LCALL 0006H ;Monitor Return to command position
SendLCDCMD: ;Subroutine start label
mov DPTR, #LCD_DATABUS ;Load 8255 address (PORT B) in DPTR
movx @DPTR, A ;Send data to 8255 port B (LCD data bus).
mov A, #08H ;RS=0 (Command reg), RW=0 (Write mode), EN=1
mov DPTR, #PORTC_8255 ;Load 8255 address (PORT C) in DPTR
movx @DPTR, A ;Send data to 8255 port C.
mov A, #00H ;RS=0 (Command reg), RW=0 (Write mode), EN=0
mov DPTR, #PORTC_8255 ;Load 8255 address ( PORT C) in DPTR
movx @DPTR, A ;Send data to 8255 port C.
;Delay so LCD completes write operation
Mov R1, #100D ;Value loaded for DELAY utility
mov R2, #10D ;Value loaded for DELAY utility
LCALL DELAY ;Implement delay
ret ;End of subroutine
SendLCDDAT: ;Subroutine start
mov DPTR, #LCD_DATABUS ;Load 8255 address (PORT B) in DPTR
movx @DPTR, A ;Send data to 8255 port B (LCD data bus).
mov A, #28H ;RS=1 (Data reg), RW=0 (Write mode), EN=1
mov DPTR, #PORTC_8255 ;Load 8255 address ( PORT C) in DPTR
movx @DPTR, A ;Send data to 8255 port C.
mov A, #20H ;RS=1 (Data reg), RW=0 (Write mode), EN=0
mov DPTR, #PORTC_8255 ;Load 8255 address ( PORT C) in DPTR
movx @DPTR, A ;Send data to 8255 port C
;Delay so LCD completes write operation
mov R1, #01D ;Value loaded for DELAY utility
mov R2, #10D ;Value loaded for DELAY utility
LCALL DELAY ;Implement delay
ret ;End of subroutine
end ;This is end of program

Result: Program is written to display character 'A' continuously on LCD .


19.8-bit ADC Interface to 8051
Aim: To convert analog value to digital using ADC kit interfaced with 8051
Apparatus: 8051 trainer kit, ADC kit
Program :
START: LCALL CRLF ;CLEAR 7-SEG.DISPLAY
MOV A,#81H ;INIT.UPPER 8255 PORT A,B&C(UP.NIBBLE)
MOV DPTR,#UCS55 ;AS O/P & C(LOWER NIBBLE) AS I/P
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#UPB55
MOVX @DPTR,A
MOV A,#09H ;SET PC4 BIT HIGH
MOV DPTR,#UCS55
MOVX @DPTR,A
MOV A,#08H ;RESET PC4 (LATCHED).PULSE FOR ALE
MOVX @DPTR,A ;PIN
MOV A,#83H ;SET PORT B I/P KEEPING REST SAME
MOVX @DPTR,A
JUMP12: MOV DPTR,#UCS55
MOV A,#0DH ;SET PC6 (START CONVERSION)
MOVX @DPTR,A
MOV A,#0CH ;RESET PC6
MOVX @DPTR,A
JUMP11: MOV DPTR,#UPC55
MOVX A,@DPTR
ANL A,#02H ;CHECK IF PC1 IS HIGH
JNB 0E1H,JUMP11 ;IF YES READ DATA.
MOV A,#0BH ;SET O/P ENABLE (OE)=1 (PC5)
MOV DPTR,#UCS55
MOVX @DPTR,A
MOV DPTR,#UPB55 ;READ DIGITAL O/P DATA
MOVX A,@DPTR
MOV R3,A
MOV A,#0AH ;OUTPUT DISABLED PC5=0
MOV DPTR,#UCS55
MOVX @DPTR,A
MOV A,#0DH ;ASCII CODE FOR 'CR'
LCALL WR79 ;ADUST CURSOR POSITION
MOV R5,#02H ;2 DIGITS TO BE OUT & DATA IS
;IN R4R3 REGISTER
LCALL NOUT ;CALL MON.UTILITY TO OUT DATA..
MOV DPTR,#UCS55
LCALL TST79 ;CALL 'TEST' FOR CHECKING ANY
;KEY IS PRESSED.
JNC JUMP12 ;IF KEY NOT PRESSED GO BACK
LJMP CMDMOD ; IF KEY PRESSED.
;---- PERIPHERAL EQUATES --------
280C = UPA55: EQU 280CH
280D = UPB55: EQU 280DH
280E = UPC55: EQU 280EH
280F = UCS55: EQU 280FH
2800 = DTA79: EQU 2800H
2801 = CW79: EQU 2801H
;---- MONITOR UTILITIES EQUATES ---
061D = CRLF: EQU 061DH
062C = WR79: EQU 062CH
059E = NOUT: EQU 059EH
0114 = DELAY: EQU 0114H
045F = RCVN: EQU 045FH
0503 = TST79: EQU 0503H
06D8 = CMDMOD: EQU 06D8H
06DB = CMDWDP: EQU 06DBH

;--- INTERNAL REGISTER ADDRESS EQUATES --


00E0 = A: EQU 0E0H
00F0 = B: EQU 0F0H
0000 = R0: EQU 00H
0001 = R1: EQU 01H
0002 = R2: EQU 02H
0003 = R3: EQU 03H
0004 = R4: EQU 04H
0005 = R5: EQU 05H
0006 = R6: EQU 06H
0007 = R7: EQU 07H
6700 ORG 6700H
Result: Analog value is converted to digital using ADC interfaced with 8051.
20.Triangular Wave Generator through DAC
interfaces to 8051
Aim: To generate a triangular wave through DAC interfaces to 8051
Apparatus: 8051 trainer kit, DAC kit
Program:
ORG 0000H
MOV TMOD,#10H
REPEAT: MOV A,#00H
RISE: MOV P2,A
ACALL DELAY
INC A
CJNE A,#80H,RISE
FALL:DEC A
MOV P2,A
ACALL DELAY
CJNE A,#00H,FALL
SJMP REPEAT
DELAY: MOV TH1,#OFFH
MOV TL1,#0B7
SETB TR1
STAY:JNB TF1,STAY
CLR TR1
CLR TF1
RET
END
Result: Triangular wave is generated using DAC

You might also like