• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC0808 with 8051

Status
Not open for further replies.

Wond3rboy

Member
Hi i am working on a little project that i want to submit to my teacher and get it over with.Its based on AT89C51 since i am still working on my Junebug(logistic problems).The problem is that i the ADC is just not converting the analog voltage.The EOC signal just isnt going low at all.

Thanks.

PS: The pins in the uc that are floating dont cause any problems with the simulation thats why i have ignored them.
 

seyed mohammad

New Member
hi,
i send you my own code.but i wrot it for adc0804.
this work very good.
you can try it very easy with a little difference for adc0808.

this code is a temperature reader with lm35 interfaced with adc0804

Code:
ORG 00H
/***************/
TABDIL EQU P3.0         /*WRITE*/
INT    EQU P3.1         /*PAYANE TABDIL*/
READ   EQU P3.2         /*READ*/

RS     EQU P3.4
RW     EQU P3.5
E      EQU P3.6
/***************/
MOV  P2,#38H
CALL COM
CALL DELAY
MOV  P2,#38H
CALL COM
CALL DELAY
MOV  P2,#38H
CALL COM
CALL DELAY
/***************/
MOV  P2,#1H
CALL COM               /*COMAND*/
CALL DELAY

MOV  P2,#0CH
CALL COM
CALL DELAY

MOV  P2,#83H
CALL COM
CALL DELAY

MOV  A,#'T'
CALL DAT               /*DATA*/
CALL READY             /*IS LCD READY?*/

MOV  P2,#84H
CALL COM
CALL DELAY

MOV  A,#'E'
CALL DAT
CALL READY

MOV  P2,#85H
CALL COM
CALL DELAY

MOV  A,#'M'
CALL DAT
CALL READY

MOV  P2,#86H
CALL COM
CALL DELAY

MOV  A,#'P'
CALL DAT
CALL READY

MOV  P2,#87H
CALL COM
CALL DELAY

MOV  A,#' '
CALL DAT
CALL READY

MOV  P2,#88H
CALL COM
CALL DELAY

MOV  A,#'I'
CALL DAT
CALL READY

MOV  P2,#89H
CALL COM
CALL DELAY

MOV  A,#'S'
CALL DAT
CALL READY

MOV  P2,#8AH
CALL COM
CALL DELAY

MOV  A,#':'
CALL DAT
CALL READY

/***************/
MOV   P1,#0FFH            /*MAKE P1 AN INPUT PORT*/
BACK:
CLR   TABDIL              /* SHOROE TABDIL ADC*/
SETB  TABDIL
HERE: JB INT,HERE         /*CHEKING THE P3.1*/
CLR   READ
CALL  CONVERSION          /*TABDILE BINERY BE DECIMAL VA SEPAS ASC*/
SETB  READ
SJMP  BACK
/***************/
CONVERSION:

/*TAGHSIM BAR 10 */

MOV  A,P1
MOV  B,#10D
DIV  AB
MOV  R0,B                 /* YEKAN DARONE R0*/
MOV  B,#10
DIV  AB
MOV  R1,B                 /*DAHGAN DARONE R1*/
MOV  R2,A                 /*SADGAN DARONE R2*/

/******ASC******/

MOV  A,#30H
ORL  A,R2             /* OR 30H WITH R2 FOR CREATING ASC AND SAVE
                            IN ACCOMULATOR */
MOV  P2,#8BH          /*MAKANIKE ROYE LCD MIKHAHIM SADGAN NESHON BEDIM*/
CALL COM
CALL DELAY
CALL DAT
CALL READY

MOV  A,#30H
ORL  A,R1
MOV  P2,#8CH    /*MAKANIKE ROYE LCD MIKHAHIM DAHGAN NESHON BEDIM*/
CALL COM
CALL DELAY
CALL DAT
CALL READY

MOV  A,#30H
ORL  A,R0
MOV  P2,#8DH     /*MAKANIKE ROYE LCD MIKHAHIM YEKAN NESHON BEDIM*/
CALL COM
CALL DELAY
CALL DAT
CALL READY

RET
/***************/
COM:

CLR  RS
CLR  RW
SETB E
CLR  E

RET

/***************/
DAT:

MOV P2,A
SETB RS
CLR  RW
SETB E
CLR  E

RET
/***************/
READY:

CLR  RS
SETB RW
BOB:
SETB E
CLR  E
JB   P2.7,BOB

RET
/***************/

DELAY:

        MOV R3,#50
DOBARE: MOV R4,#255
SEBARE: DJNZ R4,SEBARE
        DJNZ R3,DOBARE
RET
/***************/
END
 
Last edited by a moderator:

Wond3rboy

Member
Thanks for your reply but i dont have any problems with the code.The only problem i face is that i cant seem to give the clock signal correctly to the ADC.
 

seyed mohammad

New Member
i think you must connect the wire of CKA to the XTAL2.
and you must know the input frequncy of the ADC0808 is finit and you cant give it high frequncy other than it work.
so you must chose a write Crystal for micro.
 

Wond3rboy

Member
Code:
    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
	MYDATA	EQU P1
	ORG	0H
	MOV	MYDATA,#0FFH	
	SETB	EOC     	
	CLR	ALE    	
	CLR	SC    	
	CLR	OE       	
BACK:
	CLR	ADDR_C  	
	CLR	ADDR_B   	
	SETB	ADDR_A  	
	ACALL	DELAY    	
	SETB	ALE   	
	ACALL	DELAY  	
	SETB	SC     	
	ACALL	DELAY
	CLR	ALE
	CLR	SC
HERE3: 
	JB	EOC, HERE3 	
HERE1: 
	JNB	EOC, HERE1 	
	SETB	OE     	
	ACALL	DELAY  	
	MOV	A,MYDATA  	
	CLR	OE        	
	mov p3,a	
	SJMP	BACK    

DELAY:	MOV	R3,#250 		
HERE2:	MOV	R4,#255		
HERE: 	DJNZ	R4,HERE 		
     	DJNZ	R3,HERE2
      	RET
end
This is the code that i am using.I dont expect any one to find any errors since it is an example code of a book(8051 Microcontrollers and Embedded Systems by Mazidi). The only thing i changed was to display the converted data on Port 3 instead of diplaying it on LCD.I just wanted to see if it worked.

About your clock advise, the datasheet says that the ADC can take a maximum clock of 1.2Mhz and after the decade counter its 1.10592Mhz so theorictically it shouldnt be a problem.
 
Last edited:

Wond3rboy

Member
Movx is used when you want to access external memory.This is an ADC.It goes for addresses and all,here is just need to get data in from a PORT.There is no onboard ADC memory accessing.

ALE is acutally P2.4 its just a label.
 
Last edited:

Hayato

Member
When you use MOVX A,@DPTR the 8051 will automatically send an Addres through P0 and P2, then will change ALE and then PSEN or RD. After that it will acquire data from P0.

So you can connect your ADC OUTPUT BUS to P0, Output Enable to #RD, and P2 to your 8080 address bits.

The address you move to DPH.
And you'll have to invert the 8080 Output Enable, because #RD goes low when the 8051 stats acquiring the data.
 

naveencali

New Member
Hello Wond3rBoy

U do this correction first
-------------------------------------------
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
MYDATA EQU P1
ORG 0H
MOV MYDATA,#0FFH
SETB EOC
CLR ALE
CLR SC
CLR OE replace it by SETB OE
BACK:
.............
.............
.............
-------------------------------------------------------


Now check and say whether Ur problem is solved or not

NaveenCali
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top