Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "xc.h"
- #include "stdio.h"
- #include "math.h"
- //#include "iostream.h"
- //#include "FastLED.h"
- #include "nrf24_lib.h"
- #include "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 = 0;
- //int NRF24L01_RX_EX = 1;
- char datos={0};//number of the device plus personal data
- char buffer;
- #define NRF24L01_TX_EX 0
- #define NRF24L01_RX_EX !NRF24L01_TX_EX
- void blink_led() {
- LED_Toggle();
- }
- 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;
- //NRF24L01_TX_EX =0;
- //NRF24L01_RX_EX =1;
- // ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
- #if NRF24L01_TX_EX
- ret = nrf24_rf_init(TX_MODE,115); // 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");
- //#if NRF24L01_TX_EX
- //char memoria [5][50];
- //nrf24_set_rf_mode(RX_MODE);
- while (1)
- {
- #if NRF24L01_TX_EX
- //while (txcounter <= 2)//cuantas veces quiero que transmita
- //{
- // txcounter++;
- // sprintf((char*)bufferTX,"00,65,43,69,6B,6F,75,7F,81,83,8B,8E,90,96");
- //nrf24_send_rf_data(bufferTX);
- //LATBbits.LATB0 = 1;
- __delay_ms(100);
- //data reception
- #elif NRF24L01_RX_EX
- while (nrf24_is_rf_data_available()){
- __delay_ms(100);
- //__delay_ms(100); //actvar
- nrf24_read_rf_data(bufferRX);
- strcpy(bufferTX,bufferRX);//este es el bueno
- __delay_ms(100); //activvar
- LATBbits.LATB0 = 1;
- __delay_ms(100);
- LATBbits.LATB0 = 0;
- __delay_ms(100);
- seleccion (bufferTX, bufferRX);
- //writeAckPayload (0,bufferTX,32);//activar
- #endif
- __delay_ms(100);
- }
- }
- }
- else
- { __delay_ms(100);
- //printf("###############################################################\r\n");
- // printf("Failed Initialize NRF24L01\r\n");
- //printf("###############################################################\r\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement