CPE-342 MSI
LAB # 9
To interface an Analogue to Digital Converter (ADC) with 8051 MCU using
Assembly Language programming
Name Asad Rehan
Registration No# FA17-BCE-005
Batch FA17-BCE-A
Instructor’s Name Sir Usman Rafique
Objectives :
• To explain the interfacing of ADC0804 with the AT89C51 MCU using PROTEUS.
• To interface an Analogue to Digital Converter (ADC) with 8051 MCU using Assembly
Language programming
Lab Tasks:
TASK 1:
Create an assembly language program the converts the analog voltage into digital value and
displays it on LED bar display
Code:
ADC_WR EQU P2.0
ADC_RD EQU P2.1
ADC_INT EQU P2.2
LED EQU P1
ADC EQU P3
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
CALL DELAY
CALL CONVERT ;RESULT IS IN A
MOV LED, A ;WRITE RESULT TO BAR DISPLAY
JMP MAIN
CONVERT:
SETB ADC_WR
SETB ADC_RD
NOP
CLR ADC_WR
NOP
SETB ADC_WR
JB ADC_INT,$ ;POLL FOR INTR = 0
CLR ADC_RD
NOP
MOV A, ADC ;READ ADC PORT IN A
SETB ADC_RD
RET
;SUBROUTINE GENERATES SOME DELAY
DELAY:
MOV R1, 250
LOOP1:
MOV R0, #0FFH
DJNZ R0, $
MOV R0, #0FFH
DJNZ R0, $
MOV R0, #0FFH
DJNZ R0, $
MOV R0, #0FFH
DJNZ R0, $
DJNZ R1, LOOP1
RET
END
Proteus Simulation:
TASK 2:
Code:
ADC_WR EQU P2.0
ADC_RD EQU P2.1
ADC_INT EQU P2.2
LED EQU P1
ADC EQU P3
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
CALL DELAY
CALL CONVERT ;RESULT IS IN A
CJNE A,#150,LEDOFF
JMP LEDON
JMP MAIN
CONVERT:
SETB ADC_WR
SETB ADC_RD
NOP
CLR ADC_WR
NOP
SETB ADC_WR
JB ADC_INT,$ ;POLL FOR INTR = 0
CLR ADC_RD
NOP
MOV A, ADC ;READ ADC PORT IN A
SETB ADC_RD
RET
;SUBROUTINE GENERATES SOME DELAY
LEDOFF:
MOV LED, #0FFH ;WRITE RESULT TO BAR DISPLAY
LEDON:
MOV LED, #00H ;WRITE RESULT TO BAR DISPLAY
DELAY:
MOV R1, 250
LOOP1:
MOV R0, #0FFH
DJNZ R0, $
MOV R0, #0FFH
DJNZ R0, $
MOV R0, #0FFH
DJNZ R0, $
MOV R0, #0FFH
DJNZ R0, $
DJNZ R1, LOOP1
RET
END
Conclusion:
This lab experiment proved to be crucially helpful in understanding basic concepts of different
scenarios related to this specific microcontroller and so with the help of proteus and different simulation
softwares, this purpose was achieved.