Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

look up tables oand the 256 byte boundary?

Status
Not open for further replies.

tracidfish

New Member
I am working on a project where i will habve lots of smallish lookup tables.

Am i correct in thinking that it is important that theese tables do not straddle a 256b byte boundary?

if so how would i ensure i stay within theses boundarys.

i will be using a pic16f628, how do i find out how many boundaries i have and where they are/

Thanks
Chalir

(ps thanks to all those who assisyed me with my LCD it is all up and running now, turns out I had 2 pics both with a broken pins)
 
It's best (easiest!) not to straddle 256 byte boundaries, so how many tables do you need, and what is their total space requirement?.

My tutorials show various table techniques, initially placing tables near the start of memory, later placing tables up higher in their own pages, and lastly using large tables that cross boundaries without any problems so you can stick them anywhere - the last been the 8x8 LED matrix text scolling program (which uses large tables for both the fonts, and for text strings).
 
It's best (easiest!) not to straddle 256 byte boundaries, so how many tables do you need, and what is their total space requirement?.

My tutorials show various table techniques, initially placing tables near the start of memory, later placing tables up higher in their own pages, and lastly using large tables that cross boundaries without any problems so you can stick them anywhere - the last been the 8x8 LED matrix text scolling program (which uses large tables for both the fonts, and for text strings).

hi Nigel,
As Charlie has found the root cause of the LCD problem, it looks as though the LCD initialise query is a non event.?

I will continue to software initialise any LCD's I use..

I have a feeling in my water that this LCD initialise is going to resurface in the future.:)
 
hi Nigel,
As Charlie has found the root cause of the LCD problem, it looks as though the LCD initialise query is a non event.?

I will continue to software initialise any LCD's I use..

I have a feeling in my water that this LCD initialise is going to resurface in the future.:)

'Resurface' gives the impression it's 'surfaced' previously, which it appears never to have done :D
 
Thanks guys

In future it may well be worth suggesting to someone who has the same problem to connect LED's to their pins and use a on off programme. The pins that were at fault were connected and belled out using a multimeter but when they came to be turned off the just stayed high!!

I will need approximatlet 100 tables, all bvery samll, they will be returing enough data to fill both lines of the LCD (16x2). i am not sure how you can calculate their space requirment.

How do i tell if a table is starddaling a boundary, where would I find that information out?
 
Thanks guys

In future it may well be worth suggesting to someone who has the same problem to connect LED's to their pins and use a on off programme. The pins that were at fault were connected and belled out using a multimeter but when they came to be turned off the just stayed high!!

I will need approximatlet 100 tables, all bvery samll, they will be returing enough data to fill both lines of the LCD (16x2). i am not sure how you can calculate their space requirment.

How do i tell if a table is starddaling a boundary, where would I find that information out?

Just from the address, 0 is the start of the first 'page', 256 the second, 512 the third and so on.

I would suggest splitting the tables in to groups that are under 256 bytes long, and storing each group in it's own page in upper memory, or use long table techniques so you can ignore 256 byte boundaries.
 
I cannot work out how you find the address, I am using MPLAB,

I have found something called show disasembly listing, does this indicate the adress?
 
The LST file created by the assembler shows you the exact addressing, here's a sample, I've highlighted the address changes due to ORG in red.

Code:
0000                  00062     ORG      0x0000
0000   [COLOR="red"]0000[/COLOR]           00063     NOP      ;for bootloader compatibility
0001   0000           00064     NOP
0002   0000           00065     NOP
0003   2810           00066     GOTO     _START1
[COLOR="red"]1800[/COLOR]                  00067     ORG      0x1800
                      00068     #INCLUDE MATHS.INC
                      00197         LIST
                      00069     #INCLUDE HANDLERS.INC
                      00021         LIST
[COLOR="red"]0010[/COLOR]                  00070     ORG      0x0010
0010                  00071 _START1
0010   01A2           00072     CLRF     RESTORE
0011   01BC           00073     CLRF     Flags
0012   103C           00074     BCF      Flags, LEADZ
0013   1683 1303      00075     BANKSEL  ADCON1
0015   3006           00076     MOVLW    0x06
0016   009F           00077     MOVWF    ADCON1
0017   1283 1303      00078     BANKSEL  PORTA
 
From what I can gather, you will need the 'list file' box ticked in the 'gererated files' bit of MPASM to get one.
The .lst file is 'from my own experience' placed in the same file as your original .ASM file and your generated .HEX file.
 
You don't need to find the address, you use the high and low functions to access it.

IE,
Code:
	movlw	high(table)
	movwf	PCLATH
	movlw	low(table)
	addfw	offset,w
	btfsc	STATUS,C
	incf	PCLATH,f
	movwf	PCL

Mike.
 
Pommie

How would that fit into this code

#;LCD text demo - 4 bit mode
;Nigel Goodwin 2002

LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)




cblock 0x20 ;start of general purpose registers
count ;used in looping routines
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
tmp1 ;temporary storage
tmp2
templcd ;temp store for 4 bit mode
templcd2
endc

