+ Reply to Thread
Page 2 of 3
First 1 2 3 Last
Results 16 to 30 of 35

Thread: Calling a Table from Different Locations

  1. #16
    bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent
    Join Date
    Mar 2006
    Location
    Malaysia
    Posts
    1,881

    Default

    0x0300 and 0x0003 are not the same.
    If the origin of TABLE1 is 0x300, so the location of the addwf in TABLE1 is 0x300, followed by 0x301.....

    If the origin of TABLE1 is 0x0003, the location of the addwf in TABLE1 is 0s0003, followed by 0x0004.....
    bananasiong


  2. #17
    Suraj143 Newbie
    Join Date
    Jan 2007
    Location
    South Mald Isld
    Posts
    921

    Default

    Oh I see then I will start the TABLE4 from org 0x400
    Then the next instructions in the Table4 followed by 0x401, 402 etc.....

    Finally

    At one time I saw somewhere telling if the program memory size is less than 2K-words no need to write to PCLATH is this true?

    It means if my lines below 2048 then I can directly address to PCL without using PCLATH. In any place from the coding.

    Ex: Table1 is in 10th line but I can call from 2000 line?

    Thanks a lot.

  3. #18
    bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent
    Join Date
    Mar 2006
    Location
    Malaysia
    Posts
    1,881

    Default

    No, you're confused. Reread Pommie's replies.

    PCLATH can be used to change page. If you're writing to only the same page (under 2 k), you don't need to change page using PCLATH (usually bit 3 and bit 4).
    However if you use PCL after the program memory 0xff, you need to write to PCLATH, even you're just using the same page (same 2 k)
    bananasiong

  4. #19
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    Maybe some examples will help,
    Code:
    	movlw	03
    	movwf	PCLATH
    	movlw	0x45
    	movwf	PCL;	will jump to address 0x345
    
    	movlw	07
    	movwf	PCLATH
    	movlw	0xac
    	movwf	PCL;	will jump to address 0x7ac
    
    	movlw	0x0a
    	movwf	PCLATH
    	movlw	0x67
    	movwf	PCL;	will jump to address 0xa67
    
    As you can see PCLATH is simply copied into the high byte of the program counter when you write to PCL.

    Note that in the last case it is jumping to an address outside the lower 2K page and so when it returns you must clear PCLATH or subsequent gotos and calls will go to the second bank.

    Mike.

  5. #20
    bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent
    Join Date
    Mar 2006
    Location
    Malaysia
    Posts
    1,881

    Default

    You won't find anything more about paging in the datasheet of PIC16F628A which you are using. It is because this device has the flash memory of 2 k. Read the datasheet of other device to know more about that.
    bananasiong

  6. #21
    Suraj143 Newbie
    Join Date
    Jan 2007
    Location
    South Mald Isld
    Posts
    921

    Default

    Quote Originally Posted by bananasiong
    PCLATH can be used to change page. If you're writing to only the same page (under 2 k), you don't need to change page using PCLATH (usually bit 3 and bit 4).
    However if you use PCL after the program memory 0xff, you need to write to PCLATH, even you're just using the same page (same 2 k)
    Hi thanks a lot guys now I understood how the org 0x003 increments followed by the next instructions. And also I referred to the deassembly listing it was very helpful.

    A small quick question to ask.

    If I’m using PIC16F628A (2K) if I have a Table I can call it from any location of the memory without writing to PCLATH.
    But if the Table has more than 255 lines then of course I have to write to the PCLATH & call the table.

    Is this correct?

  7. #22
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    No, please reread this and the previous thread.

    Mike.
    Last edited by Pommie; 16th July 2007 at 05:07 AM.

  8. #23
    bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent bananasiong Excellent
    Join Date
    Mar 2006
    Location
    Malaysia
    Posts
    1,881

    Default

    If I’m using PIC16F628A (2K) if I have a Table I can call it from any location of the memory without writing to PCLATH.
    No, you need to write to PCLATH.
    For example, if the location of the table is 0x0123, when you call the table and involve PCL, the first returned value should be located at 0x0124. This is possible by writing 0x01 which is the high side of 0x0124 to PCLATH, otherwise the PCL will go to the location 0x0024.

    But if the Table has more than 255 lines then of course I have to write to the PCLATH & call the table.
    No, even the table consist of only 2 lines you need to write to PCLATH if the table is located out of the program memory 0x00ff (0x0100 onwards)
    bananasiong

  9. #24
    simrantogether Good simrantogether Good
    Join Date
    May 2006
    Location
    Bangalore
    Posts
    433

    Smile Excuse me..

    i wanted to know .. what is the purpose of Data tables in pic microcontroller...

    how can it help in various applicartions..

    i got stuck in this chapter...

    any help is appriciated..

    regards,

    simran..
    Simran..
    8051 Specialist..

  10. #25
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,790

    Default

    Quote Originally Posted by simrantogether
    i wanted to know .. what is the purpose of Data tables in pic microcontroller...
    It's the same as a table in any other processor, a list of values which you can index in to - or you can have a jump table, a list of jump addresses you can index in to.
    Last edited by Nigel Goodwin; 29th August 2007 at 08:05 AM.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  11. #26
    simrantogether Good simrantogether Good
    Join Date
    May 2006
    Location
    Bangalore
    Posts
    433

    Smile thanks..

    Quote Originally Posted by Nigel Goodwin
    It's the same as a table in any other processor, a list of values which you can index in to - or you can have a jump table, a list of jump addresses you can index in to.
    i think i got it...

    i.e. table meant for branching into various locations ...

    thanks..

    simran..
    Simran..
    8051 Specialist..

  12. #27
    Gayan Soyza Excellent Gayan Soyza Excellent Gayan Soyza Excellent Gayan Soyza Excellent Gayan Soyza Excellent Gayan Soyza Excellent
    Join Date
    Oct 2006
    Location
    Colombo
    Posts
    1,664
    Blog Entries
    1

    Default

    Quote Originally Posted by simrantogether
    i.e. table meant for branching into various locations ...
    simran..
    This may be useful to you.
    http://www.hobbyprojects.com/pic_tut...utorial10.html

  13. #28
    Banned Kyle-s4h Bad
    Join Date
    May 2007
    Posts
    103

    Default

    Thank you to all that contributed to this thread (reputation passed around!) -- I ran into the same problem Tuesday, came looking here for the answer yesterday (this thread just happened to be on page 1!) and fixed it last night (and understand it too!) -- all my tables are working well now (I've taken Nigels advise as well and started placing all my tables in the last page of code space, then started my program code at the beginning... and hope they never meet!

    Now -- last night I passed my first CODE page boundary (which messed up my ISR because it was at the end of my code space) -- looks like I've got more reading to do today!

  14. #29
    simrantogether Good simrantogether Good
    Join Date
    May 2006
    Location
    Bangalore
    Posts
    433

    Smile well,

    we all are humans.. who makes mistakes..

    you should thanks to God..
    Simran..
    8051 Specialist..

  15. #30
    Banned Kyle-s4h Bad
    Join Date
    May 2007
    Posts
    103

    Default

    I thought I'd append my question to this thread as I believe it is relevant -- if it should be a new thread, Nigel, please feel free to split it off.

    Since reading this thread, I have been able to work with calling tables from different locations (the title of this thread). Now, I have created a macro to handle setting PCLATH for me and would like some opinions on how this is being done. What I mean is, is what I am doing a valid technique, or am I wasting codespace? Obviously, a macro will only save you time/effort, but not codespace as it simply repeats the same code over everywhere the macro is called. Before I forget, here is the macro;

    Code:
    ; macro to set the high bits of PCLATH for a specific table (or call/goto)
    ; call - _SET_PCLATH	<table/call/goto>
    _SET_PCLATH		macro 	table
    				movwf	temp					; save W
    				movlw	HIGH table				; set the high bits of PCLATH
    				movwf	PCLATH					; for the table to be read
    				movfw	temp					; restore W
    			endm
    
    At first, I setup the above for my tables, but then figured I could use it for calls/gotos as well (just didn't change the attribute name of 'table').

    Here is a snippet of code that I just finished "updating", due to my page boundaries. Why I ask these questions is that you can see I am having to call the macro for every call, goto and table to make sure PCLATH is set properly. Some within the module are already set, while others need to be "corrected" after a return from another module... I have included the macro call in ALL of them just to make sure -- and if anything changes in future code, I shouldn't have to worry about where the modules are -- but it does eat up codespace.

    Code:
    ;----------------------------------------------------------------------------------------------
    ; Boot Information (Model, Version, etc.)
    ;----------------------------------------------------------------------------------------------
    
    Boot_Info:
    		_SET_PCLATH LCD_Clr				;
    		call	LCD_Clr
    		clrf	count
    Boot_Msg:		
    		movf	count, w				; put counter value in W
    		_SET_PCLATH Boot_Text			;
    		call	Boot_Text				; get a character from the text table
    		xorlw	0x00					; is it a zero?
    		_SET_PCLATH Boot_Version		;
    		btfsc	STATUS, Z
    		goto	Boot_Version
    		_SET_PCLATH LCD_Char			; make sure the page bits are set
    		call	LCD_Char
    		incf	count, f
    		_SET_PCLATH Boot_Msg				
    		goto	Boot_Msg
    
    Boot_Version:
    		_SET_PCLATH LCD_Line2			; make sure the page bits are set
    		call	LCD_Line2
    		clrf	count
    Boot_Msg2:
    		movf	count, w				; put counter value in W
    		_SET_PCLATH Boot_Text2			;
    		call	Boot_Text2				; get a character from the text table
    		xorlw	0x00					; is it a zero?
    		_SET_PCLATH Boot_Finish			;
    		btfsc	STATUS, Z
    		goto	Boot_Finish
    		_SET_PCLATH LCD_Char			; make sure the page bits are set
    		call	LCD_Char
    		incf	count, f
    		_SET_PCLATH Boot_Msg2			;
    		goto	Boot_Msg2
    
    Boot_Finish:
    		_SET_PCLATH Wait1Second			;
    		call	Wait1Second				; Wait for 2 seconds
    		call 	Wait1Second
    		return
    
    I guess I'm really asking -- is there a better way to do this?

    TIA!

+ Reply to Thread
Page 2 of 3
First 1 2 3 Last

Similar Threads

  1. Calling Tables for PIC877A
    By jinchang in forum Micro Controllers
    Replies: 15
    Latest: 10th June 2007, 02:08 PM
  2. PIC: Table lookup across page boundary
    By eblc1388 in forum Micro Controllers
    Replies: 11
    Latest: 16th August 2005, 02:43 PM
  3. 18F Lookup Table Cose Snippet [ASM]
    By pittuck in forum Micro Controllers
    Replies: 0
    Latest: 14th December 2004, 07:40 AM
  4. truth table vs lookup table
    By alamy in forum Micro Controllers
    Replies: 14
    Latest: 16th June 2004, 07:48 PM
  5. Lookup table for LCD and 7 segment display
    By patricktran in forum Micro Controllers
    Replies: 3
    Latest: 23rd April 2004, 01:43 PM

Tags for this Thread