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 support@ccsinfo.com

Migration between PIC18F4550 and PIC24FJ64GA006
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Pichuqy_1



Joined: 03 Aug 2010
Posts: 38

View user's profile Send private message MSN Messenger

Migration between PIC18F4550 and PIC24FJ64GA006
PostPosted: Sat Oct 19, 2019 6:41 pm     Reply with quote

Hello everyone.

I have a program made in PIC18F4550 and I need to pass it to PIC24f.
From what I could learn, migration is not direct and I need to change many things. I was able to solve many, but not all.

I would like to ask some questions:

Does the data type change? I have errors of this type:







Can I use the same graphic library? Apparently, they are just data type errors, but I can't remove them.

HDM64GS12.c


The same problem for the keyboard library.

kbd_lib.c


The library for writing / reading the internal EEprom (internal_eeprom.c) is not compatible with this microcontroller model, right?





Thank you very much for your help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Sat Oct 19, 2019 10:49 pm     Reply with quote

Try actually looking at your post.
All the included bits are not visible. Doesn't help us to see what you are
asking..... Sad

General comments:

The PIC24 you list does _not_ have internal EEPROM. So 'of course'
the internal EEPROM functions won't work. Choices are:
1) Use an external EEPROM or
2) Use the 'virtual eeprom' driver.
The latter simulates EEPROM behaviour using a couple of pages of
the flash program memory.

Now data types. This is where being explicit helps. If your code uses
explicit types it'll convert directly. Load stdint.h, and use uint8_t etc.,
and the types will work on both families. However it you have been
making assumptions and using default types like 'int', everything
changes. On the PIC24, the default 'int' is 16bit, and everything
defaults to signed instead of the unsigned default on the PIC16/18.
temtronic



Joined: 01 Jul 2010
Posts: 9114
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 20, 2019 7:30 am     Reply with quote

I have to wonder WHY the
.000030517578125 number is in the code ?
It's highly unlikely the PIC can accurately use it.

Then I 'd like to know why the migration to a PIC24 device. I'm thinking maybe speed ? though scaled integers beat floats everyday of the week.

just curious
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Sun Oct 20, 2019 8:52 am     Reply with quote

My comment about looking at the post no longer applies. The files are
now visible. I think the sharing site you have used took a while to actually
make them available so when I looked at first the files were not showing...

You don't show the processor setup and include.

Now, the processor include file defines the byte and int1 types. So many
of your errors will disappear once this is loaded correctly.
sprintf is defined in string.h. Suggests this is also not being loaded.

So most of your problems are just in the setup you are using to load the
files.

There are a couple 'left' though. First is CCP. The PIC24 does not have
a CCP peripheral. On the PIC24, this is done by two separate peripherals.
The input capture unit, and the output compare unit. You need to use
whichever you need and change the setups to match.
The EXT interrupt, is EXT1, EXT2 etc., on the PIC24.

Peripheral setups will always be different. You need to look at what the
options are for the PIC24 timer. It has far more options than the PIC18
one, but with that comes changes in the values needed to configure it.
Pichuqy_1



Joined: 03 Aug 2010
Posts: 38

View user's profile Send private message MSN Messenger

PostPosted: Sun Oct 20, 2019 7:18 pm     Reply with quote

Hello everyone. Thanks for your comments.

Ttelmah:
The reason I changed my microcontroller is because I ran out of program memory, and the only PIC I have available with more memory is the 24FJ64GA006.
The number .000030517578125, comes by default in the library MATH.h. My intention was to show the errors in the definition of variables (float32), which I believe are due to the type of data.

temtronic:
I really didn't know that this microcontroller hadn't internal eeprom. I was very surprised. I already removed it from the main code and I will add an external memory.
What isn't clear to me, is how to configure the interruption by change of state on pin RB0. Does the nomenclature starts from EXT1 in PIC24?



This is the main file:
Code:

#include "24FJ64GA006.h"                   //pic a utilizar

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES ICSP2                    //ICD uses PGC2/PGD2 pins
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
//#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES PR                        //Pimary oscillaotr disabled

#use delay(clock=20000000)

#use STANDARD_IO(B)
#use STANDARD_IO(C)
#use STANDARD_IO(D)
#use STANDARD_IO(E)
#use STANDARD_IO(F)
#use STANDARD_IO(G)

#BYTE INTCON3 = 0xFF0
#BYTE PIR1 = 0xF9E   //Peripheral interruption signaling control register

#include "MATH.h"
#include "stdlib.h"
#include "HDM64GS12.h"
#include "GRAPHICS.h"
#include "flex_kbd_4x4.h"
#include "DS3231_libreria_2.h"
#include "clabe_acceso_lcd_grafico.h"
#include "ds3231_configuracion_lcd_grafico.h"
#include "dia_semana.h"
#include "conf_timer.h"
//#include "internal_eeprom.h"
#include "TMR.h"


char valor_lm35[10];

long medicion,datox,dato;

int reset=0x00;
int cambio=0,automatico=0x00;                        
int control_teclado=0x00;    //It is used so that the menu cannot be selected again.

int bandera_backlight=0;
static int last=0;
int current;
int int_rb_1=0;
int bandera_conf=0;


char logo_1[]="SUNDAY";
char logo_2[]="MONDAY";


#int_EXT                  
ext_isr(void)               {
if(cambio==0){
cambio=1;
output_low(PIN_B13);
ext_int_edge(H_TO_L);
}
else{
cambio=0;
ext_int_edge(L_TO_H);
output_high(PIN_B13);
//suma_segundos ++;                  
borra=1;
}
}

#int_EXT1                  
ext_isr1(void)
{
if(bandera_conf==1){                                           
//bandera_conf=0;                                               
if((seleccion_menu_1 >= 3)){                           
seleccion_menu_1=0;
         }

seleccion_menu_1 = seleccion_menu_1 + 1;
delay_ms(250);
         }         
   
else{ 
if((seleccion_menu >= 7)){                           
seleccion_menu=0;
         }

seleccion_menu = seleccion_menu + 1;
delay_ms(100);
CONF_DIA_SEMANA();
    }
}


#int_EXT2   
ext_isr2(void)               
{
if(bandera_conf==1){                                    //El pirmer IF se utiliza para configurar el menu de los TIMER
                                                            //El else se utiliza para configurar el menu de los DIAS
if((seleccion_menu_1 <= 0)){                        //Tope maximo para elegir la cantidas de minutos de activación 15 min a 3 horas
seleccion_menu_1=3;
         }

seleccion_menu_1 = seleccion_menu_1 - 1;
delay_ms(250);
   
    }
 
else{   
if((seleccion_menu <= 0)){                           
seleccion_menu=8;
         }

seleccion_menu = seleccion_menu - 1;
delay_ms(100);
CONF_DIA_SEMANA();
    }
}   


///PROGRAMA
void main(void)
{
//    setup_ccp1(CCP_CAPTURE_RE);
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);                  //La frecuencia a la que el timer realiza un paso: 20000000/4/8= 0.0000016;
      
   
   disable_interrupts(INT_TIMER1);
//   disable_interrupts(INT_CCP1);
   disable_interrupts(INT_EXT);
   disable_interrupts(INT_EXT1);
   disable_interrupts(INT_EXT2);
   enable_interrupts(GLOBAL);
   
   ext_int_edge(L_TO_H);                                 //Configuracion INT_EXT de nivel alto a bajo  RB0   
   ext_int_edge(1,L_TO_H);                                 //Configuración INT_EXT1 de nivel alto a bajo RB1
   ext_int_edge(2,L_TO_H);                                 //Configuración INT_EXT2 de nivel alto a bajo RB2
   