LCD_PORT Equ PORTA
LCD_TRIS Equ TRISA
LCD_RS Equ 0x04 ;LCD handshake lines
LCD_RW Equ 0x06
LCD_E Equ 0x07

org 0x0000

movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

Initialise clrf count
clrf PORTA
clrf PORTB



SetPorts bsf STATUS, RP0 ;select bank 1
movlw 0x00 ;make all pins outputs
movwf LCD_TRIS
bcf STATUS, RP0 ;select bank 0

call Delay100 ;wait for LCD to settle


call LCD_Init ;setup LCD


clrf count ;set counter register to zero
Message movf count, w ;put counter value in W
call Text ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto NextMessage
call LCD_Char
call Delay255
incf count, f
goto Message

NextMessage call LCD_Line2 ;move to 2nd row, first column

clrf count ;set counter register to zero
Message2 movf count, w ;put counter value in W
call Text2 ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto EndMessage
call LCD_Char
incf count, f
goto Message2

EndMessage

Stop goto Stop ;endless loop




;Subroutines and text tables

;LCD routines

;Initialise LCD
LCD_Init movlw 0x20 ;Set 4 bit mode
call LCD_Cmd

movlw 0x28 ;Set display shift
call LCD_Cmd

movlw 0x06 ;Set display character mode
call LCD_Cmd

movlw 0x0d ;Set display on/off and cursor command
call LCD_Cmd

call LCD_Clr ;clear display

retlw 0x00

; command set routine
LCD_Cmd movwf templcd
swapf templcd, w ;send upper nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bcf LCD_PORT, LCD_RS ;RS line to 0
call Pulse_e ;Pulse the E line high

movf templcd, w ;send lower nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bcf LCD_PORT, LCD_RS ;RS line to 0
call Pulse_e ;Pulse the E line high
call Delay5
retlw 0x00

LCD_CharD addlw 0x30
LCD_Char movwf templcd
swapf templcd, w ;send upper nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bsf LCD_PORT, LCD_RS ;RS line to 1
call Pulse_e ;Pulse the E line high

movf templcd, w ;send lower nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bsf LCD_PORT, LCD_RS ;RS line to 1
call Pulse_e ;Pulse the E line high
call Delay5
retlw 0x00

LCD_Line1 movlw 0x80 ;move to 1st row, first column
call LCD_Cmd
retlw 0x00

LCD_Line2 movlw 0xc0 ;move to 2nd row, first column
call LCD_Cmd
retlw 0x00

LCD_Line1W addlw 0x80 ;move to 1st row, column W
call LCD_Cmd
retlw 0x00

LCD_Line2W addlw 0xc0 ;move to 2nd row, column W
call LCD_Cmd
retlw 0x00

LCD_CurOn movlw 0x0d ;Set display on/off and cursor command
call LCD_Cmd
retlw 0x00

LCD_CurOff movlw 0x0c ;Set display on/off and cursor command
call LCD_Cmd
retlw 0x00

LCD_Clr movlw 0x01 ;Clear display
call LCD_Cmd
retlw 0x00

LCD_HEX movwf tmp1
swapf tmp1, w
andlw 0x0f
call HEX_Table
call LCD_Char
movf tmp1, w
andlw 0x0f
call HEX_Table
call LCD_Char
retlw 0x00

Delay255 movlw 0xff ;delay 255 mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00

Pulse_e bsf LCD_PORT, LCD_E
nop
bcf LCD_PORT, LCD_E
retlw 0x00

;end of LCD routines

HEX_Table ADDWF PCL , f
RETLW 0x30
RETLW 0x31
RETLW 0x32
RETLW 0x33
RETLW 0x34
RETLW 0x35
RETLW 0x36
RETLW 0x37
RETLW 0x38
RETLW 0x39
RETLW 0x41
RETLW 0x42
RETLW 0x43
RETLW 0x44
RETLW 0x45
RETLW 0x46


Text addwf PCL, f
retlw 'H'
retlw 'e'
retlw 'l'
retlw 'l'
retlw 'o'
retlw 0x00

Text2 ADDWF PCL, f
RETLW 'R'
RETLW 'e'
RETLW 'a'
RETLW 'd'
RETLW 'y'
RETLW '.'
RETLW '.'
RETLW '.'
RETLW 0x00


end
 
Ahh found it

Pommie how does your code fit into this/

Thanks


Code:
;LCD text demo - 4 bit mode
;Nigel Goodwin 2002

	LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__config 0x3D18			;sets the configuration settings (oscillator type etc.)




		cblock	0x20			;start of general purpose registers
			count			;used in looping routines
			count1			;used in delay routine
			counta			;used in delay routine
			countb			;used in delay routine
			tmp1			;temporary storage
			tmp2
			templcd			;temp store for 4 bit mode
			templcd2	
		endc

LCD_PORT	Equ	PORTA
LCD_TRIS	Equ	TRISA
LCD_RS		Equ	0x04			;LCD handshake lines
LCD_RW		Equ	0x06
LCD_E		Equ	0x07

		org	0x0000

		movlw	0x07
		movwf	CMCON			;turn comparators off (make it like a 16F84)

Initialise	clrf	count
		clrf	PORTA
		clrf	PORTB



