![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi, I'm having problems adapting a set of LCD routines found on http://www.winpicprog.co.uk/pic_tutorial3.htm from the 16F628 to a 18F4520. The line I am having trouble with is: Text addwf PCL, f For a start I don't quite understand what the f signifies and the problem that it doesn't add the working register to the Program counter low, but just jumps to some other random line after that. Anyone who can shed some like on my problem would be greatly appreciated. Thanks in advance. | |
| |
| | #2 |
|
Addwf PCL,f adds the working register to PCL and stores the result back in the File (PCL) register. Had it been addwf PCL,w then the result would have been placed in the Work register. To convert this code to 18 series is a little tricky as each location is counted as two bytes and so instructions are only stored on even byte boundaries and you have to add twice the value to PCL to get the same result as a 16 series chip. If you post what you have there may be a simple work around. Edit, didn't notice you have posted your code. I'll take a look. Mike. Last edited by Pommie; 13th October 2009 at 05:55 AM. | |
| |
| | #3 |
|
The F signifies that the result of adding W to PCL goes into PCL. If you had a W instead of the F, the result would go into W. It is possible that your table is crossing a boundary. You can have the compiler check that for you by doing this: Code: Table1:
ADDWF PCL, f ;jump forward by value of W
retlw 'A'
retlw 'B'
retlw 'C'
retlw 'D'
retlw 'E'
retlw 'F' ;end of table
IF HIGH($)!=HIGH(Table1)
ERROR "End of table is not in same page as start of table"
ENDIF
;It will give an error at compile time if it crosses that boundry.
__________________ Inside every little problem, is a big problem trying to get out. Last edited by kchriste; 13th October 2009 at 06:00 AM. | |
| |
| | #4 |
|
A simple bodge would be to add a variable to mutiply by two at the start of each table and setup PCLATH. You also need to make sure each table doesn't cross a (256 byte) page boundary. Code: org 0x200
HEX_Table movwf bodge ;save W
movlw high $ ;setup PCLATH
movwf PCLATH
rlncf bodge,w ;Mutiply by 2
ADDWF PCL , f ;and add to PCL
RETLW 0x30
RETLW 0x31
RETLW 0x32
RETLW 0x33
RETLW 0x34
Mike. Last edited by Pommie; 13th October 2009 at 06:17 AM. Reason: Added comments. | |
| |
| | #5 |
|
BTW, you will need to write 0x0f to ADCON1 to make your ports digital - they default to analogue. Mike. | |
| |
| | #6 |
|
OK I think it may have worked but can you please exaplain what this line does: movlw high $ | |
| |
| | #7 |
|
It loads the work register (W) with the high byte of the program counter. Mike. | |
| |
| | #8 |
|
If it's any help, I've also been doing some work converting the tuorials to 18F, here's a string table example from Tutorial 3.3 Code: Text movwf taboff ; save table offset bcf STATUS, C ; clear STATUS bit rlcf taboff, F ; multiply by 2, save in taboff movlw HIGH(String1) ; get high byte of table start btfsc STATUS, C ; test carry bit incf WREG, W movwf PCLATH ; modify PCLATH if required movlw LOW(String1) ; get low byte of table address addwf taboff, W ; add in offset btfsc STATUS, C ; test for overflow incf PCLATH, F ; increment if needed movwf PCL ; make jump, PCLATH and PCLATU are ; written to PCH and PCU String1 retlw '1' retlw '6' retlw ' ' retlw 'B' retlw 'i' retlw 't' retlw ' ' retlw 'C' retlw 'o' retlw 'u' retlw 'n' retlw 't' retlw 'e' retlw 'r' retlw '.' retlw 0x00 | |
| |
|
| Tags |
| adapting, code, pic16, pic18 |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| about PIC18 assembly code | fengshao | Micro Controllers | 13 | 8th May 2009 01:58 PM |
| Pic16 Family | ahmaaa | Micro Controllers | 7 | 14th March 2009 03:18 PM |
| PIC18 C Code for Dragonfly | ThiSel | Micro Controllers | 5 | 3rd March 2008 04:19 PM |
| Adapting LCD code for 16F876 | bh00 | Micro Controllers | 12 | 22nd February 2007 04:03 PM |
| adc0804 interface code for pic18 | ulas | Micro Controllers | 5 | 27th June 2006 08:40 AM |