TODOPIC
Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: mizzard en 09 de Octubre de 2010, 18:44:22
-
Hola a todos, resulta que quiero usar un define para modificar el tamaño del buffer de recepcion de i2c, no sé lo que me está pasando que me da error. Si cambio el define y pongo el valor en HEX, si que me funciona.
*** Error 30 "main.c" Line 61(20,21): Expecting a ]
*** Error 43 "main.c" Line 61(20,21): Expecting a declaration
*** Error 43 "main.c" Line 61(21,22): Expecting a declaration
*** Error 30 "main.c" Line 62(20,21): Expecting a ]
*** Error 43 "main.c" Line 62(20,21): Expecting a declaration
*** Error 43 "main.c" Line 62(21,22): Expecting a declaration
*** Error 30 "main.c" Line 64(20,21): Expecting a ]
*** Error 43 "main.c" Line 64(20,21): Expecting a declaration
*** Error 43 "main.c" Line 64(21,22): Expecting a declaration
*** Error 30 "main.c" Line 65(21,22): Expecting a ]
*** Error 43 "main.c" Line 65(21,22): Expecting a declaration
*** Error 43 "main.c" Line 65(22,23): Expecting a declaration
*** Error 30 "main.c" Line 67(23,24): Expecting a ]
*** Error 43 "main.c" Line 67(23,24): Expecting a declaration
*** Error 43 "main.c" Line 67(24,25): Expecting a declaration
Con el código, lo que intento hacer es que los 2 primeros bytes de la recepcion los meto en comando y el resto en un buffer hasta que encuentro dos bytes consecutivos 0x0d y 0x0a
Si los encuentro se que he terminado de recibir datos, por lo que trato el comando que he recibido, si es AA, lo meto en mensaje y si es BB lo meto en telefono.
El código es el siguiente.
¿Cuál es el problema de #define?
¿Estaría bien programado para lo q he explicado?
Espero vuestra contestación, muchas gracias! :D
#include <18F2523.h>
//#device adc=12
#FUSES NOWDT,INTRC,PUT,NOPROTECT,NODEBUG,BROWNOUT,BORV21,NOLVP,NOCPD,NOWRT,STVREN,NOWRTD,NOPBADEN,NOWRTC,NOWRTB,NOEBTR,NOEBTRB,NOCPB,LPT1OSC,NOMCLR,NOXINST
#use delay(INTERNAL=8000000)
//NOTE: Must declare MASTER before SLAVE, i2c_isr_state() returns 0
// when MASTER is the most recent #use i2c
#use i2c(MASTER, sda=PIN_C4, scl=PIN_C3,SLOW, stream=I2CM)
#use i2c(SLAVE, sda=PIN_C4, scl=PIN_C3, address=0x20,SLOW, force_hw, stream=I2CS)
#define tamBuff 0x40;
#define tamComando 0x02;
#define tamFin 0x02;
//Library includes:
#include <limits.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
//================================================================================================================================================
//----------------------- DEFINICIONES ---------------------------------------------------------------------------------------------------
//================================================================================================================================================
//================================================================================================================================================
//----------------------- VARIABLES GLOBALES ---------------------------------------------------------------------------------------------------
//================================================================================================================================================
int i=0;
int estado=0;
boolean finCadena=false;
int end=0;
//================================================================================================================================================
//----------------------- DECLARACIÓN DE FUNCIONES ---------------------------------------------------------------------------------------------
//================================================================================================================================================
void inicializaPIC(void);
void pruebaParpadeo(void);
void escrituraMI2c(void);
void lecturaMI2c(void);
//************************************************************************************************************************************************
//************** INTERRUPCIONES ********************************************************************************************
//************************************************************************************************************************************************
int rcv_buf[tamBuff];
int wrt_buf[tamBuff];
int mensaje[tamBuff];
int telefono[tamBuff];
int comando[tamComando];
//================================================================================================================================================
#int_SSP // interrupt on i2c activity
void i2c_isr(void)
{
int state, incoming;
state = i2c_isr_state();
if(state < 0x80)
{
incoming = i2c_read(I2CS);
if (state == 1)
{
comando[0]= incoming; // El primer byte lo guardamos aquí
}
else if (state == 2)
{
comando[1] = incoming; // El segundo byte lo guardamos aquí
}
else if (state > 2 && finCadena ==false)
{
if(incoming==0x0D){
rcv_buf[state-4]=incoming; // El resto de los bytes los guardamos aquí. Podemos elegir el tamaño del buffer
end=state;
}
else if(incoming==0x0A && state==end+1){// && finCadena==1){
rcv_buf[state-4]=incoming; // El resto de los bytes los guardamos aquí. Podemos elegir el tamaño del buffer
finCadena=true;
}
else
rcv_buf[state-4]=incoming; // El resto de los bytes los guardamos aquí. Podemos elegir el tamaño del buffer
end=0;
}
else if (finCadena=true && comando[0]=='A' && comando[1]=='A') // Tengo que poner esto o 0x41?
{
strcpy(mensaje,rcv_buf); // Probar de esta forma o directamente recorrer el buffer con un for hasta encontrar 0x0D 0x0A
finCadena=false;
}
else if (finCadena=true && comando[0]=='B' && comando[1]=='B')// Tengo que poner esto o 0x42?
{
strcpy(telefono,rcv_buf); // Probar de esta forma o directamente recorrer el buffer con un for hasta encontrar 0x0D 0x0A
finCadena=false;
}
}
else
{
i2c_write(I2CS,wrt_buf[state-0x80]); // Master pide datos
}
}
//================================================================================================================================================
-
Hola, los defines como ése no llevan punto y coma al final.
-
Es verdad.... muchas gracias :P