techristian
Member level 1
- Joined
- Apr 3, 2013
- Messages
- 41
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Windsor, Ontario
- Activity points
- 1,612
When I worked with 6502 I could use an INDEX REGISTER to load the working register with a value.
With the PIC16F178X instruction set this doesn't seem to exist. Instead I'm trying to resort to the BRW command to offset my branch. I'm getting close but some junk characters are being displayed and it is skipping numbers.
The NUMBER is supposed to be displayed.
Here is my code, and I'm sure there is a simpler way to implement a LOOKUP TABLE with PIC.
Code:
LDA TABLE,X
With the PIC16F178X instruction set this doesn't seem to exist. Instead I'm trying to resort to the BRW command to offset my branch. I'm getting close but some junk characters are being displayed and it is skipping numbers.
The NUMBER is supposed to be displayed.
Here is my code, and I'm sure there is a simpler way to implement a LOOKUP TABLE with PIC.
Code:
#include <p16f1784.inc>
;CONFIG1
; __config 0x3FE4
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
; CONFIG2
; __config 0x3FFF
__CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_ON
delay equ 0x7e
BIGdelay equ 0x7f
NUMBER equ 0x7c ; if over 80h or greater next bank
temp equ 0x7d
org 0x0000
goto start
org 0x004
goto dummyINT
start movlw b'00000000' ;MOVE ZERO TO ACC "W"orking register
movwf NUMBER
movwf temp
BANKSEL 1
TRIS 7 ;since 0 in w register then porta and portc outputs
TRIS 5
BANKSEL 0
loop
incf NUMBER,1
movf NUMBER,0
movwf temp ;copy number to temp here
movlw b'00001111' ;least signifigant digit mask
andwf temp,1
LSLF temp,1
LSLF temp, 0; MULTIPLY ACC X 4 store in W
BRW
zero movlw b'01110111' ;ZERO
goto next
one movlw b'01000001' ;one
goto next
two movlw b'00111011' ;TWO
goto next
three movlw b'01101011' ;three
goto next
four movlw b'01001101' ;4
goto next
five movlw b'01101110' ;5
goto next
six movlw b'01111110' ;6
goto next
seven movlw b'01000011' ;7
goto next
eight movlw b'01111111' ;EIGHT
goto next
nine movlw b'01001111' ;9
goto next
ten movlw b'01011111' ;A
goto next
eleven movlw b'01111100' ;B
goto next
twelve movlw b'00110110' ;C
goto next
thirteen movlw b'01111001' ;D
goto next
fourteen movlw b'00111110' ;E
goto next
fifteen movlw b'00011110' ;F
next movwf PORTC ;DISPLAY LOW DIGIT
movf NUMBER,0
movwf temp
movlw b'11110000' ;high bit mask
andwf temp, 1
LSRF temp, 1
LSRF temp, 0 ;shift right 2 times store in W
BRW
;compare if temp=0 then CALL zero if 1 then CALL one etc.
zero2 movlw b'01110111' ;ZERO
goto next2
one2 movlw b'01000001' ;one
goto next2
two2 movlw b'00111011' ;TWO
goto next2
three2 movlw b'01101011' ;three
goto next2
four2 movlw b'01001101' ;4
goto next2
five2 movlw b'01101110' ;5
goto next2
six2 movlw b'01111110' ;6
goto next2
seven2 movlw b'01000011' ;7
goto next2
eight2 movlw b'01111111' ;EIGHT
goto next2
nine2 movlw b'01001111' ;9
goto next2
ten2 movlw b'01011111' ;A
goto next2
eleven2 movlw b'01111100' ;B
goto next2
twelve2 movlw b'00110110' ;C
goto next2
thirteen2 movlw b'01111001' ;D
goto next2
fourteen2 movlw b'00111110' ;E
goto next2
fifteen2 movlw b'00011110' ;F
next2 movwf PORTA
call PAUSE
;loop forever
goto loop
PAUSE movlw 0xC0
MOVWF BIGdelay
D250 movlw 0xFE
movwf delay
l250 decfsz delay,f
goto l250
DECFSZ BIGdelay,f
GOTO D250
return
dummyINT retfie
end