CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

HELP : Porting code from PIC16F877 to PIC18F452

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Eric Belanger
Guest







HELP : Porting code from PIC16F877 to PIC18F452
PostPosted: Wed May 26, 2004 8:21 am     Reply with quote

I was short of ROM space in the F877 so I had to upgrade to the F452... I'm using the PCH V3.200 compiler. I had V3.148 before I upgraded yesterday.

I'm having a hard time with the interrupts. I reduced my code to a simple toggling LED on RA4.

When there is no interrupt function defined (#INT_TIMER0), my MAIN program runs fine. But as soon as I put back a very simple interrupt function, the PIC don't seem to execute the MAIN code...

This code works:
#include "18F452.h"
#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWDT,NODEBUG
#USE FAST_IO(A)

BYTE gbyIntFlag;

void main()
{
Set_TRIS_A( 0b11101111 );

do
{
Output_Low(PIN_A4);
Output_High(PIN_A4);
}
while(1);
}

void TimeOutTickHandler( void )
{
gbyIntFlag = 1;
}


But with the #INT_TIMER0 directive the code doen't work anymore. I'm not even using the interupt function, there is no Enable_Interupts() directive in the code !

#include "18F452.h"
#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWDT,NODEBUG
#USE FAST_IO(A)

BYTE gbyIntFlag;

void main()
{
Set_TRIS_A( 0b11101111 );

do
{
Output_Low(PIN_A4);
Output_High(PIN_A4);
}
while(1);
}

#INT_TIMER0
void TimeOutTickHandler( void )
{
gbyIntFlag = 1;
}

I've been scratching my head on this problem for 2 days... Please help !

Eric
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Wed May 26, 2004 9:16 am     Reply with quote

I got this to work ok on my 18f452 board that came with PICC. It flashes the green led and it does interrupt ok.

When I compiled your first listing (3.188), I looked at the assembly and there was an infinite loop caused by the compiler. Look at your lst file and look for the interrupt, there was:

013a goto 013a

I don't know where that came from. I rearranged and used the wizard to come up with the following.

Code:
BYTE gbyIntFlag;

#INT_TIMER0
void TimeOutTickHandler( void )
{
gbyIntFlag = 1;
}
void main() {

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);

do
{
Output_Low(PIN_A5);
delay_ms(100);
Output_High(PIN_A5);
delay_ms(100);

}
while(1);
}
Code:
Ttelmah
Guest







Re: HELP : Porting code from PIC16F877 to PIC18F452
PostPosted: Wed May 26, 2004 9:25 am     Reply with quote

Eric Belanger wrote:
I was short of ROM space in the F877 so I had to upgrade to the F452... I'm using the PCH V3.200 compiler. I had V3.148 before I upgraded yesterday.

I'm having a hard time with the interrupts. I reduced my code to a simple toggling LED on RA4.

When there is no interrupt function defined (#INT_TIMER0), my MAIN program runs fine. But as soon as I put back a very simple interrupt function, the PIC don't seem to execute the MAIN code...

This code works:
#include "18F452.h"
#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWDT,NODEBUG
#USE FAST_IO(A)

BYTE gbyIntFlag;

void main()
{
Set_TRIS_A( 0b11101111 );

do
{
Output_Low(PIN_A4);
Output_High(PIN_A4);
}
while(1);
}

void TimeOutTickHandler( void )
{
gbyIntFlag = 1;
}


But with the #INT_TIMER0 directive the code doen't work anymore. I'm not even using the interupt function, there is no Enable_Interupts() directive in the code !

#include "18F452.h"
#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWDT,NODEBUG
#USE FAST_IO(A)

BYTE gbyIntFlag;

void main()
{
Set_TRIS_A( 0b11101111 );

do
{
Output_Low(PIN_A4);
Output_High(PIN_A4);
}
while(1);
}

#INT_TIMER0
void TimeOutTickHandler( void )
{
gbyIntFlag = 1;
}

I've been scratching my head on this problem for 2 days... Please help !

Eric

Did it work on 3.148?. Seriously, treat anything 'newer' than about 10 compiler versions ago, as a 'beta'. There are some really major problems with the compiler at present. Pull down 3.190, and try with this...
The code generated with 3.148, runs fine on my ICE, and happily toggles the A4 pin - big caveat here, you _must_ have a pull-up resistor on A4, it is an open collector output...

Best Wishes
Guest








PostPosted: Wed May 26, 2004 9:45 am     Reply with quote

Thanks guys for those fast replies...

I've been working with PIC's for the past 10 years, and YES there is a pull up on RA4 ! I agree this is a common error for beginners...

I tried to compile thsi code with V3.191. Doest not do any better. The RA4 output does not toggle:

Code:
#include "18F452.h"
#FUSES   HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWDT,NODEBUG
#USE     FAST_IO(A)

BYTE gbyIntFlag;

#INT_TIMER0
void TimeOutTickHandler( void )
{
   gbyIntFlag = 1;
}

void main()
{
   Set_TRIS_A( 0b11101111 );

   Enable_Interrupts(INT_TIMER0);
   Enable_Interrupts(GLOBAL);

   do
   {
      Output_Low(PIN_A4);
      Output_High(PIN_A4);
   }
   while(1);
}




As mentionned previously, it does work either with 3.200

If you get RA4 toggle with this code, please send the HEX file, I would like to try it directly. Maybe I have one on those old F452 with one of those hardware issues ... ;)

