📄 crt2400anc.c
字号:
void config_test()
{
pwr_up=1; //pwr_up=1:Power Up
delay_ms(5); //delay 5ms for 2401 enable
ce=0; //ce=0:chip configuration mode
cs=1; //cs=1:chip select activates configuration mode
_delay(25);
j=0;
while (j<18)
{
config_send_one_byte(test_config[j]);
j++;
}
cs=0;
_delay(3);
clk1=0;
data=0;
ce=1; //ce=1:activates RF2401 on-board for test
}
/*********************************config_test() END***********************************/
/************************************************************************************
* function: receive_data()
* use: receive data from module(more bytes)
* input parameter: the number you will receive(Max 25 Bytes in this application )
* output parameter: none
************************************************************************************/
void receive_data(unsigned input_data)
{
for(data_counter=0;data_counter<input_data;data_counter++)
{
data_buffer[data_counter]=receive_one_byte(); // send the input_data to PC
}
}
/********************************receive_data() END***********************************/
/************************************************************************************
* function: receive_one_byte()
* use: receive one byte from module
* input parameter: none
* output parameter: the value of receive byte
************************************************************************************/
unsigned receive_one_byte(void)
{
unsigned int *tpointer;
tpointer=&temp1; // read one byte
i=0;
while (i<8)
{
clk1=1;
_nop(); //SPI data send protocol
_c=data;
_rlc(tpointer);
clk1=0;
i++;
}
return temp1;
}
/***************************** receive_one_byte() END*********************************/
/************************************************************************************
* function: delay_ms()
* use: delay x ms(Max 65536ms,only for HOLTEK MCU)
* input parameter: unsigned long delay_counter
* output parameter: none
************************************************************************************/
void delay_ms(unsigned long delay_counter)
{
while(delay_counter>0)
{
_delay(990);
delay_counter--;
}
}
/*********************************delay_ms() END*************************************/
/************************************************************************************
* function: send_data()
* use: transmit data from RF moudle(more bytes)
* input parameter:the value will be transmitted
* output parameter: none
************************************************************************************/
void send_data(unsigned input_data)
{
pwr_up=1; //pwr_up=1:Power Up
_delay(8000); //delay 8ms for CRM2400BNC enable(Min 4ms)
ce=1; //ce=1:activates nRF2402 on-board data processing
_delay(30);
config_send_one_byte(0xaa); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xbb); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xcc); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xdd); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xee); // the address for the CRM2400BNC/CRM2400DNC
for(data_counter=0;data_counter<6;data_counter++)
{
config_send_one_byte(input_data); // send the input_data for 6 times
}
config_send_one_byte(0x0a); //send line break
config_send_one_byte(0x0d); //send CR
ce=0; //for next package
pwr_up=0; //disable CRM2400BNC
}
/**********************************send_data() END***********************************/
/************************************************************************************
* function: send_data_rf()
* use: Adjust data and send to RF.
* input parameter: none
* output parameter: none
************************************************************************************/
void send_data_rf(void)
{
led1=0; //Turn on the working indicate led for transmit mode
send_data(increase_data);
increase_data++;
if(increase_data==0x5b)
increase_data=0x41;
led1=1; //Turn off the working indicate led for transmit mode
delay_ms(50);
}
/*********************************send_data_rf() END**********************************/
/************************************************************************************
* function: change_rf_transmit_mode()
* use: delay x ms(Max 65536ms,only for HOLTEK MCU)
* input parameter: unsigned long delay_counter
* output parameter: none
************************************************************************************/
void change_rf_transmit_mode()
{
P1&=0X10;
pwr_up=1; //pwr_up=1:Power Up
delay_ms(5); //delay 4ms
ce=0; //ce=0:chip configuration mode
cs=1; //cs=1:chip select activates configuration mode
_delay(25);
config_send_one_byte(0x64);
cs=0;
_delay(3);
dr1=0;
clk1=0;
data=0;
ce=1;
delay_ms(100);
led1=1; //Turn off the led1 and prepare for transmit data indicate
led2=0; //Turn on the led2 for transmit mode indicate
}
/*********************************change_rf_transmit_mode() END*************************************/
/************************************************************************************
* function: change_rf_receive_mode()
* use:
* input parameter: none
* output parameter: none
************************************************************************************/
void change_rf_receive_mode()
{
P1&=0X10;
pwr_up=1; //pwr_up=1:Power Up
delay_ms(5); //delay 4ms
ce=0; //ce=0:chip configuration mode
cs=1; //cs=1:chip select activates configuration mode
_delay(25);
config_send_one_byte(0x65);
cs=0;
_delay(3);
dr1=0;
clk1=0;
data=0;
ce=1;
P1|=0X01;
delay_ms(100);
led1=0; //Turn on the indicate led for receive mode
led2=1; //Turn off the led2 and prepare for receive data indicate
}
/*********************************change_rf_recieve_mode() END*************************************/
/************************************************************************************
* function: transmit_mode()
* use: delay x ms(Max 65536ms,only for HOLTEK MCU)
* input parameter: unsigned long delay_counter
* output parameter: none
************************************************************************************/
void transmit_mode()
{
change_rf_transmit_mode(); //Change the RF to the transmit mode
while(STOP SW!=0)
{
send_data_rf(); //Do if start_send_data button was pressed
}
task_switch=2; //Change the status toggle to the receive mode
}
/*********************************transmit_mode() END*************************************/
/************************************************************************************
* function: receive_mode()
* use: delay x ms(Max 65536ms,only for HOLTEK MCU)
* input parameter: unsigned long delay_counter
* output parameter: none
************************************************************************************/
void receive_mode()
{
change_rf_receive_mode(); //Change the RF to the receive mode
while(START SW!=0)
{
if(dr1==1)
{
led2=0;
receive_data(8);
led2=1;
send_data_pc(8);
}
}
task_switch=1; //Change the status toggle to transmit mode
}
/*********************************recieve_mode() END*************************************/
/************************************************************************************
* function: main()
* use: blend all subroutines to do all work
* input parameter: none
* output parameter: none
************************************************************************************/
void main()
{
system_init();
while (1)
{
switch (task_switch)
{
case 0:
break;
case 1:
transmit_mode(); //The test board working in the transmit mode
break;
case 2: receive_mode(); //The test board working in the receive mode
break;
default:
break;
}
}
}
/************************************* THE END **************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -