How to add more lines to a large table

Status
Not open for further replies.

e.chain

New Member
Hi to all, well I am new in this world of microcontrollers, and I am getting more and more excited everytime I learn something new. I was reading the AN556 of microchip where they explains how call a table a the goto instructions, I can't understand very well the article and I am needing help with a table, I need to add more lines to a table and when I do it the pic doesn't work maybe I am overwriting important addresses or instructions, there is no error when I compile the asm but the pic doesn't work correctly. I am working with the PIC 12F629. Right now it is working but if I add another line the pic won't work.

Code:
CBLOCK  0X20

     XMITHREG
     XMITBITCOUNT
     PARITY
     DELAYCOUNT

     RECV            ; RECEIVE DATA HOLDING REGISTER
     TEMPSTAT
     TEMPSTAT2

     TBLCMD0
     CMDCMD1
     CHECKSUM
     TEMPCOUNT1
     TEMPCOUNT2
     TABLELOW

     LA2
     LA1
     LA0

     MEMLA1
     MEMLA2

     TRACKLA1
     TRACKLA2
     TRACKLA3

     SC0
     SC1
     SC2
     SC3
     ENDC

RVECTOR     

 ORG     0X00                ; RESET VECTOR
 GOTO	 DISPATCH_INTERNALINIT

CMDTABL

 MOVF    TABLELOW,W
 INCF    TABLELOW,F
 ADDWF   PCL,F


 ;----------------------ROM BOOT SEQUENCE TABLE---------------------------

STARTTABLE
 DT      0X04, 0X07, 0XFD, 0X8D
 DT      0X04, 0X09, 0XFD, 0X44, 0X00, 0X00
 DT      0X04, 0X08, 0XFD, 0X47, 0X7F
 DT      0X04, 0X08, 0XFD, 0X4A, 0X53
 DT      0X04, 0X08, 0XFD, 0X49, 0X00
 DT      0X04, 0X08, 0XFD, 0X4B, 0XBF  ; SET GLOBAL TIMEOUT TO 4 HOURS
 DT      0X04, 0X08, 0XFD, 0X48, 0X00
 DT      0X04, 0X11, 0XFD, 0X4C, 0X1F, 0X78, 0X7F, 0X7F, 0X7F, 0X0A, 0X00, 0X00, 0X68, 0X7F 
;CHANNEL MAP
 DT      0x04, 0x11, 0xFD, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x05, 0x1A, 0x07
 DT      0x04, 0x11, 0xFD, 0x4D, 0x01, 0x00, 0x16, 0x09, 0x0A, 0x0B, 0x1C, 0x0D, 0x0E, 0x0F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x02, 0x00, 0x10, 0x11, 0x12, 0x13, 0x2E, 0x15, 0x3C, 0x17
 DT      0x04, 0x11, 0xFD, 0x4D, 0x03, 0x00, 0x08, 0x19, 0x14, 0x1B, 0x06, 0x1D, 0x1E, 0x1F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x04, 0x00, 0x51, 0x21, 0x57, 0x23, 0x24, 0x25, 0x26, 0x27
 DT      0x04, 0x11, 0xFD, 0x4D, 0x05, 0x00, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x18, 0x2F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x06, 0x00, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x3E, 0x40
 DT      0x04, 0x11, 0xFD, 0x4D, 0x07, 0x00, 0x4D, 0x41, 0x42, 0x43, 0x5A, 0x4E, 0x58, 0x47
 DT      0x04, 0x11, 0xFD, 0x4D, 0x08, 0x00, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x0C, 0x3F, 0x4F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x09, 0x00, 0x50, 0x52, 0x22, 0x54, 0x53, 0x55, 0x56, 0x3D
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0A, 0x00, 0x69, 0x63, 0x5B, 0x67, 0x68, 0x46, 0x5E, 0x5D
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0B, 0x00, 0x20, 0x44, 0x00, 0x00, 0x00, 0x59, 0x45, 0x62
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0C, 0x00, 0x6F, 0x66, 0x73, 0x74, 0x75, 0x76, 0x00, 0x00
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0D, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6F
 DT	     0X03, 0X06, 0XF9
 DT      0X00 ; DOUBLE 00 IS USED TO FLAG END OF COMMAND BOOT SEQUENCE


LA      DT      0X00, 0XBF, 0X7F, 0X3E
 
With the method you are using, your table can be a maximum of 256 bytes long because of page boundary constraints and the offset is contained in W which is only 8 bits.

To use a longer table you have to have a bigger pointer and do a 16 bit calculation. So, with your offset in pointer you would do the following,
Code:
	movfw	Pointer+1	;get high byte
	addlw	high(Table)	;calc address
	movwf	PCLATH		;store in high byte of PC
	movfw	Pointer		;get low byte
	addlw	low(Table)	;calc low byte of address
	btfsc	STATUS,C	;was there a carry
	incf	PCLATH,F	;yes, so increment high byte
	movwf	PCL		;do jump
Table	DT	0x00

With the above code you can fill the memory with your table.

HTH

Mike.
 
Thanks Pommie for your quick response, I am new to this so be patient with me please.

It would be something like this or am I making a total disaster here:

Code:
CMDTABL

 MOVFW   TABLELOW+1
 ADDLW	 HIGH(STARTTABLE)
 MOVWF   PCLATH
 MOVFW	 TABLELOW
 ADDLW	 LOW(STARTTABLE)
 BTFSC   STATUS,C
 INCF	 PCLATH,F
 MOVWF   PCL


 ;----------------------ROM BOOT SEQUENCE TABLE---------------------------

