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.

Problem in big lookup table.

Status
Not open for further replies.

swapan

Member
Hi Friends,

It gives me pleasure that with the help of 'talkingelectronics' also experts of this forum I have been able to build a moving display. But when I try to display and move a big message, a problem is faced. The entire message does not display, rather it stops to a certain point and restarts from the beginning of the message. I think this is due to limitation of Program Counter. Searching internet for some tips on PCL, PCLATH and Big Lookup table I could not grasp any conception as to how big lookup tables could be handled. I am giving the code with the hope to have some expertise advice from forum members.

regards

swapan


Code:
 list        p=16f72        ; list directive to define processor
    #include    <p16f72.inc>    ; processor specific variable definitions
    
    __CONFIG   _CP_ALL & _WDTEN_OFF & _BODEN_ON & _PWRTEN_ON & _HS_OSC
errorlevel -203, -205, -302,
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

;***** VARIABLE DEFINITIONS (examples)

; example of using Uninitialized Data Section
cblock			0x20 
jump_value
view_count
col_1
col_2
col_3
col_4
col_5
col_6
col_7
col_8
col_9
col_10
col_11
col_12
col_13
col_14
col_15
col_16
col_17
col_18
col_19
col_20
col_21
col_22
col_23
col_24
col_25
col_26
col_27
col_28
col_29
col_30
col_31
col_32
view_count_1
view_count_2
count1
count2
count3
                             ; variable used for context saving

endc




;**********************************************************************
RESET_VECTOR      CODE    0x0000      ; processor reset vector
    goto    start                     ; go to beginning of program

INT_VECTOR        CODE    0x0004      ; interrupt vector location




MAIN_PROG         CODE

start



bsf		STATUS,RP0
movlw		00h
movwf		TRISA
movlw		00h
movwf		TRISB
movlw		00h
movwf		TRISC
movlw		06h
movwf		ADCON1
movlw		b'10000111'
movwf		OPTION_REG
bcf		STATUS,RP0
;;;;;;;;;;;
clrf	PORTB	




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Run_1:

clrf	col_1
clrf	col_2
clrf	col_3
clrf	col_4
clrf	col_5
clrf	col_6
clrf	col_7
clrf	col_8
clrf	col_9
clrf	col_10
clrf	col_11
clrf	col_12
clrf	col_13
clrf	col_14
clrf	col_15
clrf	col_16
clrf	col_17
clrf	col_18
clrf	col_19
clrf	col_20
clrf	col_21
clrf	col_22
clrf	col_23
clrf	col_24
clrf	col_25
clrf	col_26
clrf	col_27
clrf	col_28
clrf	col_29
clrf	col_30
clrf	col_31
clrf	col_32



clrf	jump_value
Run_2:
movlw	d'40'
movwf	view_count
call	shift
incf	jump_value,1
movf	jump_value,0
call	table
movwf	col_1
xorlw	0FFh
btfsc	status,z
goto	Run_1


Run_3:
decfsz	view_count,1
goto	Run_4
goto	Run_2
Run_4:
call	scan
goto	Run_3

shift:
movf		col_31,0
movwf		col_32		;32
movf		col_30,0
movwf		col_31		;31
movf		col_29,0
movwf		col_30		;30
movf		col_28,0
movwf		col_29		;29
movf		col_27,0
movwf		col_28		;28
movf		col_26,0
movwf		col_27		;27
movf		col_25,0
movwf		col_26		;26
movf		col_24,0
movwf		col_25		;25
movf		col_23,0
movwf		col_24		;24
movf		col_22,0
movwf		col_23		;23
movf		col_21,0
movwf		col_22		;22
movf		col_20,0
movwf		col_21		;21
movf		col_19,0
movwf		col_20		;20
movf		col_18,0
movwf		col_19		;19
movf		col_17,0
movwf		col_18		;18
movf		col_16,0
movwf		col_17		;17
movf		col_15,0
movwf		col_16		;16
movf		col_14,0
movwf		col_15		;15
movf		col_13,0
movwf		col_14		;14
movf		col_12,0
movwf		col_13		;13
movf		col_11,0
movwf		col_12		;12
movf		col_10,0
movwf		col_11		;11
movf		col_9,0
movwf		col_10		;10
movf		col_8,0
movwf		col_9		;9
movf		col_7,0
movwf		col_8		;8
movf		col_6,0
movwf		col_7		;7
movf		col_5,0
movwf		col_6		;6
movf		col_4,0
movwf		col_5		;5
movf		col_3,0
movwf		col_4		;4
movf		col_2,0
movwf		col_3		;3
movf		col_1,0
movwf		col_2		;2
return

