Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] tables and arrays for PIC CHIPS MPASM

Status
Not open for further replies.

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,611
When I worked with 6502 I could use an INDEX REGISTER to load the working register with a value.
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
 

My mistake was assuming that the opcode + operand took 2 bytes. Amazingly with this CPU they only take one byte or should I say 1 click on the PC ? (byte is technically only 8 bits)

Secondly I'm using the RETW table style now.

My 2 digit counter now counts without error from 00 to FF

Dan
 

movlw .2
movwf index
movlw high table1 ;TABLE HIGH ADDR.
movwf pclath ;org 200h -- 2
movf index,w
call table1
movwf result ; result <--'V'
.
.
.
.


org 200h ; x00h

table1:
addwf pcl,f
retlw 'L' ; index 0
retlw 'O' ; 1
retlw 'V' ; 2
retlw 'E' ; 3
retlw 0x03 ; 4
retlw b'00000100' ; 5
retlw .5 ; 6
retlw 06h ; 7
.

.
.
.
 

movlw .2
movwf index
movlw high table1 ;TABLE HIGH ADDR.
movwf pclath ;org 200h -- 2
movf index,w
call table1
movwf result ; result <--'V'
.
.
.
.


org 200h ; x00h

table1:
addwf pcl,f
retlw 'L' ; index 0
retlw 'O' ; 1
retlw 'V' ; 2
retlw 'E' ; 3
retlw 0x03 ; 4
retlw b'00000100' ; 5
retlw .5 ; 6
retlw 06h ; 7
.

.
.
.

Is that working with an older chip? NO BRW ?

dan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top