;William Grill Riverhead Systems 2/24/99 ; c:\upic\diffctl.asm ; ; Difference Controller Provides Display ; USE internal RC, watchdog off, internal master ; clear off and power up timer off PC equ 2 STATUS equ 3 GPIO equ 5 temp equ 20 timer equ 21 ; display timer timer1 equ 22 ; conversion timer disindex equ 23 ; display index pointer rate equ 24 result equ 25 countr equ 26 bits equ 27 #define sign bits,0 #define oldsign bits,4 #define flag bits,1 lastvalue equ 2Bh ADCON0 equ 1F ADRES equ 1E ADCON1 equ 9F ; #define ADdone ADCON0,2 ; a/d done flag #define ADgo ADCON0,2 ; a/d go #define CARRY STATUS,0 #define ZERO STATUS,2 bank0 macro bcf STATUS,5 endm bank1 macro bsf STATUS,5 endm init ; initialize registers, flags and timers movlw 9F option bank1 movlw 6 movwf ADCON1 ; configure for A0 and Vcc as reference bank0 movlw 41 movwf ADCON0 ; (select channel a0,osc/8 bcf ADdone clrf ADRES bank1 clrf ADCON1 bank0 clrf ADRES clrf GPIO clrf bits key5 bsf ADgo ; set AD go, start conversion key3 movlw .25 movwf timer ; initialize both pointers movwf timer1 movwf rate goto key ratelookup ; table of delay times based on deviation addwf PC retlw .190 retlw .160 retlw .130 retlw .100 retlw .70 retlw .40 retlw .30 retlw .20 ; pattern ; display mask table addwf PC retlw 3D ;11 1101 retlw 39 ;11 1001 retlw 29 ;10 1001 retlw 0Bh ;00 1011 retlw 0F ;00 1111 retlw 1F ;01 1111 retlw 3F ;11 1111 key movlw 2 ; (re)load sub delay movwf temp key14 decfsz temp goto key14 decfsz timer1 ; conversion timer is ~3.3ms goto key key1 btfsc ADdone ; confirm conversion is done goto key1 movfw ADRES ; get converted value movwf result xorlw 80 ; test if exactly at mid range btfss ZERO goto key10 movlw 9 ; at mid range then lite all led's goto key7 key10 bcf sign movfw result sublw 7F ; compare to half of reference btfsc CARRY goto key4 ; negative deviation movwf result decf result,w ; result negative xorlw 0FF ; convert deviation to absolute value movwf result ; correct for instance of -128 btfsc result,7 decf result,w bsf sign key4 ; positve error movwf result ; divide deviation difference by 16 rrf result rrf result rrf result rrf result,w andlw 07 call ratelookup ; get rate fronm table movwf result swapf bits,w ; test if direction has changed xorwf bits,w andlw 1 btfss ZERO goto key16 ; sign has changed ; movfw result xorwf rate,w ; test if new rate == old rate btfsc ZERO goto key12 ; no change in direction or value ; provide a filter to reduce dithering at transistions btfsc flag ; confirm 3 conversions over rate threshold goto key18 bsf flag movlw 3 ; initialize dithering counter movwf countr goto key12 key18 decfsz countr goto key12 goto key13 ; key16 movlw 10 ; compliment oldsign bit xorwf bits movfw result ; save new delay time movwf rate goto key15 bcf flag goto key12 key13 bcf flag movfw result ; save new delay time movwf rate key12 decfsz timer ; test if delay == 0 goto key17 key15 movfw rate ; reload timer movwf timer btfsc sign goto key8 incf disindex ; increment display index based on sign key9 movfw disindex ; test for index limits andlw 7 xorlw 7 btfss ZERO goto key11 movlw 6 ; adjust index btfss sign clrw movwf disindex key11 movfw disindex call pattern ; get dispaly pattern goto key7 key8 decf disindex ; decrement dispaly index based on sign goto key9 key7 tris GPIO ; assert mask to outputs key17 bsf ADgo ; set A/D go to start conversion goto key end