How to write a C Program to Exchange User Entered Text Between 2 Modules Compiles with the free version of CC5X in C Programming Language ?
Solution:/* nRF2401 test code to run on the 24G demo board, V02, This code will exchange user entered text between 2 modules. Compiles with the free version of CC5X. */ #define Clock_8MHz #include "boot.h" #include "xc8.h" #include "stdint.h" #pragma config |= 0x3F10 //Internal Oscillator, No WDT, MCLR Disabled uint8_t data_array[10]; // maximo 10 bites de dados uint8_t rf_address[5]; // maximo 5 bites de endereco // variaveis programaveis definidas no inicio do main() uint8_t tamanhodado; // tamanho em bites uint8_t endereco[5]; // endereco uint8_t tamanhoend; // tamanho endereco em bites; uint8_t canal; // canal usado void boot_up(void); void configure_transmitter(void); void transmit_data(void); void delay_ms(uint16_t); void main() { uint8_t x; boot_up(); // definicoes programaveis tamanhodado=1; endereco[3]=0x00; // address 21482 (transmissor teste) endereco[2]=0x00; endereco[1]=0x0B; endereco[0]=0xC3; tamanhoend=4; canal=15; //2.4(15 = canal) GHz // apenas indicando que foi ligado for (x = 0; x < 3; x++) { LED1 = 1; delay_ms(25); LED1 = 0; LED2 = 1; delay_ms(25); LED2 = 0; } configure_transmitter(); while(1) { LED1=botao; if(botao==0) data_array[0]=0x00; else data_array[0]=0xFF; transmit_data(); LED2=!LED2; delay_ms(25); } } void transmit_data(void) { uint8_t i, j, temp,j1; CE = 1; //Clock in address na ordem do mais significativo para o menos for(j=0; j < tamanhoend ; j++) { j1=tamanhoend-j-1; temp=endereco[j1]; for(i = 0 ; i < 8 ; i++) { DATA1 = temp.7; CLK1 = 1; CLK1 = 0; temp <<= 1; } } //Clock in the data_array na ordem do mais significativo para o menor for(j=0;j<tamanhodado;j++) { j1=tamanhodado-j-1; temp = data_array[j1]; for(i = 0 ; i < 8 ; i++) { DATA1 = temp.7; CLK1 = 1; CLK1 = 0; temp <<= 1; } } CE = 0; //Start transmission delay_ms(1); } // para controlar o canal e o tamanho da informa??o... //2.4G Configuration - Transmitter //This sets up one RF-24G for shockburst transmission void configure_transmitter(void) { uint8_t i, j, temp, temp1; uint8_t config_setup[14]; //Config Mode CE = 0; CS = 1; //Setup configuration array //=================================================================== //Data bits 111-104 data width on channel 1 (excluding CRC and adrs) is 32, mudado para 8 // definicao dos bits de configuracao no manual da NORDIC config_setup[0] = tamanhodado<<3; // bits 111-104 // como esta eh a configuracao do transmissor, os enderecos e o // address width abaixo nao interessam serao postos em zero... jv set 08 //Data bits 103-64 Channel 2 address - we don't care, set it to 200 config_setup[1] = 0; // bits 103-96 config_setup[2] = 0; // bits 95-88 config_setup[3] = 0; // bits 87-80 config_setup[4] = 0; // bits 79-72 config_setup[5] = 200; // bits 71-64 //Data bits 63-24 Channel 1 address - set it to 21482, conforme projeto config_setup[6] = endereco[4]; // bits 63-56 config_setup[7] = endereco[3]; // bits 55-48 config_setup[8] = endereco[2]; // bits 47-40 config_setup[9] = endereco[1]; // bits 39-32 config_setup[10] = endereco[0]; // bits 31-24 //Data bits 23-16 Address width and CRC (11 para enable e 16bits) config_setup[11] = tamanhoend<<5; // bits 23-16 (aqui eh bits e deslocado) config_setup[11] +=3; // bits 23-16 (aqui eh bits e deslocado) //Data bits 15-8 , potencia 0dBm config_setup[12] = 0b.0110.1111; // bits 15-8 //Data bits 7-0 // canal 2461 => 61 nos bits de 1 a 7 = 0111101 config_setup[13] = canal<<1; // bits 7-0 //=================================================================== //Clock in configuration data for(i = 0 ; i < 14 ; i++) { temp = config_setup[i]; for(j = 0 ; j < 8 ; j++) { DATA1 = temp.7; CLK1 = 1; CLK1 = 0; temp <<= 1; } } //Configuration is actived on falling edge of CS (page 10) CE = 0; CS = 0; }
Learn More :
Enter by User
- C Program to Enter an ODD number between 1 and 49.
- C Program to Calculation of One Number Raised to Another
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to find result where value and power are user given
- C Program That in a Given Natural Number x Insert Figure c at Position p
- C Program To Find Prime Number And If Number Is Not Prime Then Find Factors
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program that prompts the user to input a string, (whitespaces allowed)
- C Program to Input Number by the user between 1-100
- How to Gets User Input For Height in C Programming
- Loudness Program: Gets loudness level from user; chooses a response And prints it using logical and operative statements
- C Program to accept n numbers from user & find out the maximum element out of them by using dynamic memory allocation
- C Program to accept string from user & convert all lower case letters into upper case letters & vice versa
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- C program to accept n number from user,store these numbers into an array & count the no of occurrences of each number
- C Program to accept n numbers from user store these numbers into an array & reverse an array elements using function
- C Program to accept a string from user, delete all vowels from that string & display the result
- Write a c program to accept a string from user & generate following pattern (e.g, input "abcd")
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- C Program to accept n numbers from user,store these numbers into an array & sort the number of an array
- C Program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array
Text
Exchange
Compiles
Modules