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.....
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
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.
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
Maybe some examples will help,
As you can see PCLATH is simply copied into the high byte of the program counter when you write to PCL.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
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.
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
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.Originally Posted by bananasiong
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?
No, please reread this and the previous thread.
Mike.
Last edited by Pommie; 16th July 2007 at 05:07 AM.
No, you need to write to PCLATH.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.
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.
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)But if the Table has more than 255 lines then of course I have to write to the PCLATH & call the table.
bananasiong
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..
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.Originally Posted by simrantogether
Last edited by Nigel Goodwin; 29th August 2007 at 08:05 AM.
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
i think i got it...Originally Posted by Nigel Goodwin
i.e. table meant for branching into various locations ...
thanks..
simran..![]()
Simran..
8051 Specialist..
This may be useful to you.Originally Posted by simrantogether
http://www.hobbyprojects.com/pic_tut...utorial10.html
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!![]()
we all are humans.. who makes mistakes..
you should thanks to God..![]()
Simran..
8051 Specialist..
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;
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').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
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.
I guess I'm really asking -- is there a better way to do this?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
TIA!![]()