![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi there, Just found this site and am hoping that someone might be able to help me with a pic query! label retlw 05H retlw 0FH retlw 14H etc...... Is it possible to move the address of the first instruction (e.g. retlw 05H) of a rountine (named "label") into the working reg using the following... movlw label And then move this value from the working reg into the PCL... movwf PCL to 'jump' to that part/instruction in the program. I know that this is similar to a goto but i require it for a large kinda lookup table. Apologies if this is a really silly question. Still getting the hang of the whole pic programmnig thing!! Cheers all | |
| |
| | (permalink) | |
| Quote:
Code: addwf PCL, f goto SwitchC goto SwitchB goto Switch0 goto SwitchA goto SwitchD goto Switch9 | ||
| |
| | (permalink) | |
| Quote:
To modify the program counter directly you must first load register PCLATH with the highest bits of the adress <3:0> (an adress = 14 bits) where it will be kept on hold. Then load PCL with the lowest bits of the adress <7:0>. Once you write to PCL execution jumps to the complete adress given in PCLATH<3:0>:PCL<7:0> Do note that jumping to a lable this way DOES NOT!! put the return adress on the stack. so if you jump to a adress this way, and then do a RETURN, execution will continue to the previous adress pushed on the stack with a normal CALL, not from the adress wich loaded PCL directly Example: Jump to MyLabel directly by loading PCLATH and PCL Code: MOVLW HIGH(MyLabel) ;copy high part of MyLabel adress to W MOVWF PCLATH ;PreLoad lath with this value - this does not jump yet MOVLW LOW(MyLabel) ;copy low part of MyLabel adress to W MOVWF PCL ;load PCL with this value - NOW the jump occurs NOP ;This does not get executed ... MyLabel: ;Some Code here | ||
| |
| | (permalink) |
| Hi Nigel, Thank you very much for the info. I am outputting a number of custom characters to an LCD display (which i have defined in the CGram). I am using lookups to send certain charaters at certain times in certain positions, and was trying to find a way to shrink down my code (by only using two routines to retrieve and send screen data). The lookup table of goto's might solve it. I'll have a go. Kind Regards | |
| |
| | (permalink) |
| Cheers Exo, I had forgotten that the PCL is stored over two registers. Thank you for the info. This might work. | |
| |
| | (permalink) |
| I have done similar work and here's how I did it. Code: ;-----------------------------------------------------------
BOOT_HELLO:
MOVLW HELLO_BEG-HELLO_END
MOVWF TEMP3
BOOT_HELLO2:
CALL GET_HELLO
CALL LCDWRITE_REG
;
DECFSZ TEMP3,F
GOTO BOOT_HELLO2
;
RETURN
;-----------------------------------------------------------
GET_HELLO:
MOVLW HIGH HELLO_END
MOVWF PCLATH
;
DECF TEMP3,W
ADDWF PCL,F
HELLO_END:
RETLW 'O'
RETLW 'L'
RETLW 'L'
RETLW 'E'
RETLW 'H'
HELLO_BEG:
__________________ "Having to do with Motion Control" | |
| |
| | (permalink) |
| Hello Motion, Cheers for the info. This has pretty much done the job. Screens up and running. Thank you | |
| |