ADC (Analog To Digital Conversion)
ADC takes an analog signal, such as an electrical current, and digitize it into a binary format so that the machine can understand it.
Here we have aprogram to interface an ADC with 8051 microcontroller using a simlator.
SETB P2.2
MOV P1,#0FFh
MOV A,#06H
ACALL CMD
ACALL DELAY
MOV A,#0EH
ACALL CMD
ACALL DELAY
MOV A,#38H
ACALL CMD
ACALL DELAY
GO:
ACALL ADCDATA
ACALL HEXTOASCII
ACALL DISPLAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
SJMP GO
ADCDATA: CLR P2.1
SETB P2.1
JB P2.2,$
CLR P2.0
ACALL DELAY
MOV A,P1
SETB P2.0
RET
HEXTOASCII:
MOV B,#10
DIV AB
MOV R5,B
MOV B,#10
DIV AB
MOV R6,B
MOV R7,A
MOV A,R5
ORL A,#30H
MOV R2,A
MOV A,R6
ORL A,#30H
MOV R1,A
MOV A,R7
ORL A,#30H
MOV R0,A
RET
CMD:
MOV P3,A
CLR P2.3
CLR P2.4
SETB P2.5
ACALL DELAY
CLR P2.5
RET
DATA1:
MOV P3,A
SETB P2.3
CLR P2.4
SETB P2.5
ACALL DELAY
CLR P2.5
RET
DELAY:
MOV R4,#0FFH
DJNZ R4,$
MOV R4,#0FFH
DJNZ R4,$
RET
DISPLAY:
MOV A,#01H
ACALL CMD
ACALL DELAY
MOV A,#80H
ACALL CMD
ACALL DELAY
MOV A,R0
ACALL DATA1
MOV A,R1
ACALL DATA1
MOV A,R2
ACALL DATA1
RET
END
No comments:
Post a Comment