Here the main part of the program, which moves the wiper.

8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


;* Main program - Lets move the wiper

;*	X9C103 pin's connections:
;*
;*	PD3 -> INC (pin1) (wiper movement)
;*	PD4 -> U/D (pin2) (Up or Down mode)
;*	PD5 -> CS  (pin7) (Chip Select)

;* Register variables

	.def	digiPot  = r23		;digipot
	.def	rstWiper = r24		;reset wiper

;* Defines

	.equ	INC = 3			;INC at port D3 (pin7)
	.equ	UD  = 4			;UD  at port D4 (pin8)
	.equ	CS  = 5			;CS  at port D5 (pin9)

;* Code

RESET:
	sbi	DDRD, INC		;Move wiper input
	sbi	DDRD,  UD		;Up / Down select input
	sbi	DDRD,  CS		;Chip Select input
	cbi	PORTD, CS		;Enable X9C103

;* First make wiper position equal to the potmeter's position

	clr	digiPot			;zero
	rcall	potMeter		;read potVal and set wiper position
	ldi	rstWiper, 99		;first wiper to lower end
	cbi	PORTD, UD		;set UD lo (wiper down mode)
	rcall	vshortDelay		;wait 10 usecs
posWip:
	sbi	PORTD, INC		;wiper 1 step lower
	rcall	vshortDelay		;wait 10 usecs
	cbi	PORTD, INC
	rcall	vshortDelay		;wait 10 usecs
	dec	rstWiper		;keep stepping down ->
	brne	posWip			; end reached
	sbi	PORTD, UD		;UD hi (wiper up mode)
	rcall	vshortDelay		;wait 10 usecs
makeEq:
	inc	digiPot			;put wiper 1 step up
	sbi	PORTD, INC
	rcall	vshortDelay		;wait 10 usecs
	cbi	PORTD, INC
	rcall	vshortDelay		;wait 10 usecs
	cp	digiPot, potVal		;if digiPot = potVal ->
	brne	makeEq			; wiper equal to potVal
X9C103:
	rcall	potMeter         	;get potVal (poll potMeter)
	cp	digiPot, potVal
	breq	do_Nothing       	;if digiPot = potVal -> do nothing
	brlo	move_Down        	;if digiPot < potVal -> INC wiper
	dec	digiPot	     		;if digiPot > potVal -> DEC wiper
	sbi	PORTD, UD		;UD hi (wiper up mode)
	rcall	vshortDelay		;wait 10 usecs
	sbi	PORTD, INC		;move wiper 1 position down
	rcall	vshortDelay		;wait 10 usecs
	cbi	PORTD, INC
	rcall	vshortDelay		;wait 10 usecs
	rjmp	do_Nothing		;skip move_Down
move_Down:
	inc	digiPot
	cbi	PORTD, UD		;UD lo (wiper down mode)
	rcall	vshortDelay		;wait 10 usecs
	sbi	PORTD, INC		;move wiper 1 position up
	rcall	vshortDelay		;wait 10 usecs
	cbi	PORTD, INC
	rcall	vshortDelay		;wait 10 usecs
do_Nothing:
        rjmp	X9C103			;keep tracking the wiper

8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


RES (stardate: january 17th 2005)