//   setup_adc_ports (AN0|VSS_VDD);           
//     setup_adc(ADC_CLOCK_DIV_2);                                   //enciende adc
//     set_adc_channel(0);                                             //elige canal a medir RA0

    glcd_init(ON);

//#rom int8 0xF00004={'1','2','3','4'};                        //ver http://www.ccsinfo.com/forum/viewtopic.php?p=42027
//#rom int8 0xF00008={0x00};                              //ver http://www.forosdeelectronica.com/f24/programador-pic-18f2550-poder-montar-despues-pickit2-clone-40738/



////////////////////////////////////////////////////////////////////////////////////
reset=read_eeprom(0x08);                                  
//if(reset==0x00){                                    //CLABE DE ACCESO, no ingresa al programa hasta que no sea correcta.
                                                                //El if se realiza para que solo ingrese a la clabe cuando el equipo se agapa.
//INICIO_CLABE_ACCESO();                                 //Si el equipo se resetea utilizando la letra "D", no se ingresa a la CLABE
//   }
//write_eeprom(0x08,0x00);
//////////////////////////////////////////////////////////////////////////////////// 
//delay_ms(1000);  // wait a second
 
OSC_Start();
Disable_32kHZ();
IntSqw_Set(OUT_1Hz);                  // enable SQW output with frequency of 1Hz
 
//RTC_Set(mytime);                      // write time and date to the RTC chip
   
glcd_fillScreen(OFF);                              //Borramos  LCD
 
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT1);
enable_interrupts(INT_EXT2);

CONF_DIA_SEMANA();

do{ 
if(borra==1){                     //En este if se entra cuando se termina de realizar la interrupción por RB0                                 
mytime=RTC_Get();                       // read current time and date from the RTC chip                               
                               //Se actualiza lectura de reloj

delay_ms(100);                          // wait 100 ms
glcd_rect(0,0,70,6,1,OFF);            //Borramos minutos horas segundos
sprintf(valor_hora,"%02u:%02u:%02u",mytime->hours,mytime->minutes,mytime->seconds);          //imprime la variable 
glcd_text57(0,0,valor_hora,1,1);
sprintf(valor_hora,"%02u/%02u/20%02u",mytime->day ,mytime->month,mytime->year);          //imprime la variable
glcd_text57(60,0,valor_hora,1,1);
//chip_temp = Get_Temperature();     // read chip temperature
//rtc_print();                       // print all data
borra=0;                                             //Variable para controlar el fin de la interrupcion. Cuando Se termina de ejecutar todo, se pone                                          //la variable de control en 0, asi solo se va a ingresar cuando la interrupcion por RB0 llege

}                                    
//a su fin, osea que pasó un segundo.


//glcd_text57(0,54,D,1,1);
k=kbd_getc();
switch (k){

case 'D':
CONFIGURACION();                                    
//Se configura la hora del reloj de tiempo real.
break;


case 'C':
bandera_conf =1;
CONFIGURACION_ENCENDIDO_APAGADO();      
    //Se configura cada día con su TIMMER.
break;
}

}while(TRUE);

}

I managed to reduce errors to this:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 20, 2019 8:08 pm     Reply with quote

Pichuqy_1 wrote:

I managed to reduce errors to this:

Setup_timer_1
INT_EXT
INT_EXT

You have minor spelling or syntax errors. If you looked in the .h file for
your PIC, you would see the answers immediately.
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Mon Oct 21, 2019 12:08 am     Reply with quote

Setup_timer_1 -> setup_timer1
INT_EXT -> INT_EXT0

Beware (of course), that the frequency fed to a timer, is FOSC/2 on
a PIC24, against FOSC/4 on a PIC18. Anything timer based will need to
have timings adjusted.

#FUSES PR //Pimary oscillaotr disabled

Comment on this line is wrong. Actually the primary oscillator is enabled.
It needs to be....

#BYTE INTCON3 = 0xFF0
#BYTE PIR1 = 0xF9E //Peripheral interruption signaling control register

