📄 crt2400anc.c
字号:
/************************************************************************************
* NOTICE:
* THIS IS A USER DOCUMENT OF COMAIT
* NAME: 2401TEST_BOARD_V03.C
* USE: The 2.4GHz RF Module Test Board
* VERSION: 0.3
* REF_DOC: 2401TEST_BOARD_V02.C
* START DATE: 31/12/2003
* END DATE: 31/12/2003
* MCU: AT89C2051 DIP20 (Atmel)
* CRYSTAL: 4.00MHz
* CHANNEL: 2
* FREQUENCY: 2450MHz
* COMPANY: Comait Technology Inc.
* WRITER: Eric Chang
* DATA RATE: 1MBps
* FUNCTION DESCRIPTION:
1. CRC16
2. Address length: 40Bit (5Byte)
3. Address: AA,BB,CC,DD,EE(H->L)
4. Payload length: 64Bit (8 Bytes,Max 25 Bytes)
5. Out Power: 0dBm
************************************************************************************/
#include <At89x051.h>
//AT89C2051 pins define
#define DIN P3_0
#define DOUT P3_1
#define START_SW P3_3
#define STOP_SW P3_7
#define LED1 P3_4
#define CE P1_7
#define PWR_UP P1_6
#define CLK2 P1_5
#define DR2 P1_4
#define CS P1_3
#define DOUT2 P1_2
#define DR1 P3_2
#define CLK1 P1_1
#define DATA P1_0
#define LED2 P3_5
//Config bytes define for the test mode ,the head is config18 and the end is config1//
const unsigned test_config[18]={
0x8e,0x08,0x1e, //1c->burst mode;1e->test mode
0x40,0x40,
0xaa,0xbb,0xcc,0xdd,0xee,
0xaa,0xbb,0xcc,0xdd,0xee,
0xa3,0x2f, //6f->burst mode;2f->test mode
0x64 //2450MHz
};
//Config bytes define,the head is config18 and the end is config1//
const unsigned configbyte[18]={
0x8e,0x08,0x1c, //1c->burst mode;1e->test mode
0x40,0x40,
0xaa,0xbb,0xcc,0xdd,0xee,
0xaa,0xbb,0xcc,0xdd,0xee,
0xa3,0x6f, //6f->burst mode;2f->test mode
0x65 //2450MHz
};
unsigned data_buffer[25]; //The data buffer for one time transmission
unsigned char data_counter;
unsigned char increase_data;
unsigned char task_switch;
unsigned i,j,temp1;
void system_init();
void send_byte_pc(unsigned char data);
void send_data_pc(unsigned char length);
void config_some_bits(unsigned configbytes,unsigned bitnumber);
void config_send_one_byte(unsigned configbytes);
void config_2401();
void config_test();
void receive_data(unsigned input_data);
unsigned receive_one_byte(void);
void delay_ms(unsigned long delay_counter);
void main(void);
/*********************************************************************************
* function: myinit()
* use: initilize some normal parameter
* input parameter: none
* output parameter: none
*********************************************************************************/
void system_init()
{
task_switch=2; //Set the test board default mode as receive mode
increase_data=0x41;
pwr_up=0;
ce=0;
cs=0;
clk1=0;
data=0;
TMOD=0x20; //config UART rate
SCON=0x50; //19.2kbps(max 20kbps)
PCON=0x80;
TH1=0xfd;
TL1=0xfd;
TR1=1;
EA=0;
ES=0;
for(i=0;i<25;i++) //Clear the data buffer
{
data_buffer[i]=0;
}
if(START SW==0) //For the RF frequency test
{ //If the start_button is pressed during the power on
delay_ms(100);
if(START SW==0)
{
P1&=0X10;
pwr_up=1;
ce=1;
config_test();
while(1);
}
}
P1&=0X10;
config_2401();
P1|=0X01; //config the nrf2401
delay_ms(2);
led1=0; //Turn on the led indicate the system is already for receive data
led2=1;
}
/***********************************myinit() END*************************************/
/***********************************************************************************
* function: send_byte_pc()
* use: send one byte to pc used simulater serial port (38.4KBps,only for HOLTEK MCU)
* input parameter: the data for sending
* output parameter: none
***********************************************************************************/
void send_byte_pc(unsigned sendbyte)
{
unsigned int *tpointer;
temp1=sendbyte;
dout=0; // send start bit
_delay(10);
i=0; // send one byte
while (i<8)
{
tpointer=&temp1;
_rrc(tpointer);
if(_c==0)
{
clrPA4();
}
else
{
setPA4();
}
_delay(10);
i++;
}
_delay(6); //complement LSB delay time
dout=1; //send stop bit
_delay(4);
}
/*******************************send_byte_pc() END**********************************/
/***********************************************************************************
* function: send_data_pc()
* use: send buffer data to pc used simulate serial port
* input parameter: the length for repare send data buffer
* output parameter: none
***********************************************************************************/
void send_data_pc(unsigned char length)
{
unsigned char temp_counter;
for(temp_counter=0;temp_counter<length;temp_counter++)
{
send_byte_pc(data_buffer[temp_counter]);
}
}
/*******************************send_data_pc() END***********************************/
/************************************************************************************
* function: config_send_one_byte()
* use: one time config 2401 RF module one byte
* input parameter: unsigned
* output parameter: none
************************************************************************************/
void config_send_one_byte(unsigned configbytes)
{
unsigned int *tpointer;
temp1=configbytes;
tpointer=&temp1;
i=0; // send one byte
while (i<8) //SPI data send protocol
{
_rlc(tpointer);
if(_c==0)
{
clrP1_0();
}
else
{
setP1_0();
}
clk1=1;
_nop();
i++;
clk1=0;
}
data=0;
}
/****************************config_send_one_byte() END******************************/
/************************************************************************************
* function: config_2401()
* use: config 2401 RF module
* input parameter: none
* output parameter: none
************************************************************************************/
void config_2401()
{
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);
j=0;
while (j<18)
{
config_send_one_byte(configbyte[j]);
j++;
}
cs=0;
_delay(3);
dr1=0;
clk1=0;
data=0;
ce=1; //ce=1:activates RF2401 on-board data processing
}
/*********************************config_2401() END***********************************/
/************************************************************************************
* function: config_test()
* use: config 2401 RF module as test mode fot the frequency test
* input parameter: none
* output parameter: none
************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -