augustinetez
Active Member
OK, thanks Mike, I'll give it a try shortly.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
main
;////////////////////////////////////////////////////////////////////////////////
rlf previous,f
rlf previous,w
andlw 0x0c ;keep only bits 2 & 3
btfss PORTA,0 ;move encoder bits
iorlw 1 ;to bits 0 & 1
btfss PORTA,1
iorlw 2
movwf previous ;keep for next time
call enc_table
addlw 0x00
btfsc STATUS,Z
goto main
xorlw 1
btfsc STATUS,Z
goto up
;////////////////////////////////////////////////////////////////////////////////
; Based on the knob direction, either increment or decrement the frequency,
; update the LCD and SAA1057.
;
down
call dec_freq ;
goto update ; Update LCD
up
call inc_freq ;
update
call bin2BCD ; Convert the frequency to BCD
movlw 3
call wait
movlw 0xc5
call cmnd2LCD
call show_freq ; Display the frequency on the LCD
; call send_word ; Send the control word to the chip
goto main ; Continue main loop
call cmnd2LCD
call show_freq ; Display the frequency on the LCD
show_freq
movlw 0xC5 ; Point the LCD to digit location
call cmnd2LCD ; Send digit location to LCD
;
movfw TenK
addlw 0x00 ; Test if 'w'is 0 or 1
btfss STATUS,Z ; The Z or Zero bit is set to "1" when the result
goto $+4 ; of an arithmetic or logical operation is zero
movlw ' ' ; TenK = 0, insert space
call data2LCD ; Send byte in W to LCD
goto $+2
; movfw TenK ; TenK is not 0, insert number
call process ;
movfw Thou
rlf previous,f
rlf previous,w
andlw 0x0c ;keep only bits 2 & 3
btfss PORTA,0 ;move encoder bits
iorlw 1 ;to bits 0 & 1
btfss PORTA,1
iorlw 2
movwf previous ;keep for next time
call enc_table
addwf clicks,f
movlw 4
xorwf clicks,w
btfsc STATUS,Z
goto up
movlw 0xfc ;-4
xorwf clicks,w
btfsc STATUS,Z
goto down
goto main
;////////////////////////////////////////////////////////////////////////////////
; Based on the knob direction, either increment or decrement the frequency,
; update the LCD and SAA1057.
;
down
clrf clicks
call dec_freq ;
goto update ; Update LCD
up
clrf clicks
call inc_freq ;
;
; The current sample is AC.
; The previous sample is ac.
;
; Clockwise direction:
; c = a XOR b
; ab ac AC AC-ac
; 00 00 01 01
; 01 01 10 01
; 11 10 11 01
; 10 11 00 01
;
; Counter Clockwise direction:
; c = a XOR b
; ab ac AC AC-ac
; 00 00 11 11
; 10 11 10 11
; 11 10 01 11
; 01 01 00 11
;
;
; RA1 = A , RA0 = B
;
Temp EQU 0x70
Last_AC EQU 0x71
;
QuadCheck:
movf PORTA,W ; Sample rotary dial
andlw 3 ; mask for bits AB
movwf Temp ; Save for later
rrf Temp,F ; Shift for XOR of A with B
xorwf Temp,W ; Change 2-bit Gray code to binary
xorwf Last_AC,W ; Use three XORs to swap the
xorwf Last_AC,F ; current sample with
xorwf Last_AC,W ; the last sample.
subwf Last_AC,W ; Calculate the difference (Current-Last)
andlw 3 ; W = 01 for CW step, W = 11 for CCW step
xorlw 1 ; Test for Clockwise step
btfsc STATUS,Z ; skip if not CW step
retlw +1
xorlw 2 ; Test for Counter Clockwise step
btfsc STATUS,Z ; skip if not CCW step
retlw -1
retlw 0
;note W_TEMP and STATUS_TEMP need to be in the common area (above 0x70)
ISR MOVWF W_TEMP ; SAVE OFF CURRENT W REGISTER CONTENTS
MOVF STATUS,W ; MOVE STATUS REGISTER INTO W REGISTER
MOVWF STATUS_TEMP ; SAVE OFF CONTENTS OF STATUS REGISTER
BCF STATUS,RP0
BCF PIR1,TMR2IF
RLF previous,F
RLF previous,W
ANDLW 0X0C ;KEEP ONLY BITS 2 & 3
BTFSS PORTA,0 ;MOVE ENCODER BITS
IORLW 1 ;TO BITS 0 & 1
BTFSS PORTA,1
IORLW 2
MOVWF previous ;KEEP FOR NEXT TIME
CALL ENC_TABLE
ADDWF clicks,F
MOVLW 4
XORWF clicks,W
BTFSS STATUS,Z
GOTO CHECK_DOWN
CLRF clicks ;added this line
MOVLW high 10800 ;test if frequency has reached 108MHz
XORWF freqHigh,W
BTFSS STATUS,Z
GOTO DOINC ;high bytes don't match so do increment
MOVLW low 10800
XORWF freqLow,W
BTFSC STATUS,Z ;low bytes don't match so do increment
GOTO EXIT ;if it has, exit
DOINC INCF freqHigh,F ;if not then increment it
INCFSZ freqLow,F
DECF freqHigh,F
GOTO EXIT
CHECK_DOWN
MOVLW 0XFC ;-4
XORWF clicks,W
BTFSC STATUS,Z
GOTO EXIT
CLRF clicks ;added this line
MOVLW high 8700
XORWF freqHigh,W
BTFSS STATUS,Z
GOTO DODEC
MOVLW low 8700
XORWF freqLow,W
BTFSC STATUS,Z
GOTO EXIT
DODEC MOVF freqLow,F
SKPNZ
DECF freqHigh,F
DECF freqLow,F
GOTO EXIT
; RESTORE CONTEXT BEFORE RETURNING FROM INTERRUPT
EXIT MOVF STATUS_TEMP,W ; RETRIEVE COPY OF STATUS REGISTER
MOVWF STATUS ; RESTORE PRE-ISR STATUS REGISTER CONTENTS
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; RESTORE PRE-ISR W REGISTER CONTENTS
RETFIE ; RETURN FROM INTERRUPT
initTmr2
;using internal 4MHz clock = 1MHz instruction time
;prescaler = 4 = clocked at 250kHz
;PR2 = 249 will clock around every 250 cycles
;postscaler = 5 = clock every 250*4*5 = 5000 cycles = 5mS interrupt
MOVLW 0B00100101
MOVWF T2CON
BSF STATUS,RP0
MOVLW 249
MOVWF PR2
BSF PIE1,TMR2IE
BCF STATUS,RP0
BSF STATUS,PEIE
BSF STATUS,GIE
RETURN
GETfreq BCF STATUS,GIE
MOVFW freqLow
MOVWF freq_0
MOVFW freqHigh
MOVWF freq_1
BSF STATUS,GIE
RETURN
SETfreq BCF STATUS,GIE
MOVFW freq_0
MOVWF freqLow
MOVFW freq_1
MOVWF freqHigh
BSF STATUS,GIE
RETURN
ORG 4
GOTO ISR