scan:
bsf			PORTA,0
bsf			PORTC,3
nop
nop
bsf			PORTA,1
nop
nop

bcf		PORTA,1
bcf		PORTC,3
movf	col_32,0
movwf	PORTB
call	view_delay
movf	col_31,0
movwf	PORTB
call	view_delay
movf	col_30,0
movwf	PORTB
call	view_delay
movf	col_29,0
movwf	PORTB
call	view_delay
movf	col_28,0
movwf	PORTB
call	view_delay
movf	col_27,0
movwf	PORTB
call	view_delay
movf	col_26,0
movwf	PORTB
call	view_delay
movf	col_25,0
movwf	PORTB
call	view_delay
movf	col_24,0
movwf	PORTB
call	view_delay
movf	col_23,0
movwf	PORTB
call	view_delay
movf	col_22,0
movwf	PORTB
call	view_delay
movf	col_21,0
movwf	PORTB
call	view_delay
movf	col_20,0
movwf	PORTB
call	view_delay
movf	col_19,0
movwf	PORTB
call	view_delay
movf	col_18,0
movwf	PORTB
call	view_delay
movf	col_17,0
movwf	PORTB
call	view_delay
movf	col_16,0
movwf	PORTB
call	view_delay
movf	col_15,0
movwf	PORTB
call	view_delay
movf	col_14,0
movwf	PORTB
call	view_delay
movf	col_13,0
movwf	PORTB
call	view_delay
movf	col_12,0
movwf	PORTB
call	view_delay
movf	col_11,0
movwf	PORTB
call	view_delay
movf	col_10,0
movwf	PORTB
call	view_delay
movf	col_9,0
movwf	PORTB
call	view_delay
movf	col_8,0
movwf	PORTB
call	view_delay
movf	col_7,0
movwf	PORTB
call	view_delay
movf	col_6,0
movwf	PORTB
call	view_delay
movf	col_5,0
movwf	PORTB
call	view_delay
movf	col_4,0
movwf	PORTB
call	view_delay
movf	col_3,0
movwf	PORTB
call	view_delay
movf	col_2,0
movwf	PORTB
call	view_delay
movf	col_1,0
movwf	PORTB
call	view_delay
bcf		PORTA,0
nop
nop
bsf		PORTA,0
return



view_delay:
call		delay_2
clrf		PORTB
bsf			PORTA,1
nop
nop
bcf			PORTA,1
return



delay_2:
movlw	d'150'
movwf	count2
decfsz	count2,1
goto	$-1
return


table:
addwf		02h,1
retlw		00h
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		00h
retlw		00h
retlw		00h
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		22h	;
retlw		00h	;		C
retlw		7Fh	;
retlw		48h	;
retlw		48h	;
retlw		48h	;
retlw		37h	;
retlw		00h	;		R
retlw		7Fh	;
retlw		49h	;
retlw		49h	;
retlw		41h	;
retlw		00h	;		E
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		40h	;
retlw		40h	;
retlw		7Fh	;
retlw		40h	;
retlw		40h	;
retlw		00h	;		T
retlw		00h	;
retlw		00h	;
retlw		7Fh	;
retlw		00h	;
retlw		00h	;		I
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		3Eh	;		O
retlw		00h	;
retlw		7Fh	;
retlw		10h	;
retlw		8h	;
retlw		4h	;
retlw		7Fh	;
retlw		00h	;		N
retlw		00h
retlw		00h
retlw		00h
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		3Eh	;		O
retlw		00h	;
retlw		7Fh	;
retlw		48h	;
retlw		48h	;
retlw		40h	;
retlw		00h	;		F
retlw		00h
retlw		00h



retlw		00h
retlw		32h	;
retlw		49h	;
retlw		49h	;
retlw		49h	;
retlw		26h	;
retlw		00h	;		S
retlw		7Fh	;
retlw		02h	;
retlw		04h	;
retlw		02h	;
retlw		7Fh	;
retlw		00h	;		W
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		7Fh	;
retlw		48h	;
retlw		48h	;
retlw		48h	;
retlw		30h	;
retlw		00h	;		P
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		7Fh	;
retlw		10h	;
retlw		8h	;
retlw		4h	;
retlw		7Fh	;
retlw		00h	;		N
retlw		00h
retlw		00h
retlw		00h
retlw		00h
retlw		32h	;
retlw		49h	;
retlw		49h	;
retlw		49h	;
retlw		26h	;
retlw		00h	;		S
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		7Fh	;
retlw		48h	;
retlw		48h	;
retlw		48h	;
retlw		37h	;
retlw		00h	;		R
retlw		7Fh	;
retlw		08h	;
retlw		14h	;
retlw		22h	;
retlw		41h	;		K
retlw		00h
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		7Fh	;
retlw		48h	;
retlw		48h	;
retlw		48h	;
retlw		37h	;
retlw		00h	;		R
retlw		00h
retlw		00h

