Advertisement
Mukmin039

Main

Jul 22nd, 2022
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.22 KB | None | 0 0
  1.  
  2.  
  3. #include "xc.h"
  4. #include "stdio.h"
  5. #include "math.h"
  6. //#include "iostream.h"
  7. //#include "FastLED.h"
  8. #include "nrf24_lib.h"
  9. #include "string.h"
  10. #include "mcc_generated_files/mcc.h"
  11. #include"string.h"
  12.  
  13.  
  14.  
  15. NRF24_INIT_STATUS ret;
  16. unsigned char i;
  17. unsigned char bufferTX[50];
  18. unsigned char bufferRX[50];
  19. //int NRF24L01_TX_EX = 0;
  20. //int NRF24L01_RX_EX = 1;
  21. char datos={0};//number of the device plus personal data
  22. char buffer;
  23. #define NRF24L01_TX_EX  0
  24. #define NRF24L01_RX_EX  !NRF24L01_TX_EX
  25.  
  26.  
  27. void blink_led() {
  28.     LED_Toggle();
  29. }
  30.  
  31.  
  32.  
  33. void main()
  34. {
  35.  
  36.     // Initialize the device
  37.     SYSTEM_Initialize();
  38.  
  39.     // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
  40.     // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
  41.     // Use the following macros to:
  42.  
  43.     // Enable the Global Interrupts
  44.     INTERRUPT_GlobalInterruptEnable();
  45.  
  46.     // Disable the Global Interrupts
  47.     //INTERRUPT_GlobalInterruptDisable();
  48.  
  49.     // Enable the Peripheral Interrupts
  50.     INTERRUPT_PeripheralInterruptEnable();
  51.  
  52.     // Disable the Peripheral Interrupts
  53.     //INTERRUPT_PeripheralInterruptDisable();  
  54. //TMR0_Initialize();    
  55. TMR0_SetInterruptHandler(blink_led);
  56. //TMR0_StartTimer();    
  57. SPI1_Open(SPI1_DEFAULT);  
  58. TRISB = 0;
  59. TRISD =0;
  60.  
  61.  
  62. //NRF24L01_TX_EX =0;
  63. //NRF24L01_RX_EX =1;
  64.  
  65.   //  ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
  66.  
  67.  
  68.  
  69.  
  70. #if NRF24L01_TX_EX
  71.    ret = nrf24_rf_init(TX_MODE,115); // Tx mode with 2400+115 Ghz RF frq
  72. #elif NRF24L01_RX_EX
  73.     ret = nrf24_rf_init(RX_MODE, 115); // Rx mode with 2400+115 Ghz RF frq
  74. #endif
  75.     //enableAckPayload();
  76.    
  77.  if (ret == NRF24_INIT_OK)
  78.     {
  79.        // printf("###############################################################\r\n");
  80.         //printf("NRF24L01 Initialize successful\r\n");
  81.         //nrf24_printf_rf_config();
  82.         //printf("###############################################################\r\n");
  83.  
  84.  
  85.        
  86. //#if NRF24L01_TX_EX
  87.  
  88.  //char memoria [5][50];
  89.   //nrf24_set_rf_mode(RX_MODE);
  90.     while (1)
  91.     {      
  92.  #if NRF24L01_TX_EX
  93.  //while (txcounter <= 2)//cuantas veces quiero que transmita
  94. //{  
  95.   //  txcounter++;    
  96.    // sprintf((char*)bufferTX,"00,65,43,69,6B,6F,75,7F,81,83,8B,8E,90,96");
  97.    
  98.     //nrf24_send_rf_data(bufferTX);
  99.     //LATBbits.LATB0 = 1;
  100.     __delay_ms(100);
  101.  
  102. //data reception
  103. #elif NRF24L01_RX_EX
  104. while (nrf24_is_rf_data_available()){
  105.     __delay_ms(100);
  106. //__delay_ms(100);        //actvar
  107.   nrf24_read_rf_data(bufferRX);
  108.   strcpy(bufferTX,bufferRX);//este es el bueno
  109.  
  110.     __delay_ms(100); //activvar
  111.     LATBbits.LATB0 = 1;
  112.     __delay_ms(100);
  113.    LATBbits.LATB0 = 0;
  114.    __delay_ms(100);
  115.  seleccion (bufferTX, bufferRX);
  116.    //writeAckPayload (0,bufferTX,32);//activar
  117.  
  118.  
  119.  
  120. #endif
  121.     __delay_ms(100);
  122.    
  123. }  
  124. }
  125.  }
  126.    else
  127.      { __delay_ms(100);
  128.        
  129.      //printf("###############################################################\r\n");
  130.        // printf("Failed Initialize NRF24L01\r\n");
  131.         //printf("###############################################################\r\n");
  132.         }              
  133.              
  134. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement