8051_ADC
This project shows how the voltages of different channels of an ADC can be displayed using 8051. To simulate circuit in this project, initially activate Mixed Mode simulator from the Schematic Editor window. Simulation can be performed by selecting Run Transient analysis (Oscillograph) from Simulation menu.
The circuit contains an 8051 chip, 8-Bit Microprocessor Compatible ADC with 8-Channel Multiplexer, Voltage Sources, BCD to 7 Segment Decoder and Seven-Segment LED Display. In this circuit Port P1 of 8051 is used as the input port while the ports P0 and P2 are connected to the BCD to 7 Segment Decoders.
To each channel of the ADC, a voltage source is attached. Apart from clock, ADC should receive Address Latch Enable (ALE) signal from 8051 to fetch data from any one of the 8 channels. The three address lines of the ADC (i.e. AD0, AD1 and AD2) are used for channel selection.
After ALE signal is received, depending upon the value of the three address lines, the voltage from the corresponding channel will be taken. This analog data is converted to digital mode (ratiometric form) only if ADC receives Start Conversion (START) signal from 8051. Once the conversion is complete, End of Conversion (EOC) bit will undergo a 'Low to High’ transition and will be sent to 8051 from ADC. At the instant the EOC signal is received by 8051, an Output Enable (OE) signal is sent to ADC to make converted data available at the output lines.
The digital data will then appear at Port P1 of 8051. This ratiometric data is converted to BCD form, which is equivalent to the analog voltage supplied at the input channel of ADC. This BCD data is then send to the BCD to 7-Segment Decoders and the output appears in
7-Segment form.
The first 7-Segment display shows the channel number while the second display shows the voltage of that particular channel.
The program is as shown:
repeat:
mov r1,#0x08 ; Register 'R1' is loaded with hex value '08'
mov p0,#0x00 ; Port P0 is initialised with hex value '00'
$rep:
lcall conv ; Calling function 'conv'
inc P0 ; Incrementing port P0 by one
djnz r1,$rep ; Decrement register 'R1' by one and checks whether it is zero or not. If not, jumps to label ‘$rep’.
ljmp repeat ; Jumps to label 'repeat'.
; Start conversion
conv:
clr p3.0 ; Clear P3.0 to make ALE low
setb p3.2 ; Set P3.2 high to make EOC high
clr p3.1 ; Clear P3.1 to make START low
clr p3.3 ; Clear P3.3, to make OE low
mov p1,#0x0ff ; Port 1 is initialised to 'FF', to make it an input port
setb p3.0 ; Set P3.0 high to make a small pulse on ALE pin
setb p3.1 ; Set P3.1 high for getting a small pulse on START pin
clr p3.0 ; P3.0 is cleared to make ALE low
clr p3.1 ; P3.1 is cleared to make START low
mov r0,#0x20 ; R0 is initialised with hex value '20'
loop:
djnz r0,loop ; Decrement ‘R0’ by one and checks whether it is '0' or not. If not, jumps to label ‘loop’
; This counting operation is just to make some delay.
rep:
jnb p3.2,rep ; Checks whether bit P3.2(EOC) is set or not. If not, jumps to label 'rep'
setb p3.3 ; If EOC is set, set P3.3(OE), to make the output available at the output pins.
mov a,p1 ; The output of ADC which is available at port 1, is copied to Accumulator
; Conversion back
mov b,#51 ; Register 'B' is initialised with value '51'
div ab ; Divide a by b, Quotient will be available in Accumulator and remainder in register ‘B’
mov p2,a ; Quotient, which is available in Accumulator is copied to Port 2
clr p3.7 ; To enable decoder, clear P3.7, which is externally connected to the 'LE' pin of decoder.
mov r0,#0x0ff ; R0 is initialised to '255'
loop1:
djnz r0,loop1 ; Decrement R0 by one and checks whether it is '0' or not. If not jumps to label ‘loop1’
mov r0,#0x0ff ; R0 is initialised to '255'
loop2:
djnz r0,loop2 ; Decrement R0 by one and checks whether it is '0' or not. If not jumps to label ‘loop2’
The source code in the
code editor window
has to be
compiled
after making any modifications
(editing).
Also the code can be
debugged
during
simulation.