retlw		08h
retlw		2Ah
retlw		1Ch
retlw		7Fh
retlw		1Ch
retlw		2Ah
retlw		08h
retlw		00h
retlw		00h
retlw		00h
retlw		1Fh	;
retlw		28h	;
retlw		48h	;	
retlw		28h	;
retlw		1Fh	;
retlw		00h	;		A
retlw		7Fh	;
retlw		10h	;
retlw		8h	;
retlw		4h	;
retlw		7Fh	;
retlw		00h	;		N
retlw		00h
retlw		00h
retlw		7Fh	;
retlw		49h	;
retlw		49h	;
retlw		41h	;
retlw		00h	;		E
retlw		7Fh	;
retlw		01h	;
retlw		01h	;
retlw		01h	;
retlw		00h	;		L
retlw		7Fh	;
retlw		49h	;
retlw		49h	;
retlw		41h	;
retlw		00h	;		E
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		22h	;
retlw		00h	;		C
retlw		40h	;
retlw		40h	;
retlw		7Fh	;
retlw		40h	;
retlw		40h	;
retlw		00h	;		T
retlw		7Fh	;
retlw		48h	;
retlw		48h	;
retlw		48h	;
retlw		37h	;
retlw		00h	;		R
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		3Eh	;		O
retlw		00h	;
retlw		7Fh	;
retlw		10h	;
retlw		8h	;
retlw		4h	;
retlw		7Fh	;
retlw		00h	;		N
retlw		7Fh	;
retlw		00h	;		I
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		22h	;
retlw		00h	;		C
retlw		32h	;
retlw		49h	;
retlw		49h	;
retlw		49h	;
retlw		26h	;
retlw		00h	;		S
retlw		00h
retlw		00h
retlw		7Fh	;
retlw		08h	;
retlw		08h	;
retlw		08h	;
retlw		7Fh	;
retlw		00H	;		H
retlw		3Eh	;
retlw		41h	;
retlw		41h	;
retlw		41h	;
retlw		3Eh	;		O
retlw		00h	;
retlw		7Fh	;
retlw		49h	;
retlw		49h	;
retlw		49h	;
retlw		30h	;
retlw		00h	;		B
retlw		7Fh	;
retlw		49h	;
retlw		49h	;
retlw		49h	;
retlw		30h	;
retlw		00h	;		B
retlw		60h	;
retlw		10h	;
retlw		08h	;
retlw		10h	;
retlw		60h	;
retlw		00h	;		Y
retlw		00h	;
retlw		00h	;
retlw		7Fh	;
retlw		00h	;
retlw		00h	;		I
retlw		32h	;
retlw		49h	;
retlw		49h	;
retlw		49h	;
retlw		26h	;
retlw		00h	;		S
retlw		40h	;
retlw		40h	;
retlw		7Fh	;
retlw		40h	;
retlw		40h	;
retlw		00h	;		T

retlw		0FFh

END                       ; directive 'end of program'
 
Last edited by a moderator:
Check my PIC tutorials, the 8x8 LED matrix one shows one way of implementing large tables on a PIC, the method is used both for the font tables and the message text.
 
Are you willing to try a couple program changes? If so, first add two new variables in your cblock;

Code:
count1
count2
count3
ptrl                            ; added
ptrh                            ; added
        endc

Now change the code in the Run_2 section as shown here;

Code:
;       clrf	jump_value      ; <---------------------- remove
        movlw   high(table)     ; table address hi
        movwf   ptrh            ;
        movlw   low(table)      ; table address lo
        movwf   ptrl            ; ptrh:l = &table[0]
Run_2:
        movlw	d'40'           ;
        movwf	view_count      ;
        call	shift           ;
