// The 2.4GHz RF Module Test Board
// MCU: HT48R10A(Holtek)--24pin Fsys/4
// Crystal: 4.000MHz
// Channel: 2
// Frequency: 2450MHz
// Version: 0.1
// Data: 2003/11/20
/* Notes: 1. CRC16
2. Address length: 40Bit (5Byte)
3. Address: AA,AB,55,AB,AA(H->L)
4. Payload length: 200Bit (25Byte)
5. Out Power: 0dBm
*/
/****************************************************/
#include "Ht48r10a-1.h"
#define _et0i _0b_2
#define _ton _0e_4
#define _t0f _0b_5
#define start_button _pa5 //INPUT Pin
#define stop_button _pa6 //INPUT Pin
#define din _pb6 //INPUT Pin
#define dout _pa4 //OUTPUT Pin
#define led1 _pb0 //OUTPUT Pin
#define led2 _pc0 //OUTPUT pin
#define invalid _pb7 //INPUT/OUTPUT Pin
// din and pwr pin define //
#define data _pb5//_pa1
#define dr1 _pb4
#define clk1 _pa3//_pa0
#define dout2 _pa2
#define cs _pa1//_pb3
#define dr2 _pa0
#define clk2 _pb3//_pb2
#define pwr_up _pb2//_pb1
#define ce _pb1//_pb2
#define _pxc _pbc
#define test _pc1
//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,//0xc8,0xc8,
0xaa,0xab,0x55,0xab,0xaa,//0xaa,0xbb,0xcc,0xdd,0xee,
0xaa,0xab,0x55,0xab,0xaa,//0xaa,0xbb,0xcc,0xdd,0xee,
0xa3,0x2f,//0x2f, //6f->burst mode;2f->test mode
0x2a};//0x64}; //14->2410;2A->2450
//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,//0xc8,0xc8,
0xaa,0xab,0x55,0xab,0xaa,//0xaa,0xbb,0xcc,0xdd,0xee,
0xaa,0xab,0x55,0xab,0xaa,//0xaa,0xbb,0xcc,0xdd,0xee,
0xa3,0x6f,//0x6f, //6f->burst mode;2f->test mode
0x2b};//0x65}; //14->2410;2A->2450
const unsigned bit_times=26; //the time length for per bit in the simulater serial port
const unsigned half_bit_times=13; //the time length for half bit
const unsigned tmrc_par=0x86; //Fsys/128
const unsigned timer_start=100; //(256-100)*(128*0.25uS)=5ms
const unsigned timer_start2=0; //for the sleep mode
const unsigned timer_start3=180; // for the sent cycle
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;
unsigned temp1 @ 0x4f;
const unsigned movecount_par=0x1300; //20s
bit buzzer_flag;
#pragma vector timer0 @ 0x08
void system_init();
void send_byte_pc(unsigned char data);
unsigned char receive_byte_pc(void);
void send_data_pc(unsigned char length);
void receive_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()
{
_emi=0; //disable globle interrupt
_pac=0b11100101; //Port input/output define:0 => output; 1 => input
//set pa7 as output port other as input port
_pbc=0b11110000; //pb4 define as input for ID
//pb5 define as low voltage indicate
_pcc=0b00000010; //define pc1 an input port for the test mode
pwr_up=0;
ce=0;
cs=0;
clk1=0;
data=0;
task_switch=0;
for(i=0;i<25;i++)
{
data_buffer=0;
}
if(start_button==0) //For the RF frequency test
{
_pbc&=0b11011111;
//while(1)
//{
config_test();
//}
while(1);
}
_pbc&=0b11011111;
config_2401(); //config the nrf2401
_pbc|=0b00100000;
delay_ms(2);
_emi=1; //enable globle interrupt
led1=0; //Turn on the led indicate the system is already for work
led2=1;
}
/***********************************myinit() END**************************************/
/***********************************************************************************/
/* function: send_byte_pc() */
/* use: send one byte to pc used simulater serial port */
/* 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);
// din=_c;
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: receive_byte_pc() */
/* use: receive one byte from pc used simulater serial port */
/* input parameter: none */
/* output parameter: */
/****************************************************************************************/
unsigned char receive_byte_pc(void)
{
unsigned char temp_counter;
unsigned char temp_byte=0;
while(din==0)
{}
_delay(109);
for(temp_counter=0;temp_counter<8;temp_counter++)
{
temp_byte>>=1;
if(din) temp_byte|=0x80;
_delay(108);
}
return temp_byte;
}
/*********************************receive_byte_pc() END***********************************/
/***********************************************************************************/
/* function: send_data_pc() */
/* use: send buffer data to pc used simulater 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: receive_data_pc() */
/* use: send buffer data to pc used simulater serial port */
/* input parameter: the length for prepare receive data buffer */
/* output parameter: none */
/***********************************************************************************/
void receive_data_pc(unsigned char length)
{
unsigned char temp_counter;
for(temp_counter=0;temp_counter<length;temp_counter++)
{
data_buffer[temp_counter]=receive_byte_pc();
}
}
/*********************************receive_data_pc() END***********************************/
/************************************************************************************/
/* function: config_one_byte() */
/* use: one time config 2401 RF moudel 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)
{
_rlc(tpointer);
if(_c==0)
{
clrPB5();
}
else
{
setPB5();
}
clk1=1;
_nop();
i++;
clk1=0;
}
data=0;
}
/************************************************************************************/
/* function: config_2401() */
/* use: config 2401 RF moudel */
/* 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=1:activates RF2401 on-board data processing
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; //cs=1:chip select activates configuration mode
//pwr_up=0;
}
/***************************************************************************/
/************************************************************************************/
/* function: config_test() */
/* use: config 2401 RF as test mode fot the frequency test */
/* input parameter: none */
/* output parameter: none */
/************************************************************************************/
void config_test()
{
pwr_up=1; //pwr_up=1:Power Up
delay_ms(5); //delay 4ms
ce=0; //ce=1:activates RF2401 on-board data processing
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; //cs=1:chip select activates configuration mode
}
/***************************************************************************/
/***************************************************************************/
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 for 25 times
}
}
/************************************************************************************/
/* function: config_one_byte() */
/* use: one time config 2401 RF moudel one byte */
/* input parameter: unsigned */
/* output parameter: none */
/************************************************************************************/
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;
}
/***************************************************************************/
/***************************************************************************/
void delay_ms(unsigned long delay_counter)
{
while(delay_counter>0)
{
_delay(1000);
delay_counter--;
}
}
/***************************************************************************/
/************************************************************************************/
/* function: main() */
/* use: blend all subroutines to do all work */
/* input parameter: none */
/* output parameter: none */
/************************************************************************************/
void main(void)
{
system_init();
while (1)
{
if(dr1==1)
{
led2=0;
receive_data(8);
led2=1;
send_data_pc(8);
}
}
}
/*************************************** THE END ***************************************/
// The 2.4GHz RF Module Test Board
// MCU: HT48R10A(Holtek)--24pin Fsys/4
// Crystal: 4.000MHz
// Channel: 2
// Frequency: 2421MHz
// Version: 0.1
// Data: 2003/11/20
/* Notes: 1. CRC16
2. Address length: 40Bit (5Byte)
3. Address: AA,AB,55,AB,AA(H->L)
4. Payload length: 200Bit (25Byte)
5. Out Power: 0dBm
*/
/****************************************************/
#include "Ht48r10a-1.h"
#define _et0i _0b_2
#define _ton _0e_4
#define _t0f _0b_5
#define start_button _pa5 //INPUT Pin
#define stop_button _pa6 //INPUT Pin
#define din _pb6 //INPUT Pin
#define dout _pa4 //OUTPUT Pin
#define led1 _pb0 //OUTPUT Pin
#define led2 _pc0 //OUTPUT pin
#define invalid _pb7 //INPUT/OUTPUT Pin
// din and pwr pin define //
#define data _pa2//_pa1
#define clk1 _pa1//_pa0
#define pwr_up _pb2//_pb1
#define ce _pb3//_pb2
#define cs _pa0//_pb3
#define _pxc _pbc
#define test _pc1
//Config bytes define for the nRF2402 test mode ,the center frequency is 2421MHz
const unsigned test_config[6]={
0x8e,0x08,0x1c, // This 3 byte is add for the test mode
// and don't finger in the nRF2401 datasheet
0x0b, // test mode,only low 4 bit is available
0xf7, // BIT15=1 => CRC16
// BIT14=1 => ENABLE ON-CHIP CRC
// BIT13=1 => SHOCK BURST MODE
// BIT12=1 => 1Mbps
// BIT11,10,9=011 => 16MHz CRYSTAL
// BIT8,7=11 => OUT 0dB
0x95 // frequency=>2421MHz
};
//Config bytes define for the nRF2402 transmit mode,the center frequency is 2413MHz
const unsigned configbyte[3]={
0x03, // normal mode,only low 4 bit is available
0xf7, // BIT15=1 => CRC16
// BIT14=1 => ENABLE ON-CHIP CRC
// BIT13=1 => SHOCK BURST MODE
// BIT12=1 => 1Mbps
// BIT11,10,9=011 => 16MHz CRYSTAL
// BIT8,7=11 => OUT 0dB
0x95 // frequency=>2421MHz
};
const unsigned bit_times=26; //the time length for per bit in the simulater serial port
const unsigned half_bit_times=13; //the time length for half bit
const unsigned tmrc_par=0x86; //Fsys/128
const unsigned timer_start=100; //(256-100)*(128*0.25uS)=5ms
const unsigned timer_start2=0; //for the sleep mode
const unsigned timer_start3=180; // for the sent cycle
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 ;
unsigned temp1 @ 0x4f;
const unsigned movecount_par=0x1300; //20s
bit buzzer_flag;
#pragma vector timer0 @ 0x08
void system_init();
void send_byte_pc(unsigned char data);
unsigned char receive_byte_pc(void);
void send_data_pc(unsigned char length);
void receive_data_pc(unsigned char length);
void config_some_bits(unsigned configbytes,unsigned bitnumber);
void config_send_one_byte(unsigned configbytes);
void config_2402();
void config_test();
void send_data(unsigned input_data);
void send_data_rf(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()
{
_emi=0; //disable globle interrupt
_pac=0b11101000; //Port input/output define:0 => output; 1 => input
//set pa7 as output port other as input port
_pbc=0b10110000; //pb4 define as input for ID
//pb5 define as low voltage indicate
_pcc=0b00000010; //define pc1 an input port for the test mode
pwr_up=0;
ce="0";
cs="0";
clk1=0;
data="0";
task_switch=0;
increase_data=0x41;
for(i=0;i<25;i++)
{
data_buffer=0;
}
if(start_button==0) //For the RF frequency test
{
config_test();
while(1);
}
config_2402(); //config the nrf2401
delay_ms(2);
_emi=1; //enable globle interrupt
led1=0; //Turn on the led indicate the system is already for work
}
/***********************************myinit() END**************************************/
/***********************************************************************************/
/* function: send_byte_pc() */
/* use: send one byte to pc used simulater serial port */
/* input parameter: the data for sending */
/* output parameter: none */
/***********************************************************************************/
void send_byte_pc(unsigned char data)
{
unsigned char temp_counter;
dout="0"; //send the start bit
_delay(108);
for(temp_counter=0;temp_counter<8;temp_counter++)
{
if((data>>temp_counter)&01)
dout="1";
else
dout="0";
_delay(108);
}
dout="1"; //send the stop bit
_delay(108);
}
/*********************************send_byte_pc() END***********************************/
/****************************************************************************************/
/* function: receive_byte_pc() */
/* use: receive one byte from pc used simulater serial port */
/* input parameter: none */
/* output parameter: */
/****************************************************************************************/
unsigned char receive_byte_pc(void)
{
unsigned char temp_counter;
unsigned char temp_byte=0;
while(din==0)
{}
_delay(109);
for(temp_counter=0;temp_counter<8;temp_counter++)
{
temp_byte>>=1;
if(din) temp_byte|=0x80;
_delay(108);
}
return temp_byte;
}
/*********************************receive_byte_pc() END***********************************/
/***********************************************************************************/
/* function: send_data_pc() */
/* use: send buffer data to pc used simulater 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: receive_data_pc() */
/* use: send buffer data to pc used simulater serial port */
/* input parameter: the length for prepare receive data buffer */
/* output parameter: none */
/***********************************************************************************/
void receive_data_pc(unsigned char length)
{
unsigned char temp_counter;
for(temp_counter=0;temp_counter<length;temp_counter++)
{
data_buffer[temp_counter]=receive_byte_pc();
}
}
/*********************************receive_data_pc() END***********************************/
/************************************************************************************
* function: config_some_bits()
* use: config some bits less than one byte for nRF2402 mode config
* input parameter: config byte and the rlc bit numbers
* output parameter: none
************************************************************************************/
void config_some_bits(unsigned configbytes,unsigned bitnumber)
{
unsigned int *tpointer;
temp1=configbytes;
tpointer=&temp1;
for(i=0;i<bitnumber;i++)
{
_rlc(tpointer);
}
// send one byte
while (i<8)
{
_rlc(tpointer);
// din=_c;
if(_c==0)
{
clrPA2();
}
else
{
setPA2();
}
_nop(); //SPI data send protocol
clk1=1;
i++;
clk1=0;
}
data="0";
}
/************************************************************************************/
/* function: config_one_byte() */
/* use: one time config 2401 RF moudel one byte */
/* input parameter: unsigned */
/* output parameter: none */
/************************************************************************************/
void config_send_one_byte(unsigned configbytes)
{
/*
temp1=configbytes;
#asm
sz [04fh].7 //clk => pa0
set [012h].1 //dat => pa1
snz [04fh].7 //pa => 0x12
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].6
set [012h].1
snz [04fh].6
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].5
set [012h].1
snz [04fh].5
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].4
set [012h].1
snz [04fh].4
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].3
set [012h].1
snz [04fh].3
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].2
set [012h].1
snz [04fh].2
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].1
set [012h].1
snz [04fh].1
clr [012h].1
set [012h].0
nop
clr [012h].0
sz [04fh].0
set [012h].1
snz [04fh].0
clr [012h].1
set [012h].0
nop
clr [012h].0
#endasm
data="0";
}
*/
unsigned int *tpointer;
temp1=configbytes;
i="0"; // send one byte
while (i<8)
{
tpointer=&temp1;
_rlc(tpointer);
// din=_c;
if(_c==0)
{
clrPA2();
}
else
{
setPA2();
}
_nop(); //SPI data send protocol
clk1=1;
i++;
clk1=0;
}
data="0";
}
/************************************************************************************/
/* function: config_2402() */
/* use: config 2402 RF moudel */
/* input parameter: none */
/* output parameter: none */
/************************************************************************************/
void config_2402()
{
pwr_up=1; //pwr_up=1:Power Up
delay_ms(4); //delay 4ms
ce="0"; //ce=1:activates RF2401 on-board data processing
cs="1"; //cs=1:chip select activates configuration mode
_delay(5);
config_some_bits(configbyte[0],4);
config_send_one_byte(configbyte[1]);
config_send_one_byte(configbyte[2]);
cs="0";
_delay(3);
clk1=0;
data="0";
//ce=1; //cs=1:chip select activates configuration mode
pwr_up=0;
}
/************************************************************************************/
/* function: config_test() */
/* use: config 2401 RF as test mode fot the frequency test */
/* input parameter: none */
/* output parameter: none */
/************************************************************************************/
void config_test()
{
pwr_up=1; //pwr_up=1:Power Up
delay_ms(4); //delay 4ms
ce="0"; //ce=1:activates RF2401 on-board data processing
cs="1"; //cs=1:chip select activates configuration mode
_delay(5);
config_send_one_byte(test_config[0]);
config_send_one_byte(test_config[1]);
config_send_one_byte(test_config[2]);
config_some_bits(test_config[3],4);
config_send_one_byte(test_config[4]);
config_send_one_byte(test_config[5]);
cs="0";
_delay(3);
clk1=0;
data="0";
ce="1"; //cs=1:chip select activates configuration mode
}
void send_data(unsigned input_data)
{
pwr_up=1; //pwr_up=1:Power Up
delay_ms(8); //delay 4ms
// cs="0"; //cs=1:chip select activates configuration mode
ce="1"; //ce=1:activates RF2401 on-board data processing
_delay(30);
config_send_one_byte(0xaa); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xab); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0x55); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xab); // the address for the CRM2400BNC/CRM2400DNC
config_send_one_byte(0xaa); // 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 25 times
}
config_send_one_byte(0x0a);
config_send_one_byte(0x0d);
ce="0";
pwr_up=0;
}
void send_data_rf(void)
{
while(stop_button==1) //Send the data until the stop_data_send button waw pressed
{
led2=0; //Turn on the working indicate led
send_data(increase_data);
increase_data++;
if(increase_data==0x5b)
increase_data=0x41;
led2=1; //Turn off the working indicate led
delay_ms(50);
}
}
void delay_ms(unsigned long delay_counter)
{
while(delay_counter>0)
{
_delay(1000);
delay_counter--;
}
}
/************************************************************************************/
/* function: main() */
/* use: blend all subroutines to do all work */
/* input parameter: none */
/* output parameter: none */
/************************************************************************************/
void main()
{
system_init();
while (1)
{
if (start_button==0) task_switch=1; //send data to RF chip
//if (din==0) task_switch=2; //receive data from pc
switch (task_switch)
{
case 0:
break;
case 1:
send_data_rf(); //Do if start_send_data button was pressed
task_switch=0;
break;
case 2:
receive_data_pc(25);
task_switch=0;
break;
case 3:
send_data_pc(25);
task_switch=0;
break;
default:
break;
}
}
}
/*************************************** THE END ***************************************/
文章评论(0条评论)
登录后参与讨论