TODOPIC
Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: Tec_Claudio_Perez en 04 de Enero de 2012, 13:28:46
-
Hola a todos,
Tengo una estructura con doce variables adentro (Tipo_timer), después con esto armé un vector de 100 elementos.
Con otra variable "i" intento acceder a cada elemento para evaluarlo pero por alguna razón no me sale. Que estoy haciendo mal ?
typedef struct {
//struct Tipo_timer {
BOOLEAN Enable; // Habilita el temporizador.
BOOLEAN Res1ms; // Resolucion del temporizador de 1ms.
BOOLEAN Res10ms; // Resolución del temporizador de 10ms.
BOOLEAN Res1seg; // Resolución del temporizador de 1seg.
BOOLEAN TON; // Temporizador de Retardo a la conexión.
BOOLEAN TOF; // Temporizador de Retardo a la desconexión.
BOOLEAN TP; // Temporizador por impulsos.
BOOLEAN I; // Entrada del temporizador.
BOOLEAN IAnt; // Estado anterior de la entrada del temporizador.
BOOLEAN Q; // Salida del temporizador.
int16 ACC; // Acumulador del temporizador.
int16 PRESET; // Preset del temporizador.
} tipo_timer;
//Se disponen de 100 temporizadores.
tipo_timer T[100];
void main() {
int8 i;
//Aqui inicializo el elemento 2.
T[2].Enable=TRUE;
T[2].TON=TRUE;
T[2].Res1ms=TRUE;
T[2].PRESET=500;
T[2].ACC=0;
//Esta parte funciona bien, me ejecuta Q3=1.
if (T[2].Enable==TRUE) {
Q3=1;
}
else {
Q3=0;
}
//Esta parte no funciona, debería hacer Q4=1, pero ejecuta Q4=0.
i=2;
if (T[i].Enable==TRUE) {
Q4=1;
}
else {
Q4=0;
}
Probé declarar la variable i de varias formas, y también cambiar la estructura, pero nada. La versión de mi compilador es la 4.104 y lo estoy probando en un PIC18F4550.
Saludos a todos y gracias.
-
Y que error marca? porque dándole una mirada rápida no se ve nada raro :tongue:
-
Eso estaba por preguntar, ademas en la lista de actualizaciones no menciona algo que indique este problema...
RECENT CHANGES
4.128 A typecast inconsistancy with ANSI for 24 bit parts is fixed
4.128 A device database problem with EP chips is fixed
4.127 A bug in the handling of PIC24 bit arrays is fixed
4.127 Fuses and registers for the newest parts have been updated.
4.126 Default parameters (broke in 4.125) are now back
4.126 A problem with some PIC24 bit arrays is fixed
4.126 An optimization bug with PIC24 parts is fixed
4.126 A RAM allocation problem with EP chips is fixed
4.125 Support for the new enhanced 24 bit opcodes is added(PIC24EP parts)
4.125 Some issues with PIC18 ROM pointers have been resolved
4.125 A problem with type conversion within the PCD >> and << operators is fixed
4.125 Linking problems caused by extern references to const's is fixed
4.124 PCW Wizard was not starting right in 4.123. It is now fixed.
4.123 Various PIC24 optimization errors have been corrected
4.123 New feature to stream RS232 data through the ICD has been added
4.123 Some register addresses have been fixed for some of the new parts
4.123 Problems selecting the alternate ICD pins on some parts is now fixed
4.122 An IDE error (List Index Out of Bounds) is fixed
4.122 Problems with complex pointers to ROM have been fixed
4.122 A bug in the handling of pointers in enhanced 16 parts is fixed
4.122 A rare problem with the PIC24 signed multpily on 48 and 64 bit numbers is fixed
4.121 A problem with PIC24 initialization and optimization in very large programs is fixed
4.121 A linker problem is fixed that caused errors like "hidden reference"
4.120 Timer A and Timer B support has been added for chips that have them
4.120 New fuses were added for the newest chips and a few fuses were changed for consistancy
4.120 Built in functions have been updated for the new features in the K22 parts
4.120 A bug in the make16() for some arguments and chips is fixed
4.120 PIC24 parts with abnormal PPS register locations now work with #PIN_SELECT
4.120 The subscript notion [][xx] now works for data declarations
4.120 The wrong register being used for IOCB on some parts is now fixed
4.120 Some PIC24 code generation bugs have been fixed
4.120 Some problems with the register export in the device editor have been fixed
4.119 A PIC24 optimization bug is fixed
4.119 A problem with addressmod in some recent versions is fixed
4.119 Improved time and precision on trig functions
4.118 A bug in the PIC24 %U is fixed
4.117 A memory allocation problem for enhanced 16 parts around xA0 is fixed
4.117 A bug in complex expresions involving != or == for PCD is fixed
4.117 The #TYPE SIGNED directive now also affects char declarations
4.117 An undeserved error from SPI_XFER in PCM/PCH is fixed
4.116 A corrupt device database released with 4.115 is fixed
4.115 PCD SPI defines SPI_XMIT... have been modified to operate the same as PCM and PCH
4.115 A number of device database errors have been fixed
4.115 A PIC24 bug with &= on 32 bit operands is fixed
4.115 New #USE TIMER library added
4.114 An internal error with some bit expresions is now fixed
4.113 Using = to assign a constant string to a RAM array is now allowed
4.113 Corrected a bug dealing with bits in byte expresions
4.113 A lot of chip specific updates to work around qwerks and new features
4.112 Some ROM allocation problems when using the ROM typemod have been fixed
4.112 Added QEI functions for PIC18 parts
4.112 Corrected some problems with register names in the device database
4.111 A problem with PIC24 ROM pointers inside RAM structures has been fixed
4.111 Some missing configuration fuses have been restored
4.110 Peripheral interface for a number of chips have been updated
4.110 size_t has been changed to help with large malloc's
4.109 Some errors in some device header files have been fixed
4.109 PIC18 INT_LVD is now renamed to INT_HLVD
4.108 Built in functions, device database and header files updated for the newest parts
4.108 PIC18 bug involving int32's in complex expresions is fixed
4.108 Some issues with PIC24 structure bit fileds in expresions are fixed
4.107 Built in functions, device database and header files updated for the newest parts
4.107 Programmer support for PIC32 added and PIC24 programming is now much faster
4.106 Missing timer 1 defines for some chips have been restored
4.106 Some optimization problems with indirect access of bit fields on 24 bit parts is fixed
4.106 Load time for 24 bit parts has been greatly improved
4.105 Peripheral interface for a number of chips have been updated for the newest features
4.105 A problem with -> accross differing address spaces is fixed
4.105 PCD problem with %w is fixed
4.105 The PCD #USE SPI now correctly sets the standard modes
4.105 printf has been improved for programs that also use interrupts
4.104 SHORT INT is now the same as SHORT and INT1 as it was in earlier versions
4.104 Problems with printf redirection to functions that use ptr registers is fixed
4.104 Some problems with complex structure pointers are fixed
4.104 PCD SPI MODE= fixed to match documentation
4.103 A problem with somE initializers (the = in a declaration)is fixed
4.102 Some issues with pointers to ROM have been fixed
4.102 Compiler status window now shows worst case RAM use not best case
4.101 Internal error on some projects that use dual priority interrupts is fixed
4.101 INT_RA not defined on some parts is now fixed
4.100 New command line option sourceline= to add a source line to the start of the file
4.100 Dereferencing of function pointers is no longer required
4.100 New preprocessor function definedinc() may be used to determine the use of a C identifier
4.100 enable_interrupts() may now be used to set the edge detection on interrupts that allow it
4.100 A new function INPUT_CHANGE_x may be used to find port pins that have changed
4.100 #build/#export expanded to improve interfacing to bootloaders and resident libraries
4.100 New example set API.ZIP added to show how to use the new #build/#export features
4.100 time_t changed to rtc_time_t in the device header files, time.h not changed
4.099 A problem with interrupts corrupting port A on some par
-
El programa compila bien, no genera ningun error.
Pero hay un error de ejecución en esta parte:
//Esta parte no funciona, debería hacer Q4=1, pero ejecuta Q4=0.
i=2;
if (T[i].Enable==TRUE) {
Q4=1;
}
else {
Q4=0;
}
Deberia ejecutar Q4=1, pero por alguna razon ejecuta Q4=0
-
Y en realidad sabes que valor toma i en ese momento??
Porque no la declaras como variable global??
O sea antes del main(), tal vez el llamado no digiera ser hecho desde una variable local...
-
Y en realidad sabes que valor toma i en ese momento??
:roll: En el ejemplo coloca i = 2... Puede, nada raro, ser un bug :tongue:
Porque no la declaras como variable global??
O sea antes del main(), tal vez el llamado no digiera ser hecho desde una variable local...
No tiene sentido
-
En realidad originalmente era global, porque también accedia al vector en una rutina de interrupción, pero tampoco funciona bien, ni como global ni como local. Alguien puede corroborar que es un bug ? Por lo menos para saber que no estoy loco. En mi versión 4.1.0.4 no me funciona, lo podrian probar en alguna otra versión ?
Saludos y gracias.
-
En realidad originalmente era global, porque también accedia al vector en una rutina de interrupción, pero tampoco funciona bien, ni como global ni como local. Alguien puede corroborar que es un bug ? Por lo menos para saber que no estoy loco. En mi versión 4.1.0.4 no me funciona, lo podrian probar en alguna otra versión ?
Saludos y gracias.
Se me ocurre que quizas puedas probar el codigo en DEV-C o GCC simplemente para comprobar el funcionamiento.
-
En realidad originalmente era global, porque también accedia al vector en una rutina de interrupción, pero tampoco funciona bien, ni como global ni como local. Alguien puede corroborar que es un bug ? Por lo menos para saber que no estoy loco. En mi versión 4.1.0.4 no me funciona, lo podrian probar en alguna otra versión ?
Saludos y gracias.
Se me ocurre que quizas puedas probar el codigo en DEV-C o GCC simplemente para comprobar el funcionamiento.
mirá bajé el DEV-C, usé el ejemplo Hello World y le puse las mismas estructuras y si funciona, me quedó asi:
#include <iostream>
using namespace std;
#define TRUE 0x01
typedef struct {
//struct Tipo_timer {
short int Enable; // Habilita el temporizador.
short int Res1ms; // Resolucion del temporizador de 1ms.
short int Res10ms; // Resolución del temporizador de 10ms.
short int Res1seg; // Resolución del temporizador de 1seg.
short int TON; // Temporizador de Retardo a la conexión.
short int TOF; // Temporizador de Retardo a la desconexión.
short int TP; // Temporizador por impulsos.
short int I; // Entrada del temporizador.
short int IAnt; // Estado anterior de la entrada del temporizador.
short int Q; // Salida del temporizador.
int ACC; // Acumulador del temporizador.
int PRESET; // Preset del temporizador.
} tipo_timer;
//Se disponen de 100 temporizadores.
tipo_timer T[10];
int main (int argc, char *argv[])
{
char quit;
int i;
quit = '\0';
T[2].Enable=TRUE;
T[2].TON=TRUE;
T[2].Res1ms=TRUE;
T[2].PRESET=500;
T[2].ACC=0;
if (T[2].Enable==TRUE) {
cout << "T[2].Enable es TRUE" << endl;
}
else {
cout << "T[2].Enable es FALSE" << endl;
}
i=2;
if (T[i].Enable==TRUE) {
cout << "T[i].Enable es TRUE" << endl;
}
else {
cout << "T[i].Enable es FALSE" << endl;
}
while (quit != 'q')
{
cout << "Hello ! This is a console app." << endl;
cout << "To create a console, go to Project Options and select" << endl;
cout << "\'Win32 Console\'." << endl;
cout << "Press q to quit " << endl;
cin >> quit;
}
return 0;
}
Y la salida por consola fue esta
T[2].Enable es TRUE
T[i].Enable es TRUE
Hello ! This is a console app.
To create a console, go to Project Options and select
'Win32 Console'.
Press q to quit
Es decir la estructura en C está bien armada. No me gustaría tener que cambiar de compilador, a ver si alguien que tenga CCS puede hacerlo andar. Gracias.
-
Hola.
Porque no revisas el valor de i desde el debbug, de esa manera se puede ver que dirección de memoria tiene, de pronto se esta pisando con otra dirección de la estructura ..
Saludos.
-
Tec_Claudio_perez
Amigo probe tu programa o parte este donde te da la falla y a mi me funciona bien :mrgreen:
Lo que no veo en el programa es donde declaras Q4? :huh:
Probe este programa y en el proteus opera fino por lo menos ;-)
#include <18f252.h>
#fuses XT, NOWDT,PUT
#use delay(clock= 4000000)
typedef struct
{
BOOLEAN Enable; // Habilita el temporizador.
BOOLEAN Res1ms; // Resolucion del temporizador de 1ms.
BOOLEAN Res10ms; // Resolución del temporizador de 10ms.
BOOLEAN Res1seg; // Resolución del temporizador de 1seg.
BOOLEAN TON; // Temporizador de Retardo a la conexión.
BOOLEAN TOF; // Temporizador de Retardo a la desconexión.
BOOLEAN TP; // Temporizador por impulsos.
BOOLEAN I; // Entrada del temporizador.
BOOLEAN IAnt; // Estado anterior de la entrada del temporizador.
BOOLEAN Q; // Salida del temporizador.
int16 ACC; // Acumulador del temporizador.
int16 PRESET; // Preset del temporizador.
}tipo_timer;
void main()
{
Tipo_timer T[100];
int8 i;
int1 Q4;
//Aqui inicializo el elemento 2.
T[2].Enable=TRUE;
T[2].TON=TRUE;
T[2].Res1ms=TRUE;
T[2].PRESET=500;
T[2].ACC=0;
i=2;
if (T.Enable==TRUE) {
Q4=1;
if(Q4)
output_high(pin_B0);
}
else {
Q4=0;
}
while(true);
}
Revizalo a ver si te sirve
-
Tec_Claudio_perez
Amigo probe tu programa o parte este donde te da la falla y a mi me funciona bien :mrgreen:
Lo que no veo en el programa es donde declaras Q4? :huh:
Probe este programa y en el proteus opera fino por lo menos ;-)
#include <18f252.h>
#fuses XT, NOWDT,PUT
#use delay(clock= 4000000)
typedef struct
{
BOOLEAN Enable; // Habilita el temporizador.
BOOLEAN Res1ms; // Resolucion del temporizador de 1ms.
BOOLEAN Res10ms; // Resolución del temporizador de 10ms.
BOOLEAN Res1seg; // Resolución del temporizador de 1seg.
BOOLEAN TON; // Temporizador de Retardo a la conexión.
BOOLEAN TOF; // Temporizador de Retardo a la desconexión.
BOOLEAN TP; // Temporizador por impulsos.
BOOLEAN I; // Entrada del temporizador.
BOOLEAN IAnt; // Estado anterior de la entrada del temporizador.
BOOLEAN Q; // Salida del temporizador.
int16 ACC; // Acumulador del temporizador.
int16 PRESET; // Preset del temporizador.
}tipo_timer;
void main()
{
Tipo_timer T[100];
int8 i;
int1 Q4;
//Aqui inicializo el elemento 2.
T[2].Enable=TRUE;
T[2].TON=TRUE;
T[2].Res1ms=TRUE;
T[2].PRESET=500;
T[2].ACC=0;
i=2;
if (T.Enable==TRUE) {
Q4=1;
if(Q4)
output_high(pin_B0);
}
else {
Q4=0;
}
while(true);
}
Revizalo a ver si te sirve
ok, gracias.
-
Muy extraño, ya probé con 18f4550 y con 18f2550 en Proteus y no tengo el problema, ¿podrías subir los archivos de tu proyecto y simulación para probar?
-
Nunca dio error de variable inexistente??
Sera porque en la estructura hay variables tipo Q ?? :shock: :shock: :shock:
Yo no me había dado cuenta que no habían sido declaradas...
-
Asi es MGLSOFT
Yo no vi las variable Q4, Q3... declaradas por eso la cree y al simulalrla en el proteus me funciono todo bien, abra que esperar a que tec_claudio_perez revice y nos avice si ya pudo resolver el problema :mrgreen:
-
Hola.
Mira que dentro de la estructura hay una variable I (boolean) .... y eso puede crear conflicto con la de afuera i, a mi me paso mas de una vez, eso si es bug del CCS :5]
Intenta dar otro nombre a esa variable a ver que pasa
Saludos
-
Mira que dentro de la estructura hay una variable I (boolean) .... y eso puede crear conflicto con la de afuera i, a mi me paso mas de una vez, eso si es bug del CCS :5]
Intenta dar otro nombre a esa variable a ver que pasa
:D Ese CCS es todo un tema :D
-
que si que :D
recuerdo que aumentaba la variable dentro de la estructura, mas no la otra ... jeje
-
Hola.
Mira que dentro de la estructura hay una variable I (boolean) .... y eso puede crear conflicto con la de afuera i, a mi me paso mas de una vez, eso si es bug del CCS :5]
Intenta dar otro nombre a esa variable a ver que pasa
Saludos
yo desde siempre he evitado usar variables del mismo nombre (sea mayúscula y minúscula) y no hablo solo de programación para micros, los lenguajes estructurados crean desde confusiones hasta fallas del mas allá :(
-
Yo utilizo k,j,i en cada una de las funciones y nunca un problema. Además no tiene sentido, y si creas varias estructuras del mismo tipo, CCS no va a saber cual modificarle su elemento :D Debe ser una versión especifica que da problemas con respecto a esto :tongue:
-
Pues, no recuerdo que versión era ... pero quede curado :D :D :D por ello uso mejor nombres diferentes ....
Entre estructuras nunca me dio problema .... pero si dentro de una estructura definía una variable, esa misma variable no la defino ni por el p$#$ fuera de ella :D :D :D :D :D
Saludos