STARTTABLE
 DT      0X04, 0X07, 0XFD, 0X8D
 DT      0X04, 0X09, 0XFD, 0X44, 0X00, 0X00
 DT      0X04, 0X08, 0XFD, 0X47, 0X7F
 DT      0X04, 0X08, 0XFD, 0X4A, 0X53
 DT      0X04, 0X08, 0XFD, 0X49, 0X00
 DT      0X04, 0X08, 0XFD, 0X4B, 0XBF  ; SET GLOBAL TIMEOUT TO 4 HOURS
 DT      0X04, 0X08, 0XFD, 0X48, 0X00
 DT      0X04, 0X11, 0XFD, 0X4C, 0X1F, 0X78, 0X7F, 0X7F, 0X7F, 0X0A, 0X00, 0X00, 0X68, 0X7F 
;CHANNEL MAP
 DT      0x04, 0x11, 0xFD, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x05, 0x1A, 0x07
 DT      0x04, 0x11, 0xFD, 0x4D, 0x01, 0x00, 0x16, 0x09, 0x0A, 0x0B, 0x1C, 0x0D, 0x0E, 0x0F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x02, 0x00, 0x10, 0x11, 0x12, 0x13, 0x2E, 0x15, 0x3C, 0x17
 DT      0x04, 0x11, 0xFD, 0x4D, 0x03, 0x00, 0x08, 0x19, 0x14, 0x1B, 0x06, 0x1D, 0x1E, 0x1F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x04, 0x00, 0x51, 0x21, 0x57, 0x23, 0x24, 0x25, 0x26, 0x27
 DT      0x04, 0x11, 0xFD, 0x4D, 0x05, 0x00, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x18, 0x2F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x06, 0x00, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x3E, 0x40
 DT      0x04, 0x11, 0xFD, 0x4D, 0x07, 0x00, 0x4D, 0x41, 0x42, 0x43, 0x5A, 0x4E, 0x58, 0x47
 DT      0x04, 0x11, 0xFD, 0x4D, 0x08, 0x00, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x0C, 0x3F, 0x4F
 DT      0x04, 0x11, 0xFD, 0x4D, 0x09, 0x00, 0x50, 0x52, 0x22, 0x54, 0x53, 0x55, 0x56, 0x3D
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0A, 0x00, 0x69, 0x63, 0x5B, 0x67, 0x68, 0x46, 0x5E, 0x5D
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0B, 0x00, 0x20, 0x44, 0x00, 0x00, 0x00, 0x59, 0x45, 0x62
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0C, 0x00, 0x6F, 0x66, 0x73, 0x74, 0x75, 0x76, 0x00, 0x00
 DT      0x04, 0x11, 0xFD, 0x4D, 0x0D, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6F
 DT	     0X03, 0X06, 0XF9
 DT      0X00 ; DOUBLE 00 IS USED TO FLAG END OF COMMAND BOOT SEQUENCE


LA      DT      0X00, 0XBF, 0X7F, 0X3E


PS: I think I don't understand the Pointer thing.
 
Last edited:
TABLELOW+1 must contain the high byte of the pointer. Pointer must be defined as a word. Pointer must also be incremented as a word.

Maybe it would make more sense to increment the pointer in the table routine.

Code:
; in you cblock section you would have
Pointer:2

; in your initialisation you would have,
	clrf	Pointer
	clrf	Pointer+1

; here is the modified code that increments pointer as well
; calling this repeatedly will fetch the next entry in the table.

	movfw	Pointer+1	;get high byte
	addlw	high(Table)	;calc address
	movwf	PCLATH		;store in high byte of PC
	movfw	Pointer		;get low byte
	addlw	low(Table)	;calc low byte of address
	btfsc	STATUS,C	;was there a carry
	incf	PCLATH,F	;yes, so increment high byte
	incf	Pointer,F	;increment pointer
	btfsc	STATUS,Z;	;has it wrapped around
	incf	Pointer+1,F	;yes, so increment high byte
	movwf	PCL		;do jump
Table	DT	0x00

HTH

Mike
 
It is working perfectly, thanks a lot Pommie, the last explanation was the key I was defining the OFFSET as 0x00, and only clearing the offset and not offset+1. Thanks a lot.

Here is the corrected one.

Code:
CMDTABL

 MOVFW   OFFSET+1
 ADDLW	 HIGH(STARTTABLE)
 MOVWF   PCLATH
 MOVFW	 OFFSET
 ADDLW	 LOW(STARTTABLE)
 BTFSC   STATUS,C
 INCF	 PCLATH,F
 INCF	 OFFSET,F
 BTFSC	 STATUS,Z
 INCF	 OFFSET+1,F
 MOVWF	 PCL
 
Glad to here it's working. One other nice thing about doing tables this way is that they can go anywhere in memory so you could now move the table to the end of your code. To my mind, data is placed after code - guess it must be something to do with the way I was brought up.

Mike.
 
I do not believe it. MOVFW actually works. Is this instruction actually a macro or compile directive built into MPASM because MOVFW is not listed in the ordained 35 instruction set?

I just looked at the Program Memory. Turns out MOVFW is converted to MOVF SPEED, W. We can I find a list of all the little secrets of MPASM?

Never mind I found it here: https://www.electro-tech-online.com/custompdfs/2007/03/33014J.pdf But I bet there is more
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…