;       incf	jump_value,1    ; <---------------------- remove
;       movf	jump_value,0    ; <---------------------- remove
;       call	table           ; <---------------------- remove
        call    rdtable         ; read byte from table
        incf    ptrl,F          ; post increment pointer
        skpnz                   ;
        incf    ptrh,F          ;
        movwf	col_1           ; update col_1 from table
        xorlw	0FFh            ; end of table?
        btfsc	status,z        ; no, skip, else
        goto	Run_1           ; start over
Run_3:

Finally, add new code and make changes shown here;

Code:
rdtable
        movf    ptrh,W          ;   
        movwf   PCLATH          ;   
        movf    ptrl,W          ;   
        movwf   PCL             ;   
table:
;       addwf	02h,1           ; <---------------------- remove
        retlw	00h
        retlw	1Fh             ;
        retlw	28h             ;
        ~~~

Please let us know if it works?

Regards, Mike
 
Thanks Mike for sparing your valuable time to show me a direction. Repeatedly I have gone through the changes suggested by you and got some idea. I shall incorporate the change in my code and certainly intimate you the result. Before that, one point I like to get clear from you Sir. "movlw high(table)" "movlw low(table)" - here I am messing up. 'Table address hi' and 'table address lo' comments against those instructions may also kindly be elaborated to some extent.


regards


swapan
 
hi swapan,

I'm sure someone can jump in and explain about the low() and high() operators much better than I can.

Meanwhile, can you post a schematic or a link to the schematic of the circuit this code is intended to drive, please?

Thank you.

Cheerful regards, Mike
 
Last edited:
Thanks Mike. I don't know if anybody will jump in to explain the issue. I am sure it will be very helpful for me if you take up the matter please. As regards schematic or link of the circuit, please note that there was a thread "LED Sign Board 64X8 - PIC 16F628A" started by Mr. Gayan Soyza, a member of this forum. You might know about it as there was several contributions from yourself. I have taken up that project with some changes as below.

I have used PIC 16F72 in place of PIC 16F628A and 32 columns in place of 64 column.

regards, swapan
 
Spending thirty minutes re-reading that thread didn't help much. Gayan used 74HC164's at the beginning of the thread and then switched to 74HC595's. Looking at your program it seems you might be using 74HC164's with column 31 on the left side of the display and column 0 on the right side of the display. Without a schematic and lacking any useful comments in your program I can't even tell what frequency crystal you're using.

Regards...
 
Dear Mike,

You have guessed exactly what I did. Actually I am a mere electronics hobbyist having no institutional background in this field. All that I have, some working experience. With the help of various tutorial on internet and some forums, I have started playing with microcontroller. Hence there may be novice question from my end. In the above project, PORTA,0 is used as reset pulse, PORTA,1 is used as Serial Input and PORTC,3 used as clock pulse. I have used 20MHz crystal.

regards,

swapan
 
If your table have greater than 255 (FF) line you may have problems because when you are calling table you are adding "w" to going desired line and if you try to added more than FF you are just adding (if you increase FF you get 00) after zero values this means you are getting back to the first line and execute the first value in the table. there is a few ways to get rid of this situation first don't write a table longer than 255 line, second if you pass 255 increase program counter hıgh 'PCH' value one before calling the table.
 
Dear Mike,

You have guessed exactly what I did. Actually I am a mere electronics hobbyist having no institutional background in this field. All that I have, some working experience. With the help of various tutorial on internet and some forums, I have started playing with microcontroller. Hence there may be novice question from my end. In the above project, PORTA,0 is used as reset pulse, PORTA,1 is used as Serial Input and PORTC,3 used as clock pulse. I have used 20MHz crystal.

Hi Swapan,

Actually it looks like you're using RA0 for <reset>, RA1 for <clk>, and RC3 for <dat> or <ser> (however you want to distinguish it).

You've done a very nice job on your program, coming up with some simple and elegant solutions to some difficult problems. Adding meaningful comments may help you in the future. I can show you an example with comments, if you like (my optimized interpretation of your program).

May I offer one suggestion, please? Consider using the assembler 'dt' (data table) pseudo instruction to build a line containing multiple 'retlw' data values. For example, the message table below will produce the same set of 'retlw' instructions when compiled/assembled but uses much fewer lines in your source file.

Have fun. Cheerful regards, Mike

Code:
;******************************************************************
;  message table                                                  *
;******************************************************************

rdtable
        movf    ptrh,W          ;   
        movwf   PCLATH          ;   
        movf    ptrl,W          ;   
        movwf   PCL             ;   
table
        dt      00h                     ;
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      00h,00h,00h             ;
        dt      3Eh,41h,41h,41h,22h,00h ;  C
        dt      7Fh,48h,48h,48h,37h,00h ;  R
        dt      7Fh,49h,49h,41h,00h     ;  E
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      40h,40h,7Fh,40h,40h,00h ;  T
        dt      00h,00h,7Fh,00h,00h     ;  I
        dt      3Eh,41h,41h,41h,3Eh,00h ;  O
        dt      7Fh,10h,08h,04h,7Fh,00h ;  N
        dt      00h,00h,00h             ;
        dt      3Eh,41h,41h,41h,3Eh,00h ;  O
        dt      7Fh,48h,48h,40h,00h     ;  F
        dt      00h,00h,00h             ;
        dt      32h,49h,49h,49h,26h,00h ;  S
        dt      7Fh,02h,04h,02h,7Fh,00h ;  W
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      7Fh,48h,48h,48h,30h,00h ;  P
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      7Fh,10h,08h,04h,7Fh,00h ;  N
        dt      00h,00h,00h,00h         ;
        dt      32h,49h,49h,49h,26h,00h ;  S
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      7Fh,48h,48h,48h,37h,00h ;  R
        dt      7Fh,08h,14h,22h,41h,00h ;  K
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      7Fh,48h,48h,48h,37h,00h ;  R
        dt      00h,00h                 ;
        dt      08h,2Ah,1Ch,7Fh,1Ch,2Ah,08h
        dt      00h,00h,00h             ;
        dt      1Fh,28h,48h,28h,1Fh,00h ;  A
        dt      7Fh,10h,08h,04h,7Fh,00h ;  N
        dt      00h,00h                 ;
        dt      7Fh,49h,49h,41h,00h     ;  E
        dt      7Fh,01h,01h,01h,00h     ;  L
        dt      7Fh,49h,49h,41h,00h     ;  E
        dt      3Eh,41h,41h,41h,22h,00h ;  C
        dt      40h,40h,7Fh,40h,40h,00h ;  T
        dt      7Fh,48h,48h,48h,37h,00h ;  R
        dt      3Eh,41h,41h,41h,3Eh,00h ;  O
        dt      7Fh,10h,08h,04h,7Fh,00h ;  N
        dt      7Fh,00h                 ;  I
        dt      3Eh,41h,41h,41h,22h,00h ;  C
        dt      32h,49h,49h,49h,26h,00h ;  S
        dt      00h,00h                 ;
        dt      7Fh,08h,08h,08h,7Fh,00h ;  H
        dt      3Eh,41h,41h,41h,3Eh,00h ;  O
        dt      7Fh,49h,49h,49h,30h,00h ;  B
        dt      7Fh,49h,49h,49h,30h,00h ;  B
        dt      60h,10h,08h,10h,60h,00h ;  Y
        dt      00h,00h,7Fh,00h,00h     ;  I
        dt      32h,49h,49h,49h,26h,00h ;  S
        dt      40h,40h,7Fh,40h,40h,00h ;  T
        dt      0FFh                    ; <end-of-table>

;******************************************************************
        end
 
Last edited:
Dear Mike,

First of all I beg apology for passing wrong information regarding various pulses derived from PIC. Your observation is right. Though I have designed PCB with provision of various pulses as you have pointed out, but while explaining, I made the mistake. However, I shall be more cautious in future.

Thanks for your suggestion. I always hope such suggestion and guidance. Just I am going through your code and shall get in touch with you soon.


regards,

swapan
 
Thanks Mike. Changing the code as you have suggested the problem is overcome. No it is possible to handle a big table.

The system that I took up has one draw back. Every time, if I like to change the message to be displayed, the code is to be modified and built. In other system there is provision of changing the message using interfaced key pad/ key board. I need any link or assistance in this regard.

regards,
swapan
 
you may define temporary variables and when you get a value from keypad you may write it in to the this temps, and modify your table to get temps to write them into lcd
for ex; you get temp1, temp2, temp3..... tempx (not bigger than 126 ) you will increase two times per cycle w to getting value of the tempx your look up table should be like this:

addwf pcl,f
nop
movf temp1,w
retlw
movf temp2,w
retlw
.
.
.
movf tempx,w
retlw
movlw 00h ;table end value
retlw

as I mentioned before this table should have lines not bigger than 255 temp values must have the ascıı values of the carecters and your program that calls the table need to be able to send this value to the lcd in proper way for the used mod 4bit-8bit of the lcd.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top