; For: 		AT89C4051 @ 11.0592MHz
; Hardware:	INTERFACED WITH ADC0831
; Program goal:	CREATE A DIGITAL VOLTAGE METER
; Assembler:	M-IDE Studio for MCS-51


;place all the usual pre code items here (INTERRUPT VECTORS, ETC)


CS	EQU P3.1     		;CONNECTED TO CS ON ADC0831
CLK	EQU P3.0		;CON TO CLK ON ADC0831
D0	EQU P3.7		;CON TO DO ON ADC0831
;THIS MEANS WE STILL HAVE 1 AVAILABLE PIN LEFT (EXTERNAL INTERRUPT 0, P3.2)

;main
MAIN:	;INITIALIZE
	;INITIALIZE
	;INITIALIZE
	ACALL	ADC0_L
	

;THESE SUBS ARE GOING TO ACTIVATE CHIP, TOGGLE CLOCK, AND GET DIGITAL VALUES STARTED.
ADC0_L:	CLR	CS		;ACTIVATE CHIP
	MOV	R0,#7		;8 BIT COUNTER
	SETB	CLK
	ACALL	GET_D0BYTE

GET_D0BYTE:
	CLR	CLK		;SET LOW
REPEAT:	
        SETB	CLK		;SET HIGH
	CLR	CLK	        ;TOGGLE LOW
	MOV	C,D0		;MOV TO CARRY
	RRC	A
	DJNZ	R0,REPEAT
	JMP	CALCULATE	;GO, CALCULATE VALUE
	

CALCULATE:
	MOV	B,0C4H		;C4 IS 196, WE WANT .0196 BUT THIS WILL DO
	MUL	AB		;STEP VALUE TIMES WHATEVER OUR CHIP STORED IN ACCUMULATOR
	MOV	R1,B		;STORE B FOR A FEW
	;
	; unfinished
END

Hello, This is my first time posting here, I hope I posted this right. Thanks for taking the time to check this out and potentially help me out.

My goal of this program is to use the Atmel AT89C4051 paired with 7 segment led's (connected to port 1, digit selection for digits 0-4 tied to p1.7/p3.5/p3.4/p3.3 respectively), and help from a ADC0831 chip to create a digital volt meter.

I am only looking for 5 volt max reading with thousandths place accuracy (0.000) to be output to the led display. My led code and wiring is fine (not displayed in code), my only issues are with the math and calculations in order to attain the proper voltage values.

From my understanding of this chip I will activate the ADC0831 chip via chip select (active low) and then toggle the clock while reading pin d0. d0 starts after the second clock low, and continues output on each successive low. I handle this by storing the d0 value each time into carry, rotate carry into the accumulator a total of 8 times. Now the value that d0 gives out is essentially the number that should be multiplied by the count, which from the chip will be 5/255, or a step count of 19.6 mV steps.

******
Lets say the value of d0 is 0A8Hex (168decimal). In assembly Im assuming I want to make the step count value 196 or 0C4Hex and multiply the numbers together to get my voltage value (off by a factor of 4). The true value should be .0196*168decimal=3.292Volts and should be displayed on the LED

now here is my problem. I dont quite understand how to multiply by 196 and get my factor of 4 decimal place error to the true value. I have been stuck on this issue for a while and cannot find any help in my 8051 book. Can anyone please show me or lead me in the right direction for this. If you would like to email me feel free, its just my user name at gmail. Thanks for your time.

Never mind, problem solved. I just decided to change the numbers to decimal via divide by factors of 10, etc, and properly truncated and stored the numbers for led that way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.