SetPorts	bsf 	STATUS,		RP0	;select bank 1
		movlw	0x00			;make all pins outputs
		movwf	LCD_TRIS
		bcf 	STATUS,		RP0	;select bank 0

		call	Delay100		;wait for LCD to settle


		call	LCD_Init		;setup LCD


		clrf	count			;set counter register to zero
Message		movf	count, w		;put counter value in W
		call	Text			;get a character from the text table
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, Z
		goto	NextMessage
		call	LCD_Char
		call	Delay255
		incf	count, f
		goto	Message

NextMessage	call	LCD_Line2		;move to 2nd row, first column

		clrf	count			;set counter register to zero
Message2	movf	count, w		;put counter value in W
		call	Text2			;get a character from the text table
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, Z
		goto	EndMessage
		call	LCD_Char
		incf	count, f
		goto	Message2

EndMessage	
		
Stop		goto	Stop			;endless loop




;Subroutines and text tables

;LCD routines

;Initialise LCD
LCD_Init	movlw	0x20			;Set 4 bit mode
		call	LCD_Cmd

		movlw	0x28			;Set display shift
		call	LCD_Cmd

		movlw	0x06			;Set display character mode
		call	LCD_Cmd

		movlw	0x0d			;Set display on/off and cursor command
		call	LCD_Cmd

		call	LCD_Clr			;clear display

		retlw	0x00

; command set routine
LCD_Cmd		movwf	templcd
		swapf	templcd,	w	;send upper nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 0
		call	Pulse_e			;Pulse the E line high

		movf	templcd,	w	;send lower nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 0
		call	Pulse_e			;Pulse the E line high
		call 	Delay5
		retlw	0x00

LCD_CharD	addlw	0x30
LCD_Char	movwf	templcd
		swapf	templcd,	w	;send upper nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bsf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			;Pulse the E line high

		movf	templcd,	w	;send lower nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bsf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			;Pulse the E line high
		call 	Delay5
		retlw	0x00

LCD_Line1	movlw	0x80			;move to 1st row, first column
		call	LCD_Cmd
		retlw	0x00

LCD_Line2	movlw	0xc0			;move to 2nd row, first column
		call	LCD_Cmd
		retlw	0x00

LCD_Line1W	addlw	0x80			;move to 1st row, column W
		call	LCD_Cmd
		retlw	0x00

LCD_Line2W	addlw	0xc0			;move to 2nd row, column W
		call	LCD_Cmd
		retlw	0x00

LCD_CurOn	movlw	0x0d			;Set display on/off and cursor command
		call	LCD_Cmd
		retlw	0x00

LCD_CurOff	movlw	0x0c			;Set display on/off and cursor command
		call	LCD_Cmd
		retlw	0x00

LCD_Clr		movlw	0x01			;Clear display
		call	LCD_Cmd
		retlw	0x00

LCD_HEX		movwf	tmp1
		swapf	tmp1,	w
		andlw	0x0f
		call	HEX_Table
		call	LCD_Char
		movf	tmp1, w
		andlw	0x0f
		call	HEX_Table
		call	LCD_Char
		retlw	0x00

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7			;delay 1mS
		movwf	counta
		movlw	0x01
		movwf	countb
Delay_0
		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

Pulse_e		bsf	LCD_PORT, LCD_E
		nop
		bcf	LCD_PORT, LCD_E
		retlw	0x00

;end of LCD routines

HEX_Table  	ADDWF   PCL       , f
            	RETLW   0x30
            	RETLW   0x31
            	RETLW   0x32
            	RETLW   0x33
            	RETLW   0x34
            	RETLW   0x35
            	RETLW   0x36
            	RETLW   0x37
            	RETLW   0x38
            	RETLW   0x39
            	RETLW   0x41
            	RETLW   0x42
            	RETLW   0x43
            	RETLW   0x44
            	RETLW   0x45
            	RETLW   0x46


Text		addwf	PCL, f
		retlw	'H'
		retlw	'e'
		retlw	'l'
		retlw	'l'
		retlw	'o'
		retlw	0x00

Text2		ADDWF   PCL, f
            	RETLW   'R'
            	RETLW   'e'
            	RETLW   'a'
            	RETLW   'd'
            	RETLW   'y'
            	RETLW   '.'
            	RETLW   '.'
            	RETLW   '.'
            	RETLW   0x00


		end
 
You would change each table so it looked like this,
Code:
HEX_Table	movwf	offset
		movlw	high(table)
		movwf	PCLATH
		movlw	low(table)
		addwf	offset,w
		btfsc	STATUS,C
		incf	PCLATH,f
		movwf	PCL
table		retlw	0x30
		retlw	0x31
		retlw	0x32
		retlw	0x33
		retlw	0x34
		retlw	0x35
		retlw	0x36
		retlw	0x37
		retlw	0x38
		retlw	0x39
		retlw	0x41
		retlw	0x42
		retlw	0x43
		retlw	0x44
		retlw	0x45
		retlw	0x46
You will need to add a variable called offset and choose a different name for all the tables.

To enter code you type [code] before your code and [/code] after it.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top