Continue to Site

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.

16f to 18f code migration/optimization

Status
Not open for further replies.

maria_100784

Newbie level 6
Joined
Nov 19, 2011
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,371
Hello. I need some help regarding the migration from the 16f877a to 18f25k22 device..i had modified all the registers acording to the datasheets but my program wont work on 18f25k22, but compilation is successufuly . I`m using MPLAB V8.8. The project forward the data from a eusart line ,and output it via rs232 in windows based terminal.
I will put the both .asm files in atachament , as in [-CODE-] mode it would ruin the structure of the asm lines. What i`m doing wrong? ...:(...please help [in pic16f877a the application is working right, in 25k22 i dont get any "move or byte" the in rs232 terminal].Thank YOu.
 

Hi,

Wow - where do you start !

Your original code may work, but its a whole lot of code in the interrupt routine.

I have not gone though things in detail but some of the obvious thing to correct are -

The Config code - you have none - importantly it needs to know what oscillator to use, particularly as that chip has an internal ones available, which also need setting to the required frequency in your main code.

Same with Mclre - is the whole chip left in reset ?

Your ISR is wrong, on the 18F you have 2 levels of Interrupt High starting at 0x008 and Low at 0x018 , so your code writes into the Low vector.
You should put your ISR code into a subroutine and place it after the retfie of the Low vector ISR -

Code:
		ORG	0x0008

		bra	HighInt		;go to high priority interrupt routine

;******************************************************************************
;
;	Low priority interrupt vector
;	=============================
 
		ORG	0x0018

;		movff	STATUS,STATUS_TEMP	;save STATUS register
;		movff	WREG,WREG_TEMP		;save working register
;		movff	BSR,BSR_TEMP		;save BSR register

;	*** low priority interrupt code goes here ***


;		movff	BSR_TEMP,BSR		;restore BSR register
;		movff	WREG_TEMP,WREG		;restore working register
;		movff	STATUS_TEMP,STATUS	;restore STATUS register
		retfie

;******************************************************************************
;
;	High priority interrupt routine
;	===============================

HighInt		nop


Would suggest you use the Microchip/ ASM/TEMPLATEs/pic18f25k22.temp. file as a guide line and try and just flash a led to prove the system works then migrate one function at a time checking each works ok.
 

The CONFIG OPTIONS are seted in MPLAB menu "CONFIGURE BITS" and they are deleted from code...so this is not the problem...I`m suspecting maybe a TMR0 problem? in regard that it must be set properly to 8BIT mode?
 

Hi,

The Config lines may be in Mplab but we cannot see them to know how they are set !

More on the ISR routine, the 18F High Interrupt does its own context saving so no need for you to do the same thing.

Out of interest, why have you moved to this 18F chip ? - seems little advantage for what you are doing over the 16F ?
 

unfortunetly, MIcrochip does not provide TEMPLATE file for 18f25k22 :( ..I`m moving to 18f due CPU speed concern
 

Hi,

More questions than answers..

What speed concern ?

What crystal frequency are you using on the 877A and 25k22 ? - no mention in your code.
Its always important to specify this and the config code in your program code when you post it.

You can use the 46K22 template, just allow for the smaller memory.

I can see from the 877A program that you are outputting data via the USART but its not clear what else you program is doing with Timer0 and the other i/o ports, can you enlighten me - have been trying to simulate it..

Are you running the program on hardware or Simulating it ?
 

I want to use it at maximum speed that a actual PIC can do it , with a external 64 MHZ OSC..on the 877a i was using 20 mhz OSC. The program reads serial data by interrupts ,and outputs it via uart..running on real hardware , no simulation. Thanks
 

Hi,

As you are finding out the K series of 18F chips are quiet a bit different from the 16F chips.

The standard 18F2520 is prehaps more suited to easy code upgrade from the 16Fs.
They can achieve 32Mhz with the internal oscillator and PLL or 40Mhz with a crystal, so allowing 115k baud.

As the 16Fs with 20mhz can still achieve 57k baud think for that small speed difference, you would be better spending your time perfecting your code skills on the 877A before adding more complications on yourself.

You will also find much more forum and web support for the 16F than the 18 K series.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top