| Author |
Message |
ericmar
Joined: 14 Apr 2004 Posts: 279 Location: Singapore
|
17 Jul 2004 17:07 rlf pic18f |
|
|
|
|
I was wondering if those programs that works in PIC16F877 can work in PIC18F452???
I'm still a newbie so I really hv no idea on this!
Please help!
|
|
| Back to top |
|
 |
C-Man
Joined: 19 Jul 2001 Posts: 1235 Helped: 73
|
17 Jul 2004 17:24 pic18f pic16f |
|
|
|
|
Most programs should be able to work with PIC18 but you will have to recompile or reassemble them as most of PIC16 use 14bit instructions while PIC18 use 16bit instructions.
Also some of the SFR's can have differnt adresses ...
best regards
|
|
| Back to top |
|
 |
manu
Joined: 14 Mar 2004 Posts: 178 Helped: 9 Location: France
|
17 Jul 2004 18:41 pic18f addwf pcl |
|
|
|
|
In 16Fs, the RP0 & RP1 bits ( status register ) become bsr in 18Fs, it's a register
For example, you want work in bank 1 --> movlb d'001' where movlb means MOVe Litteral to Bsr
regards,
|
|
| Back to top |
|
 |
Google AdSense

|
17 Jul 2004 18:41 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
hill
Joined: 17 Jun 2004 Posts: 285 Helped: 9
|
17 Jul 2004 22:12 pic18f computed goto |
|
|
|
|
1) All SFR are not requires banking, so remove any pagesel or bank select instruction.
2) Look for any $-1 like instruction. You need to double the figure. Ex $-1 becomes $-2, $-2 becomes $-4 etc.
3) Look for instruction that modifies PCL like ADDWF PCL, W. Since 18 series address are WORD aligned, you need to add 2 lines before that instruction. CLRF STATUS, C and RLCF WREG, F.
Or use the enhanced feature of 18 series TBLPTRU/H/L. Microchip has an application notes for this.
4) RRF becomes RRCF, RLF becomes RLCF.
5) Am I missing anything else…
|
|
| Back to top |
|
 |
ericmar
Joined: 14 Apr 2004 Posts: 279 Location: Singapore
|
18 Jul 2004 14:53 pic18f bsr |
|
|
|
|
Thank you guys!
But what is "$-1 like instruction"?
|
|
| Back to top |
|
 |
hill
Joined: 17 Jun 2004 Posts: 285 Helped: 9
|
18 Jul 2004 17:16 pic18f status |
|
|
|
|
Ex. BTFSC STATUS, C
GOTO $-1
The first instruction test the C flag in STATUS register. If C=0, next instruction (GOTO) will be skipped. For the second instruction, $ is represents current address. This instruction will cause the Program Counter to go back to previous instruction.
For 18F series you have to change that to BRA $-2.
More safe way is using label!
TEST: BTFSC STATUS, C
GOTO TEST
In this case, the code will works for both series.
|
|
| Back to top |
|
 |
Jouster
Joined: 12 Aug 2004 Posts: 1
|
12 Aug 2004 0:48 pic16f instructions |
|
|
|
|
Mr. Hill,
Thanks a million for sharing your knowledge!
I've been pulling my hair for 2 days trying to convert my 16F code to 18F. Haven't seen it anywhere (in the datasheet) that the two lines you show above need to be added for the 'addwf PCL' to work. I've been trying to increase 'count' to compensate for 'increment by 2' to no avail.
Now my code works!
Thanks again.
|
|
| Back to top |
|
 |
hill
Joined: 17 Jun 2004 Posts: 285 Helped: 9
|
12 Aug 2004 12:07 addwf pcl 18f |
|
|
|
|
You're welcomed.
But remember in PIC18, using computed goto method, you could only access 128 bytes of data. If you need to access more than that, you'll need to do some calculation to PCLATH and maybe PCLATU. But that would result in ineffecient code. For this purpose, I would recommend you to use table poinetr TBLPTRU, TBLPTRH and TBLPTRL.
|
|
| Back to top |
|
 |