Wrong. This chip does not have an INTCON3 register. The address you are
using will be into the standard RAM.
Pichuqy_1



Joined: 03 Aug 2010
Posts: 38

View user's profile Send private message MSN Messenger

PostPosted: Mon Oct 21, 2019 4:39 pm     Reply with quote

Thank you for your answers.

I am finishing with the compilation and now, I have problems with the functions. With the PIC18F4550 the program was compiled perfectly, but not now.
I still don't understand the reason why the conflict with the functions.
Is the definition of functions different for PIC24?

Where can I learn how to solve this problem? Embarassed Embarassed
I know that my programming is not the best, but I am trying to improve it.




This is the main.c where I call the two functions.


This is one of the functions.


This is the other
newguy



Joined: 24 Jun 2004
Posts: 1902

View user's profile Send private message

PostPosted: Mon Oct 21, 2019 4:47 pm     Reply with quote

One thing to watch out for: the 8 bit compilers (PCB, PCM and PCH) all treat integers as *unsigned* by default. The 16 bit compiler treats integers as *signed* by default.

When I migrated a working project from a PIC18 to a dsPIC I learned this little tidbit the hard way. It's also, coincidentally, the reason why I now *always* explicitly declare whether a variable is signed or unsigned no matter what.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 21, 2019 7:59 pm     Reply with quote

Why are you highlighting "CONFIGURACION_ENCENDIDO_APAGADO()" ?
It's not listed as an error.

The only function listed as an error is "CONFIGURACION()". You are
getting the "Function used but not defined" error.

This error occurs if you have a function prototype for CONFIGURACION()
but you don't have the actual function declaration anywhere in your
program. It might be in a file, but you forgot to #include the file.
Pichuqy_1



Joined: 03 Aug 2010
Posts: 38

View user's profile Send private message MSN Messenger

PostPosted: Mon Oct 21, 2019 10:01 pm     Reply with quote

I can't figure out what is going on with this.

I have not forgotten to add the .h files. The next photo shows it.


PCM programmer wrote:

"Why are you highlighting "CONFIGURACION_ENCENDIDO_APAGADO()" ?
It's not listed as an error."

For both functions it shows me the same error, but I don't understand why it only shows me one at a time.

There is something I can't understand with the definition of functions. Notice how the error translates when I comment on the function // CONFIGURATION () ;.

[/img]


I really don't know what to do now. I think I'm going to have to look for a PIC18 with more program memory.
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Tue Oct 22, 2019 1:31 am     Reply with quote

The problem is almost certainly 'types'. On the PIC18, byte, int, char are
all accepted as the same type. On the PIC18, they differ. int, is a signed int16,
char is a signed int8, byte is an unsigned int8. Now it is saying the function
is not defined, because it cannot find a function definition, with the variables
required that matches how it is actually being called. I had this when using
some functions that used byte, and the actual call was using char.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 22, 2019 12:02 pm     Reply with quote

Also we see something not good. In the bottom left corner of the first
image, we see:
Quote:
Compiler Toolchain: CCSC vs. 5.009

Red flag.
Pichuqy_1



Joined: 03 Aug 2010
Posts: 38

View user's profile Send private message MSN Messenger

PostPosted: Tue Oct 22, 2019 4:16 pm     Reply with quote

Sorry, but I don't understand. Is there something wrong with the compiler version?
newguy



Joined: 24 Jun 2004
Posts: 1902

View user's profile Send private message

PostPosted: Tue Oct 22, 2019 4:49 pm     Reply with quote

Yes, "inside information" for those of us who have used the compiler for many years. Version 5 was initially very unreliable and riddled with bugs. Somewhere after your version (not sure exactly) was when version 5 approached being usable. As for myself, at the time version 5 became available, I stuck with version 4.099 for as long as I possibly could, then started to use version 4.141 because it supported a dsPIC I was using that 4.099 didn't.

I do remember watching the "chatter" here regarding version 5 and thinking "I'm not upgrading yet."
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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