Eric
Eric Belanger
Guest







PostPosted: Wed May 26, 2004 9:51 am     Reply with quote

My chip has the folowing inscriptions : PIC18F452-I/PT 04033AE

Eric
[email protected]
Ttelmah
Guest







PostPosted: Wed May 26, 2004 10:08 am     Reply with quote

Eric Belanger wrote:
My chip has the folowing inscriptions : PIC18F452-I/PT 04033AE

Eric
[email protected]

Try the simple expedient, of adding some delays.
You may be hitting the read_modify_write problem at the speed that A4 is being driven. You don't mention the clock rate (except in using HS, which implies >4MHz), but given that A4's input is a schmidt trigger buffer, the pull-up, would need to be a very low value, even if the board capacitance is only a few pF. Try something like:
Code:

   do
   {
      Output_Low(PIN_A4);
      delay_cycles(10);
      Output_High(PIN_A4);
      delay_cycles(8);
   }
   while(1);


Best Wishes
bele2009



Joined: 24 Nov 2003
Posts: 2

View user's profile Send private message

PostPosted: Wed May 26, 2004 10:24 am     Reply with quote

Sorry, but it does not work either.

The pull-up is 560 Ohms. I checked with a scope on RA4 and all I see is a flat line...

Who ever tought a simple thing like that could be so frustrating !

Eric
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Wed May 26, 2004 12:28 pm     Reply with quote

This is definately pulsing A4. And interrupting.

Code:
#include <18F452.h>
#device ICD=TRUE
#device adc=10
#use delay(clock=20000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, STVREN, NODEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#zero_ram
#use fast_io(a)

BYTE gbyIntFlag;

#INT_TIMER0
void TimeOutTickHandler( void )
{
gbyIntFlag = 1;
}
void main() {

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   Set_TRIS_A( 0b11101111 );
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);

do
{
Output_Low(PIN_A4);

Output_High(PIN_A4);

}
while(1);
}

:020000040000FA
:0400000052EF00F0CB
:08000800FFFF056ED8CF06F0E2
:10001000E950076EEA50086EE150096EE2500A6E30
:10002000D9500B6EDA500C6EF350146EF450156EFE
:10003000E0500D6E000100500F6E0150106E025026
:10004000116E0350126E0450136EF2AA2BEF00F0E3
:10005000F2B44CEF00F00F50006E1050016E1150D2
:10006000026E1250036E1350046E0D50E06E0D8E32
:100070000750E96E0850EA6E0950E16E0A50E26ED0
:100080000B50D96E0C50DA6E1450F36E1550F46E9E
:10009000055006C0D8FF1000FFFF010E176EF29446
:1000A0002BEF00F0FFFFF86AD09E0D8EF20E006E6F
:1000B000060E016EEA6A020EE96EEF6AE92AD8B40A
:1000C000EA2A002E5DEF00F0012E5DEF00F0EA6AF3
:1000D000E96A060EC16E860EC16EC19CC250380B15
:1000E000C26E9698C69A949A94889496000EC66E9C
:1000F000C76ED190800ED56EEF0E926ECD6A000E57
:10010000016ECA6E000ECB6EB150480BB16EF28A12
:10011000C00EF212899889888AEF00F08EEF00F005
:020000040030CA
:0E00000000220C0E000101000FC00FE00F40A7
:00000001FF
;PIC18F452




P.S. I just edited to add the fast_io line.... still works.
bele2009



Joined: 24 Nov 2003
Posts: 2

View user's profile Send private message

PostPosted: Wed May 26, 2004 12:59 pm     Reply with quote

Thanks

I just programmed your HEX data with MPLAB and it works. With my custom programmer it does not. So I think we found the problem... Smile

So back to the drawing board for the programmer before complaining about the compiler and the chip !

I'll fix that and everything sould be ok then (I hope)

Eric
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group