Professional Documents
Culture Documents
AIM/OBJECTIVE:
To verify the analog to digital conversion as well as digital to analog conversion of both DC supply and Sinusoidal
supply using ADC 0808 and DAC 0808.
EQUIPMENT REQUIRED:
SOFTWARE USED:
SUMMARY ON DATASHEET:
ADC 0808: The ADC0808 is a data acquisition component device with a 8 bit analog to digital converter, 8 channel
multiplexer compatible with 8051 microcontroller. It uses successive approximation as the conversion technique.
The maximum supply voltage should not exceed 6.5V and the maximum voltage at individual pins should not
exceed -0.3V to Vcc+0.3V. Storage temperature should not exceed more than 150 degrees Celsius. Operating
temperature range is from -40 degree Celsius to 85 degrees Celsius. Range of Vcc is from 4.5Vdc to 6.0Vdc.
DAC 0808: This 8-bit IC converts a digital signal to an analog signal. The power supply voltage range varies from
+-4.5V to +-18V. Operating temperature is 0 to 75 degrees Celsius. Output current range is between 2.1mA to
4.2mA.
THEORY:
ADC 0808 has 8 bit input channel and 8 output bits. Therefore we get a resolution of (1/2 8) from this chip. There are
3 separate channel selection pins to select a particular signal for conversion. Hence, at a time 8 signals can be
connected to the IC for conversion. Apart from the input channels, input channel selectors and output pins, there are
4 main important pins; SC (Start conversion), EOC (End of conversion), OE(Output Enable) and ALE(Address
Latch Enable).
The steps for conversion are as follows. Firstly, the ALE pin is an important pin as it is used to latch the input
channel address after it undergoes a low to high transition. After the ALE pin is set, SC pin is given a high pulse. By
1 | Page
the time conversion starts, ALE pin is rest again. After the start of conversion, EOC pin is continuously monitored to
check if it goes low. Going Low means end of conversion and the output is ready to be read by the microcontroller.
A proper delay is given till the EOC pin gets set again so that it can block other data in line before the current data
gets read. Now, the OE pin is given low to high transition to read the output data and hence the conversion gets
completed and the cycle repeats itself.
Figure 1 : Timing Diagram for ADC
2 | Page
PROCEDURE:
Proteus ISIS software was started and a new project was started.
3 | Page
Components like ADC 0808, DAC0808, resistors, capacitors, OpAmps, LED and oscilloscope were
connected.
The code was embedded in the microcontroller and connections were made between ADC, DAC and
8051uC.
Sinusoidal supply was given at channel 1V DC at channel 7, 2.5V DC at channel 4 and 5V DC at channel 0
PROGRAM:
ALE
BIT P2.4
OE
BIT P2.5
SC
BIT P2.6
EOC
BIT P2.7
ADDR_A
BIT P2.0
ADDR_B
BIT P2.1
ADDR_C
BIT P2.2
CLK_PIN
BIT P2.3
EQU
P1
RESET:
ORG 0H
; RESET ISR
LJMP INITIALIZE
ORG 0BH;
TIMER0 ISR
CPL CLK_PIN ;complement the clock generator pin
RETI
; return control from the interrupt to continue with the next instruction
INITIALIZE:
ORG
50H
MOV
DATAPORT,#0FFH
SETB SWITCH_PIN
4 | Page
; SKIP the interrupt vector table ,which extends till 23h for 8051
JNB
SWITCH_PIN,ENABLE_INTERRUPT_CLK
TIMER0 INTERRUPT ELSE MANUAL CLK
GUEST_LOGIN:MOV DPTR,#GUESTNAME
ACALL MATCH_TEXT
JZ LOGINERROR
MOV DPTR,#ASKPASS
ACALL SEND_LINE
ACALL RCV_LINE
MOV DPTR,#GUESTPW
5 | Page
CREDITS
ACALL MATCH_TEXT
JNZ MAIN
LOGINERROR:MOV A,#13
ACALL SEND_CHAR
MOV DPTR,#LOGINFAILED
ACALL SEND_LINE
SJMP USER_LOGIN;ACALL CONVERT_NUMBER_TO_CHARS_AND_SEND
MAIN:
MOV A,#13
ACALL SEND_CHAR
MOV DPTR,#AUTHOR
ACALL SEND_LINE
MAIN_LOOP:
; fetching the channel to read from the terminal
MOV DPTR,#SEL_CH_TEXT
ACALL SEND_LINE
ACALL RCV_CHAR
ACALL SEND_CHAR
MOV
R0,A
MOV A,#13
;move the received char into r0 while a still holds the received char
;load a with ascii of carriage return i.e 13
ACALL SEND_CHAR
MOV DPTR,#ENTERED_CH_TEXT
ACALL SEND_LINE
;setting the channel address
MOV A,R0
;NOTE THAT R0 CONTAINS THE ASCII VALUE OF THE CHANNEL NUMBER
(ex: if channel selected is 0[or say x(0<x<9)] ,then R0 = 48[or 48+x])
CLR C ; THIS IS NEEDED AS IF CARRYFLAG IS SET , THE FINAL ANSWER IS
SUBTRACTED BY ONE(i.e A - X(the no. that is being subtracted) - 1)
6 | Page
SUBB A,#'0' ;get the register A to get the numeric value of the channel selected . IE
SUBTRACT '0'(OR ASCII '48) FROM IT
ACALL SET_ADC_ADDR
AC_READ:ACALL READ_ADC
; at this point we have the ADC value in the Accumulator A , so we just send it to the
terminal but after converting its
; digits into the corresponding characters
ACALL CONVERT_NUMBER_TO_CHARS_AND_SEND
;WAIT_X:SJMP WAIT_X
SJMP MAIN_LOOP
//SJMP AC_READ
CONVERT_NUMBER_TO_CHARS_AND_SEND:
;MOV R0,A
;MAKE SURE THAT R0 IS NOT IN USE BY THIS TIME AND THAT A
CONTAINS THE NUMBER TO BE CONVERTED AND SENT // STORE THE VALUE OF A IN R0 FOR
FURTHER USE
MOV B,#100
DIV AB ; QUOTIENT IN A AND REMAINDER IN B , at this point A contains the
hundredth place's FACE value and B the remainder
7 | Page
ADD A,#'0'
CHARACTER
ACALL SEND_CHAR ; SEND THE hundredth place's faceValue(quotient) to
terminal(i>e the quotient, which is present in A at this point of time.)
MOV A,#13
ACALL SEND_CHAR
ACALL SEND_CHAR
RET
SET_ADC_ADDR:
MOV P2,A
; Re-initialise the control pins on port2 like EOC,ALE,SC and oc as they might have
been overwritten by the above statement
SETB
EOC
CLR
ALE
CLR
8 | Page
SC
CLR
OE
; Re-initialisation complete
ACALL DELAY
ACALL GEN_CLK_MANUALLY
RET
READ_ADC:
SETB
ALE
ACALL DELAY
SETB
SC
ACALL DELAY
CLR
ALE
CLR
SC
CJNE R7,#0,BYPASS2MAN_GEN
ELSE CALL GEN_CKL_MANUALLY
WAIT2EOC_LOW:JB
EOC, WAIT2EOC_LOW
WAIT2EOC_HIGH:JNB EOC,WAIT2EOC_HIGH
SJMP BYPASS2OUTPUT
BYPASS2MAN_GEN:ACALL
GEN_CLK_MANUALLY
BYPASS2OUTPUT:SETB
OE
ACALL DELAY
MOV
A,DATAPORT
;CLR
OE
END
RET
9 | Page
; CLEAR IT TO UNLATCH THE ADC DATA FROM THE OUT PORT AT THE
DELAY:
MOV
R3,#255
HERE2DELAY:
NOP
NOP
NOP
NOP
NOP
DJNZ
R3,HERE2DELAY
RET
DELAY2:
MOV
R2,#100
HERE2DELAY2:
ACALL DELAY
DJNZ
R2,HERE2DELAY2
RET
SETUP_SER_AND_CLOCK_GEN:
MOV TMOD,#22H ;TIMER1 MODE2(for serial) and TIMER0 MODE2(auto-reload
mode for generating clock of ~10KHz for ADC 0808)
SETB TR1
CLR RI ; clear RI for the 1st reception
10 | P a g e
; SET TIMER0 CONFIG.(used for timer interrupt to generate ~10KHz for ADC
0808)
; TAKE 11.0592MHZ APPROX(XTAL) = 12 MHz
; CLOCK FOR TIMERx = XTAL/12 = 12MHz/12 = 1MHz
; DIVIDING FACTOR = 1MHz / 10 KHz = 100
; SO WE NEED TO HAVE ONE CLOCK CYCLE (i.e one squarewave ) IN 100
CLOCK CYCLES OF TIMER0
; IN ONE CLOCK CYCLE(i.e one squarewave) , WE NEED TO TOGGLE a PIN
TWICE TO GENERATE THE COMPLETE SQAUREWAVE
; SO WE MUST TOGGLE THE PIN IN EVERY 50 CLOCK CYCLES OF TIMER0
; VALUE TO BE LOADED INTO TH0(WHICH AUTO-RELOADS TL0) = 256 - 50 =
206(alternatively we can give -50)
MOV
TH0,#-50
BYPASS_SSACG:RET
GEN_CLK_MANUALLY:
MOV R6,254
127) CLK PULSES
;GENERATE 127(2 loops for one clOCK pulse < hence 254/2 =
REPEAT_CLK:MOV TH0,#-50
SETB TR0
WAIT2TIMER0FLAG:JNB TF0,WAIT2TIMER0FLAG
CLR TF0;CLEAR TIMER0 OVERFLOW FLAG
CPL CLK_PIN ; TOGGLE CLOCK PIN
11 | P a g e
DJNZ R6,REPEAT_CLK
RET
SEND_CHAR:
MOV SBUF,A
WAIT2SEND:JNB TI,WAIT2SEND
CLR TI
RET
RCV_CHAR:
WAIT2RCV:JNB RI,WAIT2RCV
MOV A,SBUF
CLR RI
RET
SEND_LINE:
CLR A
MOVC A,@A+DPTR
ACALL SEND_CHAR
INC
DPTR
JNZ SEND_LINE
RET
;SEL_CH:
;MOV DPTR,#SEL_CH_TEXT
;ACALL SEND_LINE
;RET
RCV_LINE:
12 | P a g e
MOV R1,#30H; RAM locations 30H to 7FH(total = 7FH - 30H = 4FH = 79 bytes)
are available as places to save byte sized data
;ONLY R1 AND R0 CAN BE USED AS POINTERS , AS WE
HAVE ALREADY USED R0 , HERE WE USE R1 FOR BEING ON THE SAFE SIDE
RCV_AGAIN:ACALL RCV_CHAR
CJNE A,#13,STORE_CHAR
;IF ENTER IS HIT(I.E WE RECEIVE CARRIAGE
RETURN or ASCII 13) , THEN EXIT ELSE STORE THE CHAR
MOV @R1,#0 ; PUT NULL CHARACTER IN THE LOCATION
RET
STORE_CHAR:MOV @R1,A
INC R1
CJNE R1,#80H,RCV_AGAIN
AS IT CONTAINS SFRs
RET
PRINT_FROM_RAM:
MOV R1,#30H; RAM locations 30H to 7FH(total = 7FH - 30H = 4FH = 79 bytes)
are available as places to save byte sized data
;ONLY R1 AND R0 CAN BE USED AS POINTERS , AS WE
HAVE ALREADY USED R0 , HERE WE USE R1 FOR BEING ON THE SAFE SIDE
PRINT_AGAIN:MOV A,@R1
JNZ PRINT_CHAR
AS IT INDICATES END OF STRING
RET
PRINT_CHAR:ACALL SEND_CHAR
INC R1
CJNE R1,#80H,PRINT_AGAIN ;WE MUST NOT GO BEYOND RAM ADDRESS 7FH
AS IT CONTAINS SFRs
RET
MATCH_TEXT:
13 | P a g e
MOV R1,#30H; RAM locations 30H to 7FH(total = 7FH - 30H = 4FH = 79 bytes)
are available as places to save byte sized data
;ONLY R1 AND R0 CAN BE USED AS POINTERS , AS WE
HAVE ALREADY USED R0 , HERE WE USE R1 FOR BEING ON THE SAFE SIDE
;MOV DPTR,#SCREWIT
COMPARE:CLR A
MOVC A,@A+DPTR
JZ MATCH_PASSED
MOV R5,A
MOV A,@R1
CJNE A,05H,MATCH_FAILED ; WE CANT PASS "R5" TO CJNE BUT WE CAN PASS
ITS ADDRESS WHICH IS 05H
INC DPTR
INC R1
SJMP COMPARE
MATCH_PASSED:MOV A,#1
RET
MATCH_FAILED:MOV A,#0
RET
CREDITS_TEXT : DB "||rourkela|National Institute Of Technology|| -> isasense",13,13,0
SEL_CH_TEXT : DB "Select ADC Channel: ",0 ; CARRIAGE RETURN ASCII=13
ENTERED_CH_TEXT : DB "Channel ADC Reading: ",0
END
RESULTS:
Circuit:
14 | P a g e
15 | P a g e
When DC excited
Figure 7: DC output
CONCLUSION:
16 | P a g e
A DC as well as Sinusoidal input signal was successfully converted to a digital output using a ADC0808 chip. The
result was verified using a virtual oscilloscope, The output from the ADC was taken as an input for the DAC and it
was verified that a corresponding Analog signal was obtained at the output of a DAC chip.
17 | P a g e