Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: MatchingWristMain.c
- * Author: Rito III
- *
- * Created on 7 de abril de 2022, 7:08
- */
- #include "xc.h"
- #include "stdio.h"
- #include "math.h"
- //#include "iostream.h"
- //#include "FastLED.h"
- #include "../nrf24_lib.h"
- #include "build/default/debug/../production/mcc_generated_files/../../production/mcc_generated_files/../../../../string.h"
- #include "../mcc_generated_files/mcc.h"
- #include"string.h"
- NRF24_INIT_STATUS ret;
- unsigned char i;
- unsigned char bufferTX[50];
- unsigned char bufferRX[50];
- //int NRF24L01_TX_EX = 1;
- //int NRF24L01_RX_EX = 0;
- #define NRF24L01_TX_EX 1
- #define NRF24L01_RX_EX !NRF24L01_TX_EX
- char datos={0};//number of the device plus personal data
- char buffer;
- char dispositivo[3];
- char genero[3];
- int age;
- char edo_civil[3];
- char hijos[3];
- char religion [3];
- char educacion[3];
- char toma[3];
- char fuma[3];
- char ocupacion[3];
- char caracter[3];
- char casa[3];
- char carro[3];
- char comportamiento[3];
- char dispositivo_h[3];
- char genero_h[3];
- int age_h;
- char edo_civil_h[3];
- char hijos_h[3];
- char religion_h [3];
- char educacion_h[3];
- char toma_h[3];
- char fuma_h[3];
- char ocupacion_h[3];
- char caracter_h[3];
- char casa_h[3];
- char carro_h[3];
- char comportamiento_h[3];
- //const unsigned long long pipes[2] = { 0xEEFDFDFDECLL, 0xEEFDFDF0DFLL };
- void blink_led() {
- LED_Toggle();
- }
- //#define LED_PIN 2
- //#define NUM_LED 3
- //CRGB leds[NUM_LED];
- //void setup ()
- //{
- //FastLED.addLeds<WS2812,LED_PIN, RGB>(leds,NUM_LED);
- //FastLED.SetMaxPowerInVoltsAndMilliamps(3,300);
- //leds[1]= CRGB (0,255,0);
- //FastLED.show();
- //FastLED.clear();
- //}
- void Led_color(int color)
- {
- if (color==1)
- {
- //leds[1]= CRGB[255,0,0];
- //FastLED.show();
- int k;
- for (k=0;k<= 6;k++)
- {
- LATBbits.LATB5 = 1;
- LATBbits.LATB4 = 1;
- LATBbits.LATB3 = 1;
- __delay_ms(1000);
- LATBbits.LATB3 = 0;
- LATBbits.LATB4 = 0;
- LATBbits.LATB5 = 0;
- __delay_ms(1000);
- //printf("blink Red color\n");
- }
- }
- if (color==2)
- {
- //leds[1]= CRGB[0,0,255];
- //FastLED.show();
- int w;
- for (w=0;w<= 6;w++)
- {
- LATBbits.LATB0 = 1;
- LATBbits.LATB1= 1;
- LATBbits.LATB2 = 1;
- __delay_ms(1000);
- LATBbits.LATB0 = 0;
- LATBbits.LATB1= 0;
- LATBbits.LATB2 = 0;
- __delay_ms(1000);
- //printf("blink yellow color\n");
- }
- }
- if (color==3)
- {
- int z;
- for (z=0;z<= 6;z++)
- {
- LATDbits.LATD5 = 1;
- LATDbits.LATD6 = 1;
- LATDbits.LATD7 = 1;
- __delay_ms(1000);
- LATDbits.LATD5 = 0;
- LATDbits.LATD6 = 0;
- LATDbits.LATD7 = 0;
- __delay_ms(1000);
- //printf("blink green colour\n");
- }
- }
- }
- //void timer1_interrupt (void)
- //{
- //}
- /*
- void timer1_run (void)
- {
- //initialize the timer
- TMR1=0; //TIMER 1 CON OSCILADOR EXTERNO Y PRESCALER DE 8
- T1CONbits.TMR1ON = 0;//apago el timer 1 y es tambien para la interrupcion del rollover
- T1CONbits.TMR1CS = 0b10;//lo configuro con oscilador externo
- T1CONbits.T1CKPS = 0b11;//lo configuro con 1 de preescaler
- T1CONbits.SOSCEN = 1;//configuro para oscilador externo
- OSCCON2bits.SOSCGO = 1; //configuro para oscilador externo con entrada en SOSCO/SOSCI pins
- PIE1bits.TMR1IE = 1;//habilita interrupcion
- //inicializamos contadores y TMR1 registros
- TMR1H = 0;
- TMR1L = 0;
- PIR1bits.TMR1IF = 0; //para borrar la interrupcion por desbordamiento del timer
- T1CONbits.T1SYNC = 1; //para syncronizar el oscilador
- TMR1=0xFB1E; // 64,286 para contar 200 msec por 100 veces
- T1CONbits.TMR1ON = 1;//enciendo el timer
- }*/
- void seleccion (unsigned char* t, unsigned char* r){
- unsigned char host[50];
- unsigned char data[50];
- char soltero[3] = {"67"};
- char casado [3]= {"68"};
- char divorciado[3] = {"69"};
- char complicado[3] = {"6A"};
- char con_hijos[3]= {"6B"};
- char sin_hijos[3] ={"6C"};
- char catolico[3]={"6D"};
- char cristiano[3]={"6E"};
- char musulman[3] = {"6F"};
- char ateo[3] = {"70"};
- char testigo[3] = {"71"};
- char luz_mundo[3] = {"72"};
- char sin_religion[3] = {"73"};
- char otra[3] = {"74"};
- char ingeniero[3] = {"75"};
- char no_importa[3] = {"9B"};
- char licenciado[3] = {"76"};
- char master [3]= {"77"};
- char doctorado[3] = {"78"};
- char tecnico[3] = {"79"};
- char prepa[3] = {"7A"};
- char secundaria [3]= {"7B"};
- char primaria[3] = {"7C"};
- char sin_estudios[3] = {"7D"};
- char drinks[3] = {"7E"};
- char no_toma[3] ={"7F"};
- char smoke[3] = {"80"};
- char no_fuma[3] = {"81"};
- char empleado[3] = {"82"};
- char comerciante[3] = {"83"};
- char business_owner[3] = {"84"};
- char sin_trabajo[3] = {"85"};
- char ama_de_casa[3] = {"86"};
- char caracter_fuerte[3] = {"87"};
- char caracter_dulce [3]= {"88"};
- char timido [3]= {"89"};
- char bondadoso[3] = {"8A"};
- char agarrado[3] = {"8B"};
- char honesto [3]= {"8C"};
- char trakala [3]= {"8D"};
- char casa_propia[3] = {"8E"};
- char renta [3]= {"8F"};
- char carro_propio[3] = {"90"};
- char sin_carro [3]= {"91"};
- char buen_corazon[3] = {"92"};
- char romantico [3]= {"93"};
- char detallista [3]= {"94"};
- char con_mala_memoria [3]= {"95"};
- char no_romantico[3] = {"96"};
- char no_detallsita [3]= {"97"};
- char colerico[3] = {"98"};
- char protector[3] = {"99"};
- char abusivo [3]= {"9A"};
- strcpy (data,t);
- strcpy(host,r);
- char d[]=",";
- char *datap0 = strtok(data,d);
- strcpy(dispositivo ,datap0); // add the device
- char *datap1=strtok(NULL,d);
- strcpy(genero ,datap1); // add the gender
- char *datap2=strtok(NULL,d);
- age= atoi(datap2); //add the age and converted into integer
- char *datap3=strtok(NULL,d);
- strcpy(edo_civil,datap3);//if married or not
- char *datap4=strtok(NULL,d);
- strcpy(hijos,datap4);//if any kids
- char *datap5=strtok(NULL,d);
- strcpy(religion,datap5); // religion
- char *datap6=strtok(NULL,d);
- strcpy(educacion ,datap6);//education
- char *datap7=strtok(NULL,d);
- strcpy(ocupacion,datap7);//drinks
- char *datap8=strtok(NULL,d);
- strcpy(caracter ,datap8);//smokes
- char *datap9=strtok(NULL,d);
- strcpy(toma ,datap9); //occupation
- char *datap10=strtok(NULL,d);
- strcpy(fuma ,datap10);//character
- char *datap11=strtok(NULL,d);
- strcpy(casa ,datap11);//house
- char *datap12=strtok(NULL,d);
- strcpy(carro ,datap12);//car
- char *datap13=strtok(NULL,d);
- strcpy(comportamiento,datap13);//comportamiento
- char *datap14=strtok(NULL,d);
- //host
- char *hostp0 = strtok(host,d);
- strcpy(dispositivo_h,hostp0);//add the device into the string
- char *hostp1=strtok(NULL,d);
- strcpy(genero_h,hostp1); // add the gender
- char *hostp2=strtok(NULL,d);
- age_h= atoi(hostp2); //add the age and converted into integer
- char *hostp3=strtok(NULL,d);
- strcpy(edo_civil_h,hostp3);//if married or not
- char *hostp4=strtok(NULL,d);
- strcpy(hijos_h,hostp4);//if any kids
- char *hostp5=strtok(NULL,d);
- strcpy(religion_h ,hostp5);//religion
- char *hostp6=strtok(NULL,d);
- strcpy(educacion_h ,hostp6);//education
- char *hostp7=strtok(NULL,d);
- strcpy(ocupacion_h ,hostp7);//drinks
- char *hostp8=strtok(NULL,d);
- strcpy(caracter_h ,hostp8);//smokes
- char *hostp9=strtok(NULL,d);
- strcpy(toma_h ,hostp9); //occupation
- char *hostp10=strtok(NULL,d);
- strcpy(fuma_h ,hostp10);//character
- char *hostp11=strtok(NULL,d);
- strcpy(casa_h ,hostp11);//house
- char *hostp12=strtok(NULL,d);
- strcpy(carro_h ,hostp12);//car
- char *hostp13=strtok(NULL,d);
- strcpy(comportamiento_h,hostp13);//comportamiento
- char *hostp14=strtok(NULL,d);
- if ( strcmp(genero,genero_h)!=0 )//revisa genero
- {
- if ( age_h <= age )//revisa edad
- {
- //printf("Edad compatible\n");//tengo que diseñar algo que me actualize esto sin conectarme a la pulsera
- if (( strcmp(edo_civil_h,soltero)==0 )||(strcmp(edo_civil_h,divorciado)==0 )||(strcmp(edo_civil_h,complicado)==0 ))//revisa estado civil
- {
- //printf("Estado civil compatible\n");
- if (strcmp(hijos_h,sin_hijos)==0)//sin hijos
- {
- //printf("Hijos compatible\n");
- if (strcmp(religion,religion_h)==0)//misma.religion
- {
- //printf("Religion compatible\n");
- if ((strcmp(educacion_h,ingeniero)==0)||(strcmp(educacion_h,licenciado)==0)||(strcmp(educacion_h,master)==0)||(strcmp(educacion_h,doctorado)==0)||(strcmp(educacion_h,no_importa)==0))
- {
- //printf("educacion compatible\n");
- if ((strcmp(ocupacion_h,empleado)==0)||(strcmp(ocupacion_h,comerciante)==0)||(strcmp(ocupacion_h,business_owner)==0)||(strcmp(ocupacion_h,ama_de_casa)==0)) // le gusta la profesion
- {
- //printf("ocupacion compatible\n");
- if ((strcmp(caracter_h,caracter_dulce)==0)||(strcmp(caracter,timido)==0)||(strcmp(caracter_h,bondadoso)==0)||(strcmp(caracter_h,trakala)==0))
- {
- //printf("caracter_compatible\n");
- if (strcmp(toma_h,no_toma)==0)//si no toma
- {
- //printf("Bebida compatible\n");
- if (strcmp(fuma_h,no_fuma)==0)//si no fuma
- {
- //printf("Fumar compatible\n");
- if (strcmp(casa_h,casa_propia)==0 )//likes have a house
- {
- //printf("Casa compatible\n");
- if (strcmp(carro_h,carro_propio)==0)//likes have a car
- {
- //printf("Carro compatible\n");
- if ((strcmp(comportamiento_h,buen_corazon)==0 )||(strcmp(comportamiento_h,romantico)==0)||(strcmp(comportamiento_h,detallista)==0)||(strcmp(comportamiento_h,protector)==0))//likes behaviour
- {
- // printf("Personalidad compatible\n");
- Led_color(3);
- }
- else
- {
- //flash yellow wrist
- //printf("personalidad no compatible\n");
- Led_color(2);
- }
- }
- else
- {
- //printf("carro no compatible\n");Led_color(2);
- //flash yellow.wrist
- Led_color(2);
- }
- }
- else
- {
- //printf("casa no compatible\n");Led_color(2);
- //flash yellow wrist
- Led_color(2);
- }
- }
- else
- {
- //printf("Fumar no compatible\n");
- Led_color(2);
- //flash.red wrist
- }
- }
- else
- {
- //printf("Bebida no compatible\n");
- Led_color(2);
- //flash red wrist
- }
- }
- else
- {
- //printf("caracter no compatible\n");
- Led_color (1);
- //flash red color
- }
- }
- else
- {
- //printf("Ocupacion no compatible\n");Led_color(2);
- //flash yellow.wrist
- Led_color(1);
- }
- }
- else
- {
- //printf("estudios no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- //printf("Religion no compatible\n");
- Led_color(1);
- ///flash red wrist
- }
- }
- else
- {
- //printf("hijos no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- //printf("Estado civil no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- //printf("Edad no compatible\n");
- Led_color(1);
- //flash red wrist
- }
- }
- else
- {
- //finito:
- Led_color(1);
- //printf("Genero no compatible\n");
- //led_color(1);
- }
- }
- void main()
- {
- // Initialize the device
- SYSTEM_Initialize();
- // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
- // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
- // Use the following macros to:
- // Enable the Global Interrupts
- INTERRUPT_GlobalInterruptEnable();
- // Disable the Global Interrupts
- //INTERRUPT_GlobalInterruptDisable();
- // Enable the Peripheral Interrupts
- INTERRUPT_PeripheralInterruptEnable();
- // Disable the Peripheral Interrupts
- //INTERRUPT_PeripheralInterruptDisable();
- //TMR0_Initialize();
- TMR0_SetInterruptHandler(blink_led);
- //TMR0_StartTimer();
- SPI1_Open(SPI1_DEFAULT);
- TRISB = 0;
- TRISD =0;
- #if NRF24L01_TX_EX
- ret = nrf24_rf_init(TX_MODE, 0b00000010); // Tx mode with 2400+115 Ghz RF frq
- #elif NRF24L01_RX_EX
- ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
- #endif
- //enableAckPayload();
- if (ret == NRF24_INIT_OK)
- {
- printf("###############################################################\r\n");
- printf("NRF24L01 Initialize successful\r\n");
- nrf24_printf_rf_config();
- printf("###############################################################\r\n");
- }
- else
- {
- printf("###############################################################\r\n");
- printf("Failed Initialize NRF24L01\r\n");
- printf("###############################################################\r\n");
- }
- //#if NRF24L01_TX_EX
- //char memoria [5][50];
- while (1)
- {
- //while (txcounter <= 2)//cuantas veces quiero que transmita
- //{
- // txcounter++;
- #if NRF24L01_TX_EX
- sprintf((char*)bufferTX,"01,00,03,04,05,06,07,08");//ejemplo verde
- nrf24_send_rf_data(bufferTX);
- LATBbits.LATB0 = 1;
- __delay_ms(100);
- LATBbits.LATB0 = 0;
- __delay_ms(100);
- //sprintf((char*)bufferRX,"01,66,42,67,6C,6F,82,88,7F,81,8E,90,92");//ejemplo rojo
- sprintf((char*)bufferTX,"01,00,03,04,05,06,07,08");
- nrf24_send_rf_data(bufferTX);
- __delay_ms(100);
- LATBbits.LATB0 = 1;
- __delay_ms(100);
- LATBbits.LATB0 = 0;
- __delay_ms(100);
- //sprintf((char*)bufferRX,"01,66,20,69,6C,6F,9B,82,88,7F,81,8F,90,92");//ejemplo amarillo
- sprintf((char*)bufferTX,"01,00,03,04,05,06,07,08");
- nrf24_send_rf_data(bufferTX);
- LATBbits.LATB0 = 1;
- __delay_ms(100);
- LATBbits.LATB0 = 0;
- __delay_ms(100);
- //nrf24_read_rf_data(bufferRX);//activar
- // sprintf((char*)bufferRX,"01,66,42,67,6C,6F,82,88,7F,81,8E,90,92");//ejemplo rojo
- //sprintf((char*)bufferRX,"01,66,20,69,6C,6F,9B,82,88,7F,81,8E,90,92");//ejemplo verde
- //sprintf((char*)bufferRX,"01,66,20,69,6C,6F,9B,82,88,7F,81,8F,90,92");//ejemplo amarillo
- // TRISBbits.RB0 = 1;
- // __delay_ms(100);//activar
- // TRISBbits.RB0 = 0;
- //}
- //lo muevo a modo receptor
- //seleccion(bufferTX, bufferRX);
- #elif NRF24L01_RX_EX
- //nrf24l01_read_rf_data(bufferrx)
- //printf("please input your host data");
- //scanf("%c",&buffer);
- //sprintf(host[x],"datos%x",bufferrx);
- //puts(homemst);
- //}
- /*if (z<=5)
- {
- z++;
- strcpy(memoria[z],bufferRX);
- }
- */
- //give values to the constants
- //data reception
- //#elif nr24l01_rx_ex
- //while nr24l01_data available
- /*printf("dispositivos a comparar=%x,%x\n",data[0],host[0]);
- int c=2;
- while (c<=5)
- {
- if (strcmp(memoria[c], bufferRX)== 0)
- {//printf("dispositivo ya escaneado");
- goto finito;
- }
- else
- {c++;
- }
- }
- */
- //NRF24L01_TX_EX =0;
- //NRF24L01_RX_EX =1;
- ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
- //TRISBbits.RB0 = 1;
- __delay_ms(100);
- //TRISBbits.RB0 = 0;
- //__delay_ms(100); //actvar
- nrf24_read_rf_data(bufferRX);//este es el bueno
- //TRISBbits.RB0 = 1;
- __delay_ms(100); //activvar
- //TRISBbits.RB0 = 0;
- writeAckPayload (0,bufferTX,32);//activar
- //TRISBbits.RB0 = 1;
- //__delay_ms(100);
- // TRISBbits.RB0 = 0;
- // seleccion (bufferTX, bufferRX);activar
- /*
- //initialize the timer
- TMR1=0; //TIMER 1 CON OSCILADOR EXTERNO Y PRESCALER DE 8
- T1CONbits.TMR1ON = 0;//apago el timer 1 y es tambien para la interrupcion del rollover
- T1CONbits.TMR1CS = 0b01;//lo configuro con oscilador interno
- T1CONbits.T1CKPS = 0b11;//lo configuro con 1 de preescaler
- T1CONbits.SOSCEN = 0;//configuro para oscilador interno
- // OSCCON2bits.SOSCGO = 0; //configuro para oscilador externo con entrada en SOSCO/SOSCI pins
- OSCCON =0b00110110;// se configura el reloj a interno con una frecuencia de 1 Mhz
- PIE1bits.TMR1IE = 0;//deshabilita interrupcion
- //inicializamos contadores y TMR1 registros
- TMR1H = 0;
- TMR1L = 0;
- PIR1bits.TMR1IF = 0; //para borrar la interrupcion por desbordamiento del timer
- // T1CONbits.T1SYNC = ; //para syncronizar el oscilador
- TMR1=0x3CB0; // 15,536 para contar 200 msec
- T1CONbits.TMR1ON = 1;//enciendo el timer
- //data reception
- //bufferRX[32]= "016642676C6F9B7F8182889B9B92";
- //
- while (PIR1bits.TMR1IF==0) //otra vez hago el ciclo para que empieze a contar
- {
- nrf24_read_rf_data(bufferRX);
- //printf("NRF24 Receive Data: %s\r\n", bufferRX);
- __delay_ms(10);*/
- /*
- //char guest2[50];
- //for (int y=0;y<=13;y++)
- //{
- //sprintf(guest2, "host %x", host[y]);
- //puts(guest2);
- //}
- //PIR1bits.TMR1IF = 0;//apago la bandera de desboradmiento del timer
- // T1CONbits.TMR1ON = 0;//apago el timer
- // PIR1bits.TMR1IF = 0;//apago la bandera de desboradmiento del timer
- // TMR1H = 0;//iniciallizo los timer TMR1h y L
- // TMR1L = 0;
- // TMR1=0x3CB0; // 15,536 para contar 200 msec
- // T1CONbits.TMR1ON = 1;//enciendo el timer
- //compatibility
- */
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement