#include <xc.h>
#include <stdint.h>
#include <string.h>
#define _XTAL_FREQ 4000000
struct myRxStruct
{
uint8_t indexStr;
const char *ptrCheck;
uint8_t flags;
};
struct myRxStruct myRxStruct = {0,0,0};
const char *txtComp[]={
"hola",
"tiempo"
};
void test(char a)
{
char recv;
recv = a;
if(!myRxStruct.indexStr)
{
// Recien comienzo? Veo si alguno de los string comienza con la letra que quiero
uint8_t i = 0;
for(i=0 ;i < (sizeof txtComp / sizeof (txtComp[0]));i++){
if(*txtComp[i] == recv) {
// Solo tengo en cuenta cuando tengo alguna coincidencia
myRxStruct.indexStr = i;
myRxStruct.indexStr++;
myRxStruct.ptrCheck = txtComp[i];
myRxStruct.ptrCheck++;
break;
}
}
} else {
// Continuo con las demas letras
if(recv == *myRxStruct.ptrCheck){
// Aca coinciden
myRxStruct.ptrCheck++;
// Termino el string?
if(!*myRxStruct.ptrCheck)
{
myRxStruct.flags |= myRxStruct.indexStr;
myRxStruct.indexStr = 0;
}
} else {
// Aca no coincide
myRxStruct.indexStr = 0;
}
}
}
void main(void){
char text[]= "hola";
while(1)
{
uint8_t j;
for(j=0;j<sizeof text;j++)
test(text[j]);
}
}