|
|
View previous topic :: View next topic |
Author |
Message |
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
Pic18F87J94 bootloader. Downloaded firmware doesn't work. |
Posted: Fri Jul 06, 2018 7:29 am |
|
|
Hello
I have a firmware that works with a Pic18F87j94 and compiler version 5.025.
I am trying to put a bootloader and I use the CCS usb bootloader example.
I have modified the example putting my project fuses.
It works correctly and it is detected by computer and siow.exe software.
I compile the main firmware including usb_bootloader.h library.
I dowload the firmware into the pic with siow.exe software.
The problem is that now the firmware doesn't run correctly. I have checked interrupts and they are correct. It seems that it doesn't read correctly the input ports.
Any idea?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
|
Posted: Mon Jul 09, 2018 1:42 am |
|
|
Hello
I have tried your solution. It was actived IOL1WAY fuse. I have desactived but I have still the problem.
In mains program fuses I have put
Code: | #include <18F87J94.h>
#device ADC=10
#device PASS_STRINGS=IN_RAM
#case
#FUSES NONE
#use delay(internal=64M,USB_FULL) |
In bootloader I have put those one:
Code: | #include <18F87J94.h>
#build(stack=1024)
#FUSES NOWDT //***0.9++++++
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BROWNOUT_SW //Brownout controlled by configuration bit in special file register
#FUSES BORV18 //Brownout reset at 1.8V
//#FUSES PROTECT //Code protected from reads
#FUSES SOSC_LOW //Low-power SOSC circuit is selected******c
#FUSES NOCLOCKOUT //I/O function on OSC2
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOPLL
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
//#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
//#FUSES WPDIS //All Flash memory may be erased or written
//#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected //ISRA
//#FUSES NOWPCFG //Configuration Words page is not erase/write-protected
//#FUSES T5G_IS_T5G //Timer 5 Gate is driven by the T5G input
//#FUSES CINA_DEFAULT //C1INA and C3INA are on their default pin locations
//#FUSES ABW8 //8-bit Address bus
//#FUSES BW16 //16-bit external bus mode
//#FUSES NOWAIT //Wait selections unavailable for Table Reads or Table Writes
//#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
//#FUSES MSSP2MSK7 //MSSP2 uses 7 bit Masking mode
//#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
//#FUSES WDTWIN_25% //Watchdog Window is 25% of WDT period
//#FUSES WDTCLK_PERIPHERAL //WDT uses FOSC/4 as clock source
//#FUSES WINDIS //Watch Dog Timer in non-Window mode
//#FUSES NOVREGSLEEP //Ultra low-power regulator is disabled
//#FUSES VBATBOR //VBAT BOR Enabled
//#FUSES DS_SW
#FUSES SOSC_DIG //Digital mode, I/O port functionality of RC0 and RC1
#FUSES NOWPFP //Write/Erase Protect Page Start/End Location, set to page 0
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#use delay(internal=64M,USB_FULL)
#use fast_io(ALL) |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Mon Jul 09, 2018 3:13 am |
|
|
The #build line you show is fundamentally 'wrong'. The PIC18F87J94, does not support a software stack, so you can't expand it with a:
#build(stack=1024)
This option only applies for chips like PIC24/30's, which use the stack for variables, and not just return addresses and have a software stack pointer.
The option is _not_ in the PCH manual. Only in PCD.
Now you show your start of your main, but not whether you are building this to run with a bootloader?. You do realise that the main code has to be built 'offset' to load above the bootloader, if it is going to work?.
So you build the main with #include <bootloader.h> to provide this relocation, while the bootloader builds with:
Code: |
#define _bootloader
#include <bootloader.h>
|
You say you have done this, but have you at any point changed anything in the bootloader?. If so, the 'LOADER_SIZE' define will almost certainly need to have changed. You need to build the bootloader, check how large it is, and then set this to the end of the next erase page in the memory above this point, or things won't work....
Now that all having been said, one other thought would be that possibly you are building the bootloader with fast_io selected, and then not setting TRIS correctly in the main code.
Give a more detailed explanation of what the code actually does?.
For testing, have you successfully built the main, with the same fuses you now have in the bootloader, and had it working without the bootloader?. |
|
|
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
|
Posted: Mon Jul 09, 2018 6:59 am |
|
|
If I download the firmware without bootloader in the pic it runs ok with all the original fuses.
I tried to disable
#use fast_io(ALL)
and in this case it also runs ok
Then I make the bootloader firmware:
I have used "ex_usb_bootloader.c" example. I only have put my project fuses in "ex_usb_common.h" file (the same used in original code)
Code: | #if defined(USB_HW_CCS_PIC18F87J50)
#include <18F87J94.h>
#FUSES NOWDT //***0.9
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BROWNOUT_SW //Brownout controlled by configuration bit in special file register
#FUSES BORV18 //Brownout reset at 1.8V
#FUSES PROTECT //Code protected from reads
#FUSES SOSC_LOW //Low-power SOSC circuit is selected
#FUSES NOCLOCKOUT //I/O function on OSC2
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOPLL
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES WPDIS //All Flash memory may be erased or written
#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES NOWPCFG //Configuration Words page is not erase/write-protected
#FUSES T5G_IS_T5G //Timer 5 Gate is driven by the T5G input
#FUSES CINA_DEFAULT //C1INA and C3INA are on their default pin locations
#FUSES ABW8 //8-bit Address bus
#FUSES BW16 //16-bit external bus mode
#FUSES NOWAIT //Wait selections unavailable for Table Reads or Table Writes
//#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES MSSP2MSK7 //MSSP2 uses 7 bit Masking mode
#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
#FUSES WDTWIN_25% //Watchdog Window is 25% of WDT period
#FUSES WDTCLK_PERIPHERAL //WDT uses FOSC/4 as clock source
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES NOVREGSLEEP //Ultra low-power regulator is disabled
#FUSES VBATBOR //VBAT BOR Enabled
#FUSES DS_SW
#use delay(internal=64M,USB_FULL)
//#use fast_io(ALL)
#endif |
and in HW_INIT () I initialize the ports
Code: | #define HW_INIT() ConfigurarPuertos();
#byte PADCFG1=0xF54 //PADCFG1
#define PullUpH PADCFG1,3 //Habilitacion Pull-up en puerto H
void ConfigurarPuertos ()
{
output_a(0);
output_b(0);
output_c(0);
output_d(0);
output_e(0);
output_f(0);
output_g(0);
output_h(0);
output_j(0);
set_tris_a(0x00); //Puerto A (OUT)
set_tris_b(0x01); //Puerto B (IN 0, RESTO OUT)
set_tris_c(0x00); //Puerto C (OUT)
set_tris_d(0x0C); //Puerto D (OUT, 2,3-IN)
port_d_pullups(TRUE); //Resistencias de pull-up en puerto D ***c
set_tris_e(0x03); //Puerto E (0,1 IN, RESTO OUT)
port_e_pullups(TRUE); //Resistencias de pull-up en puerto E ***c
set_tris_f(0xFF); //Puerto F (IN)
set_tris_g(0xFF); //Puerto G (IN)
port_g_pullups(TRUE); //Resistencias de pull-up en puerto G ***c
set_tris_h(0xFF); //Puerto H (OUT/IN)
bit_set (PullUpH); //Forzamos porque CCS no lo tiene implementado
set_tris_j(0xF0); //Puerto J (IN/OUT)
port_j_pullups(TRUE); //Resistencias de pull-up en puerto H ***c
} |
And then I modify the button to enter into bootloader.
I downloaded the firmware and it is detected by siow.exe software.
In mains code:
I disable all the fuses
Code: | #include <18F87J94.h>
#device ADC=10
#device PASS_STRINGS=IN_RAM //para permitir copiar strings const en ram para emplear como entradas a funciones
#case // Will cause the compiler to be case sensitive.
#FUSES NONE
#use delay(internal=64M,USB_FULL)
//#use fast_io(ALL) |
and I include:
#include <usb_bootloader.h>
I have checked that bootloader firmware is less than 0x2000. It is about 0x1700.
I have debugged bootloader and it takes correct values:
LOADER_END: 0x1FFF
LOADER_SIZE: 0x2000
LOADER_START: 0x0000
APPLICATION_END: 0xFFEF
APPLICATION_START: 0x2000
APPLICATION_INTERRUPT: 0x2008 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Jul 09, 2018 9:44 am |
|
|
OK, I don't use that PIC or bootloader so just a comment.
1) when configuring ports using set_tris... and fast_io....) I'd do that first THEN output_xxx. You've got it the other way round, which may affect your external devices. When using 'standard_io(), the compiler configures the port everytime before you access it.
2) you've got #case enabled so perhaps there's something (like a variable or function) that is not working as expected ?
3) Normally you don't 'comment out' fuses, you either code:
#fuse fusenumberone
or
#fuse nofusenumberone
If you comment out a fuse, the compiler will probably code for what IT considers to be the default value, which may not be what you want !
I have ALL the fuses, one per line in a PICtype.fuz file and #include to access it. It allows me to have a good KNOWN set of fuses and cleans up the main() program visually.
Maybe something I offer will help.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Mon Jul 09, 2018 11:09 am |
|
|
One other comment.
You have ports using:
port_d_pullups(TRUE); //Resistencias de pull-up en puerto D ***c
Are you sure this is the right syntax for your chip?.
A lot of chips require you to set the pullups on a 'per pin' basis.
So:
port_d_pullups(0xFF); //Resistencias de pull-up en puerto D ***c
If your chip supports per pin settings, 'TRUE, will only be enabling the pull up on the bottom pin...
UPDATE.................
Have just checked the data sheet, and on this chip the pullups are on a 'per port' basis, so 'TRUE' will enable them all. One less thing to worry about.
Fuses by default always sit in their 'erased' state. So what a fuse goes to if you don't set it, depends on what the erased setting gives.
Realistically, the 'obvious' thing is that something about the settings used in the bootloader, is preventing some part of the hardware from initialising correctly. Something like a pin driven to a level, before the 'initialisation' code present in the 'main', which then results in a chip not initialising as expected. You need to think how all pins are driven during the bootloader phase. Honestly probably the best thing is to leave everything set as it is at 'boot', rather than making any settings in the bootloader. The bootloader need do nothing except read it's trigger pin (input is the default state for all pins), and should initialise nothing unless it is asked to operate. Even things like the USB init should not be called unless it is going to execute. |
|
|
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
|
Posted: Tue Jul 10, 2018 7:07 am |
|
|
Hello
Thank you very much for your time and suggestions
I have tried all of them without good results (standard_io, fast_io, fixed_io, fuses, pull-up values...)
In bootloader now I don't configure ports. I read only the push buttom to enter in bootloader mode.
I have minimized the code and in a while(1) bucle I active some leds and 7-segment display. It works but if I enable all the port reading code, leds start blinking. It is only when active all of them. Not for active some particular. I try to desactive one or other and it works. Only with all of them
Code: | if (input_state(IN_LREFRIGDETECT)==1)
Cont_REFRIG++; |
In the display I visualize some values to check if ports configuration are correct. TRIS and PADCFG1 (Pullup) registers are correct.
I have checked also analog registers. ANCON1 and ANCON2 register are correct but ANCON3 althought I configure with 0x07 value I read always 0xFF value (RH7-RH0 analogs).
I have forced this value but it doesn't change
I have put desired values in bootloader firmware but nothing
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Tue Jul 10, 2018 7:24 am |
|
|
Do a really basic test.
Simple main, that toggles a pin at perhaps 1 second intervals.
Choose a pin that can work with your hardware.
Compile this to load with the bootloader.
Load it.
Does the pin toggle?. At the right rate?.
I must admit I'd still suspicious that your 'main' code is not correctly being loaded by your bootloader. Or that the bootloader is not correctly jumping to the main code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue Jul 10, 2018 7:39 am |
|
|
Have to agree with Mr. T and do a basic test like he says.
What is confusing is how you say your main program worked 100% when 'burned' into the PIC yet fails when 'bootloaded' into the PIC.
As long as ALL the fuses are the same for the bootloader and main program and enough room is allowed for main to be loaded, I can't see why it doesn't work.
Also, pretty sure I saw you had enabled the 'PROTECT' fuse. While it shouldn't be the cause, it should be changed to NOPROTECT until the product is ready to leave the door( IE sold). |
|
|
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
|
Posted: Tue Jul 10, 2018 9:41 am |
|
|
Yes. This is what I have done.
I have left one timer interrupt and it actives a flag every one second to increment a counter. With this counter I switch on some leds sequentially. Also I active a 7-segment display. I can see messages in it.
When I enable the code to read inputs then I still can see the display message but leds start blinking. This leds are connected to PORTA.
It is very strange.
I have left USB initialization USB_Init();
perhaps I can test if I can run the program without it |
|
|
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
|
Posted: Wed Jul 11, 2018 3:13 am |
|
|
Hello
I have put a function like I use in reading ports library and it runs ok, with all of them. I have realised that if I declare the counters used in this library as global it works but if they are local then it fails.
If I don't include a GSM library that I was not using it works. Then I have enabled all the code without this GSM library but fails again. It can't read an external EEPROM. I had to disable it and usb communication. Then sometimes works but not correctly.
It seems that it is a problem with variables in RAM
I have also disable this line:
Code: | #device PASS_STRINGS=IN_RAM //para permitir copiar strings const en ram para emplear como entradas a funciones |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Wed Jul 11, 2018 3:46 am |
|
|
It has all the symptoms, that you have something in your code that is incorrectly using a pointer, and walking over memory beyond the end of an array. Changes that affect 'where' variables are placed in memory, then affect what gets damaged by this. So if you change variable declarations they move to areas that are not affected....
You need to look at absolutely everything you have written that writes to something using a pointer or an array, and verify that the index being used is legitimate. |
|
|
isgoy
Joined: 29 Mar 2012 Posts: 13 Location: Spain
|
|
Posted: Fri Jul 13, 2018 7:08 am |
|
|
Hello
I have reduced the firmware because it seems that it is a problem with ram variables. I have reduced it to have a minimum firmware where it fails. I have realised that if I declare some arrays the firmware makes something wrong. But without this declarations it runs ok. Then I reduced it to minimal and it also fails.
This is .c file
Code: | //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#define VERSIONBASE 10 //VERSION BASE
#define VERSION_DATOS_SOFTWARE 1 //VERSION DE LOS DATOS DE COMUNICACION CON SOFTWARE
#define ID_EQUIPO 21 //21-SAR714
#define ACABADO_EQUIPO 1
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#define CON_BOOTLOADER
//#define DEGUG_X_RS232
#include <SAR714.h>
#ifdef CON_BOOTLOADER
#include <usb_bootloader.h>
#endif
//Implementamos esto porque CCS no tiene contemplado la instrucion port_h_pullups(TRUE);
#byte PADCFG1=0xF54 //PADCFG1
#byte INTCON=0xFF2 //INTCON
#byte INTCON2=0xFF1
#byte INTCON3=0xFF0
#byte PIE1=0xF9D
#byte PIE2=0xFA0
#byte PIE3=0xFA3
#byte PIE4=0xFB4
#define PullUpH PADCFG1,3 //Habilitacion Pull-up en puerto H
void ConfigurarPuertos ()
{
output_a(0);
output_b(0);
output_c(0);
output_d(0);
output_e(0);
output_f(0);
output_g(0);
output_h(0);
output_j(0);
set_tris_a(0x00); //Puerto A (OUT)
set_tris_b(0x01); //Puerto B (IN 0, RESTO OUT)
set_tris_c(0x00); //Puerto C (OUT)
set_tris_d(0x0C); //Puerto D (OUT, 2,3-IN)
port_d_pullups(0xFF); //Resistencias de pull-up en puerto D
set_tris_e(0x03); //Puerto E (0,1 IN, RESTO OUT)
port_e_pullups(0xFF); //Resistencias de pull-up en puerto E
set_tris_f(0xFF); //Puerto F (IN)
set_tris_g(0xFF); //Puerto G (IN)
port_g_pullups(0xFF); //Resistencias de pull-up en puerto G
set_tris_h(0xFF); //Puerto H (OUT/IN)
bit_set (PullUpH); //Forzamos porque CCS no lo tiene implementado
set_tris_j(0xF0); //Puerto J (IN/OUT)
port_j_pullups(0xFF); //Resistencias de pull-up en puerto H
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// INICIALIZACION DE LOS CONTADORES DE LOS PULSADORES //
// Llamamos a esta función en la inicializacion de variables
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
void InicializarContadoresPulsadores(void)
{
BorraFlancos(); //Borramos los flancos de los pulsadores
EstadoPuertoPulsadorAnt=1; //Iniciamos en reposo
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// Funcion: Borra todo los flags de los flancos de los pulsadores
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
void BorraFlancos (void)
{
FlancoSubidaPulsador=0;
FlancoBajadaPulsador=0;
}
/*.................................................................................
PULSADOR ABAJO
Si se mantiene pulsado durante 1.5 seg se generan flancos automaticamente cada
100 mseg para incrementos rapidos automaticos
.....................................................................................*/
void pulsadorAbajo (void)
{
if (EstadoPuertoPulsador==0) //Miramos si esta pulsado
{
if (EstadoPuertoPulsadorAnt==1) //Si aux esta a 0, no hay flanco
FlancoBajadaPulsador=1; //Flanco de bajada en el puls.
EstadoPuertoPulsadorAnt=0; //Copiamos la entrada en el bit aux.
}
else
{
if (EstadoPuertoPulsadorAnt==0) //miramos si antes estaba pulsado
FlancoSubidaPulsador=1; //Flanco de subida en el pulsador
EstadoPuertoPulsadorAnt=1; //Copiamos la entrada en el bit. aux.
}
}
void LeerPuertos (void)
{
if (input_state(PULS_ABAJO)==1)
CONT_PABAJO++;
ContEntradas++; //Hemos tomado otra muestra de las entradas
if (ContEntradas==250) //VAlidamos las entradas con 250 muestras
{
ContEntradas=0; //Para el siguiente muestreo
ContPab=CONT_PABAJO;
EstadoPuertoPulsador=FiltroEntrada(&CONT_PABAJO);
}
}
unsigned int1 FiltroEntrada (unsigned int8 *cont_entrada)
{
if (*cont_entrada>128) //si esta a 1 más tiempo
{
*cont_entrada=0; //borramos el contador
return (1); //Esta más tiempo a 1
}
else
{
*cont_entrada=0; //borramos el contador
return (0); //Esta más tiempo a 1
}
}
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Funcion: actualizar los contadores que se incrementan cada 100ms
A esta rutina se la llama desde la interrupcion del timer cada 100ms
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void contadores100ms ()
{
if (IncCont100ms==1)
{
IncCont100ms=0; //Borramos para el siguiente
}
}
void contadores1seg ()
{
if (IncCont1seg==1)
{
ContSegundos++; //contador de segundos general
IncCont1seg=0; //borramos para el siguiente
}
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::
Interrupciones del timer
Se produce una interrupcion cada 0.256mseg
::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
//#int_TIMER0
#int_TIMER2
void TIMER2_isr(void)
{
ContTimer++; //incrementamos contador 0,256 ms overflow
switch (ContTimer)
{
case 390: //(195.3125) 100mseg...........
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 781: //(390.65) 200mseg.............
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 1172: //(585.93) 300mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 1562: //(781.25) 400mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 1953: //(976.56) 500mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 2344: //(1171.875) 600mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 2734: //(1367.1875) 700mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 3125: //(1562.5) 800mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 3516: //(1757.8125) 900mseg..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
break;
case 3906: //(1953.125) 1000mseg (999.936 mseg)..................
IncCont100ms=1; //Mandamos actualizar los contadores de 100mseg
IncCont1seg=1; //Mandamos actualizar los contadores de 1seg
ContTimer=0;
break;
}
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Funcion: Encender los Leds en funcion del programa
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void EncenderLeds (void)
{
// Leds.bits.Comunicacion=VARC; //Siempre apagado
// Leds.bits.Automatico=CtrlPantalla.bits.ActualizarPant; //Primero apagamos el led
LedsParticulares.bits.Stop2=input(PULS_ABAJO); //ISRA
LedsParticulares.bits.Stop1=input(PULS_MENOS);
LedsParticulares.bits.Start1=input(PULS_MAS);
LedsParticulares.bits.Start2=input(PULS_ARRIBA);
ApagarLedsValores ();
switch (NumeroPantalla)
{
case PANT_VELOCIDAD:
LedsParticulares.bits.Velocidad=1; //El led parpadea si estamos
break;
case PANT_BAT: LedsParticulares.bits.Bateria=1; break;
case PANT_HR: LedsParticulares.bits.Horas=1; break;
}
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::
// Apaga todos los leds bajo el display
//:::::::::::::::::::::::::::::::::::::::::::::::::::::
void ApagarLedsValores (void)
{
LedsParticulares.bits.Presion=0;
LedsParticulares.bits.Velocidad=0;
LedsParticulares.bits.Fuel=0;
LedsParticulares.bits.Bateria=0;
LedsParticulares.bits.Horas=0;
}
//Funcion de escritura de los puertos que no estan definidos en librerias.
//Es para evitar ampliar las estructuras de common_sve por una aplicacion particular
void EscribirPuertosParticulares (void)
{
#ifdef LED_FUEL
output_bit(LED_FUEL,!LedsParticulares.bits.Fuel);
#endif
#ifdef LED_RPM
output_bit(LED_RPM,!LedsParticulares.bits.Velocidad);
#endif
#ifdef LED_BAR
output_bit(LED_BAR,!LedsParticulares.bits.Presion);
#endif
#ifdef LED_HR
output_bit(LED_HR,!LedsParticulares.bits.Horas);
#endif
#ifdef LED_BAT
output_bit(LED_BAT,!LedsParticulares.bits.Bateria);
#endif
#ifdef LED_START2
output_bit(LED_START2,!LedsParticulares.bits.Start2);
#endif
#ifdef LED_STOP2
output_bit(LED_STOP2,!LedsParticulares.bits.Stop2);
#endif
#ifdef LED_ALARMPRES
output_bit(LED_ALARMPRES,!LedsParticulares.bits.AlarmaPresion);
#endif
#ifdef LED_STOP1
output_bit(LED_STOP1,!LedsParticulares.bits.Stop1);
#endif
#ifdef LED_START1
output_bit(LED_START1,!LedsParticulares.bits.Start1);
#endif
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// CAMBIO DE PANTALLA
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void cambio_pantalla()
{
if (FlancoSubidaPulsador==1) //Miramos si se pulsa solo el boton arriba
{
LedsParticulares.bits.AlarmaPresion =1;
if (VARC==1)
return;
VARC=1;
NumeroPantalla--; //pasamos a la anterior
if (NumeroPantalla==PANT_INICIAL) //Miramos si llegamos al inicio
{
NumeroPantalla=PANT_FINAL; //Pasamos a la final
NumeroPantalla--; //pasamos a la anterior activa
}
}
else
{
VARC=0;
LedsParticulares.bits.AlarmaPresion=0;
}
}
///////////////////////////////////////////////////////////////////////////////
//progrma principal
///////////////////////////////////////////////////////////////////////////////
void main()
{
ConfigurarPuertos ();
//Timer/RTCC....................
setup_timer_2(T2_DIV_BY_16,255,1); //256 us overflow, 256 us interrupt
//Interrupciones................
// enable_interrupts(INT_TIMER2);
// enable_interrupts(GLOBAL);
PIE1 = 0X02; //tmr2
PIE2 = 0X00;
PIE3 = 0X00;
PIE4 = 0X00;
INTCON = 0XC0;
INTCON2 = 0X00;
INTCON3 = 0X00;
ContTimer=0; //Contador de interrupciones por el timer
ContSegundos=0;
NumeroPantalla=PANT_INICIAL;
NumeroPantalla++;
memset (&LedsParticulares,1,sizeof (LedsParticulares));
//Apagamos los leds
LedsParticulares.bits.Presion=0;
LedsParticulares.bits.Velocidad=0;
LedsParticulares.bits.Fuel=0;
LedsParticulares.bits.Bateria=0;
LedsParticulares.bits.Horas=0;
LedsParticulares.bits.Start2=0;
LedsParticulares.bits.Stop2=0;
LedsParticulares.bits.AlarmaPresion=0;
LedsParticulares.bits.Stop1=0;
LedsParticulares.bits.Start1=0;
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// BUCLE PRINCIPAL
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
while (1)
{
SalSirena =0; //isra
if (ContTimer>2000)
SalSirena =1;
output_bit(SIRENA_INT,SalSirena);
LeerPuertos();
pulsadorAbajo(); //Lectura de pulsadores
contadores100ms (); //incrementar los contadores de 100 mseg
contadores1seg (); //incrementar los contadores de 1 seg
cambio_pantalla();
EncenderLeds();
EscribirPuertosParticulares();
BorraFlancos ();
}
}
|
And this .h file
Code: | #include <18F87J94.h>
#device ADC=10
//#device PASS_STRINGS=IN_RAM //para permitir copiar strings const en ram para emplear como entradas a funciones
#case // Will cause the compiler to be case sensitive.
#ifdef CON_BOOTLOADER
#FUSES NONE //Fusibles en el bootloader
#else
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG //ISRA
#FUSES BROWNOUT_SW //Brownout controlled by configuration bit in special file register
#FUSES BORV18 //Brownout reset at 1.8V
#FUSES NOPROTECT //Code protected from reads //ISRA
#FUSES SOSC_LOW //Low-power SOSC circuit is selected
#FUSES NOCLOCKOUT //I/O function on OSC2
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOPLL
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES WPDIS //All Flash memory may be erased or written
#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES NOWPCFG //Configuration Words page is not erase/write-protected
#FUSES T5G_IS_T5G //Timer 5 Gate is driven by the T5G input
#FUSES CINA_DEFAULT //C1INA and C3INA are on their default pin locations
#FUSES NOEXTADDRSFT
#FUSES ABW8 //8-bit Address bus
#FUSES BW16 //16-bit external bus mode
#FUSES NOWAIT //Wait selections unavailable for Table Reads or Table Writes
#FUSES NOIOL1WAY
//#FUSES LS24MHZ //ISRA CUAL?
#FUSES LS48MHZ
#FUSES MSSP2MSK7 //MSSP2 uses 7 bit Masking mode
#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
#FUSES WDTWIN_25% //Watchdog Window is 25% of WDT period
#FUSES WDTCLK_PERIPHERAL //WDT uses FOSC/4 as clock source
#FUSES NOWDT //***0.9
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES NOVREGSLEEP //Ultra low-power regulator is disabled
#FUSES VBATBOR //VBAT BOR Enabled
#FUSES DS_SW
#FUSES DSWDT_16SEC //ISRA AÑADIDO
#endif
#use delay(internal=64M,USB_FULL)
#use fast_io(ALL)
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Definición de variables
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
unsigned int8 ContSegundos; //contador de segundos general
unsigned int16 ContTimer; //Contador de interrupciones por el timer
unsigned int8 P1[100]; //isra
unsigned int8 P2[100];
unsigned int8 P3[100];
unsigned int8 P4[100];
unsigned int8 P5[100];
unsigned int8 P6[100];
unsigned int8 VARC;
unsigned int8 ContPab;
unsigned int8 ContEntradas; //Contador para validar las entradas
unsigned int8 CONT_PABAJO;
unsigned int8 ContPulsAbajo; //Contador para ver que se mantiene pulsado el boton abajo(0.1seg)
unsigned int1 EstadoPuertoPulsador;
unsigned int1 EstadoPuertoPulsadorAnt;
unsigned int1 FlancoBajadaPulsador;
unsigned int1 FlancoSubidaPulsador;
unsigned int1 IncCont100ms;
unsigned int1 IncCont1seg;
unsigned int1 SalSirena;
unsigned int8 NumeroPantalla;
typedef struct
{
int Fuel :1; // Estado del Led de Fuel 0: Off 1:On
int Velocidad :1; // Estado del Led de velocidad 0: Off 1:On
int Presion :1; // Estado del Led de presion 0: Off 1:On
int Horas :1; // Estado del Led de horas 0: Off 1:On
int Bateria :1; // Estado del Led de batería 0: Off 1:On
int Start1 :1; // Estado del Led de start1 0: Off 1:On
int Stop1 :1; // Estado del Led de stop1 0: Off 1:On
int Start2 :1; // Estado del Led de start2 0: Off 1:On
int Stop2 :1; // Estado del Led de stop2 0: Off 1:On
int AlarmaPresion :1; // Estado del Led de la habilitacion de la alarma de presion 0: Off 1:On
int :1; //
int :1; //
int :1; //
int :1; //
int :1; //
int :1; //
} BitsLedsParticulares;
typedef union
{
BYTE octetos[2];
BitsLedsParticulares bits;
} SalidaLedsParticulares;
SalidaLedsParticulares LedsParticulares;
void ConfigurarPuertos ();
void contadores100ms ();
void contadores1seg ();
void ApagarLedsValores (void);
void cambio_pantalla();
void EncenderLeds (void);
void LeerPuertos (void);
unsigned int1 FiltroEntrada (unsigned int8 *cont_entrada);
void LecturaPulsadores (void);
void ContadoresPulsadores(void);
void InicializarContadoresPulsadores(void);
void BorraFlancos (void);
void pulsadorAbajo (void);
//Definicion de las salidas.......................
#define SIRENA_INT PIN_C3
#define LED_FUEL PIN_A4 //No se usa. Ponemos el que es el de HR en el SAR716 para apagarlo
#define LED_BAR PIN_A2 //No se usa. Lo apagaremos
#define LED_COMUNIC PIN_A3 //No se usa. Lo apagaremos
#define LED_RPM PIN_A1 //Esta en el mismo sitio
#define LED_HR PIN_A5 //Coge la posicion de BAT
#define LED_BAT PIN_A0 //Coge la posicion de FUEL
#define LED_AUTO PIN_B7
#define LED_START2 PIN_A6
#define LED_STOP2 PIN_A7
#define LED_ALARMPRES PIN_C2
#define LED_STOP1 PIN_C6
#define LED_START1 PIN_C7
#define DISPLAY_SEG_A PIN_B5
#define DISPLAY_SEG_B PIN_D7
#define DISPLAY_SEG_C PIN_J1
#define DISPLAY_SEG_D PIN_J3
#define DISPLAY_SEG_E PIN_B1
#define DISPLAY_SEG_F PIN_B4
#define DISPLAY_SEG_G PIN_J0
#define DISPLAY_SEG_UC PIN_J2
#define DISPLAY_SEG_LC PIN_J2
#define DISPLAY_SEG1 PIN_C5
#define DISPLAY_SEG2 PIN_C4
#define DISPLAY_SEG3 PIN_B3
#define DISPLAY_SEG4 PIN_B2
#define PULS_MENOS PIN_J4
#define PULS_MAS PIN_J5
#define PULS_ABAJO PIN_J6
#define PULS_ARRIBA PIN_J7
//Definicion de las pantallas..................
#define PANT_INICIAL 0 //Marca el inicio de las pantallas
#define PANT_VELOCIDAD 1
#define PANT_BAT 2
#define PANT_HR 3
#define PANT_FINAL 4 //marcamos la ultima pantalla a mostrar de normal
#define PANT_HORARIA 5 //Pantalla del reloj |
In this firmware I read a pushbutton (Abajo) and when it detects a change in its state then change "NumeroPantalla". With NumeroPantalla value I switch different leds.
If I declare P1..P6 arrays then it seems that it doesn't read correctly the pushbutton port because I see that switched on led changed without pushing it.
I have tried to change FiltroEntrada function not using pointers and it also fails.
I have tried to enable manual interruptions and it also fails
.......
I don't know What to do
thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Fri Jul 13, 2018 2:17 pm |
|
|
I must admit I'd be starting to be suspicious about your compiler version. 5.025, is an old compiler, and I do remember there being some issues with large RAM usage back with these early V5 compilers. |
|
|
|
|
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
|