Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Is the program that works in PIC16F works with PIC18F?

Status
Not open for further replies.

ericmar

Full Member level 5
Joined
Apr 14, 2004
Messages
278
Helped
3
Reputation
6
Reaction score
4
Trophy points
1,298
Location
Singapore
Activity points
2,941
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!
 

C-Man

Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,191
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
 

manu

Full Member level 3
Joined
Mar 14, 2004
Messages
179
Helped
11
Reputation
22
Reaction score
2
Trophy points
1,298
Location
France
Activity points
1,299
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 :wink:
regards,
 

hill

Full Member level 5
Joined
Jun 17, 2004
Messages
278
Helped
10
Reputation
20
Reaction score
1
Trophy points
1,298
Activity points
2,334
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…
 

ericmar

Full Member level 5
Joined
Apr 14, 2004
Messages
278
Helped
3
Reputation
6
Reaction score
4
Trophy points
1,298
Location
Singapore
Activity points
2,941
pic18f bsr

Thank you guys!
But what is "$-1 like instruction"?
 

hill

Full Member level 5
Joined
Jun 17, 2004
Messages
278
Helped
10
Reputation
20
Reaction score
1
Trophy points
1,298
Activity points
2,334
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.
 

Jouster

Newbie level 1
Joined
Aug 12, 2004
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
12
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.
 

hill

Full Member level 5
Joined
Jun 17, 2004
Messages
278
Helped
10
Reputation
20
Reaction score
1
Trophy points
1,298
Activity points
2,334
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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top