This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

怎么在2个板子之间把温度传感器得到的温度传过去

Other Parts Discussed in Thread: CC430F5137, CC1101

CC430F5137的板子2的程序如下,怎么改下板子2的程序,使得上面通过温度传感器得到的温度示数传到板子1上面去?

/******************************************************************************
* CC430 RF Code Example - TX and RX (variable packet length =< FIFO size)
*
* Simple RF Link to Toggle Receiver's LED by pressing Transmitter's Button
* Warning: This RF code example is setup to operate at either 868 or 915 MHz,
* which might be out of allowable range of operation in certain countries.
* The frequency of operation is selectable as an active build configuration
* in the project menu.
*
* Please refer to the appropriate legal sources before performing tests with
* this code example.
*
* This code example can be loaded to 2 CC430 devices. Each device will transmit
* a small packet upon a button pressed. Each device will also toggle its LED
* upon receiving the packet.
*
* The RF packet engine settings specify variable-length-mode with CRC check
* enabled. The RX packet also appends 2 status bytes regarding CRC check, RSSI
* and LQI info. For specific register settings please refer to the comments for
* each register in RfRegSettings.c, the CC430x613x User's Guide, and/or
* SmartRF Studio.
*
* M. Morales
* Texas Instruments Inc.
* February 2010
* Built with IAR v4.21 and CCS v4.1
* DS18B20
******************************************************************************/

#include "../inc/RF_Toggle_LED_Demo.h"

#define PACKET_LEN (0x05) // PACKET_LEN <= 61
#define RSSI_IDX (PACKET_LEN+1) // Index of appended RSSI
#define CRC_LQI_IDX (PACKET_LEN+2) // Index of appended LQI, checksum
#define CRC_OK (BIT7) // CRC_OK bit
// 433MHz下的发射功率宏定义
#define PATABLE_VAL (0xc0) // 0XC4-- 10 dBm;
// 0X50-- 0 dBm;
// 0X2D-- -6 dBm;
// 0X26-- -12dBm;
// 0x05-- -30dBm;
// 0xc0-- max
#define LED_RBIT BIT0
#define LED_GBIT BIT0
#define LED_DIR P1DIR
#define LED_OUT P1OUT
#define LED_SEL P1SEL
#define LEDR_ON() LED_OUT|=LED_RBIT
#define LEDG_ON() LED_OUT|=LED_GBIT
#define LEDR_OFF() LED_OUT&=~LED_RBIT
#define LEDG_OFF() LED_OUT&=~LED_GBIT

#define BUTTON_BIT 0
#define BUTTON_DIR PJDIR
#define BUTTON_OUT PJOUT
#define BUTTON_REN PJREN
#define BUTTON_IN PJIN

#define CHANNEL 2


extern RF_SETTINGS rfSettings;

unsigned char packetReceived;
unsigned char packetTransmit;

unsigned char RxBuffer[64];
unsigned char RxBufferLength = 0;
const unsigned char TxBuffer[6]= {PACKET_LEN, 0x27, 'J', 'X', 'H', CHANNEL};
unsigned char buttonPressed = 0;
unsigned int i = 0,rssi=0;

unsigned char transmitting = 0;
unsigned char receiving = 0;
unsigned char rec_done_flag=0;

unsigned char GET_BUFF[5] = {0,0,0,0,0};

void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;//关闭看门狗
// WDTCTL = WDT_ARST_250;
UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO

__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // Select DCO range 24MHz operation
UCSCTL2 = FLLD_1 + 609; // 374Set DCO Multiplier for 12MHz
// (N + 1) * FLLRef = Fdco
// (374 + 1) * 32768 = 12MHz
// (609 + 1) * 32768 = 20MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop

// Worst-case settling time for the DCO when the DCO range bits have been
// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization.
// 32 x 32 x 12 MHz / 32,768 Hz = 375000 = MCLK cycles for DCO to settle
// 32 x 32 x 20 MHz / 32,768 Hz = 625000 = MCLK cycles for DCO to settle
__delay_cycles(625000);
// Increase PMMCOREV level to 2 for proper radio operation
SetVCore(2);

ResetRadioCore(); //复位cc430 里面的Radio
InitRadio(); //初始化CC430 的Radio 模块
InitButtonLeds(); //初始化按键和LED

USART_Init();

InitializeTFT();
lcd_initial();
LCD_CLEAR();

ReceiveOn(); //开启接收模式
receiving = 1;
_EINT();
while (1)
{
// WDTCTL = WDT_ARST_250;
// Display_Desc();
// __bis_SR_register( LPM3_bits + GIE );

LCD_P8X16Str(0,0,"OWN CHANNEL:");
LCD_P8X16NUM(96,0,CHANNEL);
LCD_P8X16Str(0,16,"GET CHANNEL:");
LCD_P8X16Str(0,32,"GET RSSI:");
LCD_P8X16Str(0,48,"GET CODE:");
LCD_P8X16Str(0,96,"GET LENGTH:");
LCD_P8X16Str(0,112,"TEMP:");

get_temper(Do1Convert());
LCD_P8X16Str(48,112,tempter);
__no_operation();
if(!(BUTTON_IN & (1<<BUTTON_BIT)))
{
_NOP();
delayms(30);
if(!(BUTTON_IN & (1<<BUTTON_BIT)))
{
_NOP();
LEDR_ON();
ReceiveOff();
receiving = 0;
Transmit( (unsigned char*)TxBuffer,sizeof TxBuffer );
transmitting = 1;
while(!(BUTTON_IN & (1<<BUTTON_BIT)));
}

}
else if(!transmitting)
{
ReceiveOn();//开启接收模式
receiving = 1;
}
if(rec_done_flag)
{
for(i=0;i<3;i++)
{
GET_BUFF[i] = RxBuffer[i+2];
}
LCD_P8X16NUM(96,16,RxBuffer[PACKET_LEN]); //Get Channel
LCD_P8X16Str(0,64,GET_BUFF); //GET CODE
LCD_P8X16NUM(96,96,RxBufferLength); //GET CODE LENGTH
LCD_P8X16NUM(96,32,rssi);

rec_done_flag = 0;
}
}
}

void delayms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<800;j++);
}
}

void InitButtonLeds(void)
{
// Initialize Port J
PJOUT = 0x01;
PJDIR = 0xFF;

// Set up the button as interruptible
BUTTON_DIR&=~(1<<BUTTON_BIT); // 按键设置为输入
BUTTON_REN|=BIT0; // 上拉

// Set up LEDs
LED_OUT&=~(LED_RBIT|LED_GBIT); // LED端口输出0
LED_DIR|=(LED_RBIT|LED_GBIT); // LED端口方向设置为输出
}

void InitRadio(void)
{
// Set the High-Power Mode Request Enable bit so LPM3 can be entered
// with active radio enabled
PMMCTL0_H = 0xA5;
PMMCTL0_L |= PMMHPMRE_L;
PMMCTL0_H = 0x00;

WriteRfSettings(&rfSettings);

WriteSinglePATable(PATABLE_VAL);
}

void Transmit(unsigned char *buffer, unsigned char length)
{
RF1AIES |= BIT9;
RF1AIFG &= ~BIT9; // Clear pending interrupts
RF1AIE |= BIT9; // Enable TX end-of-packet interrupt

WriteBurstReg(RF_TXFIFOWR, buffer, length);

Strobe( RF_STX ); // Strobe STX
}

void ReceiveOn(void)
{
RF1AIES |= BIT9; // Falling edge of RFIFG9
RF1AIFG &= ~BIT9; // Clear a pending interrupt
RF1AIE |= BIT9; // Enable the interrupt

// Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode
Strobe( RF_SRX );
}

void ReceiveOff(void)
{
RF1AIE &= ~BIT9; // Disable RX interrupts
RF1AIFG &= ~BIT9; // Clear pending IFG

// It is possible that ReceiveOff is called while radio is receiving a packet.
// Therefore, it is necessary to flush the RX FIFO after issuing IDLE strobe
// such that the RXFIFO is empty prior to receiving a packet.
Strobe( RF_SIDLE );
Strobe( RF_SFRX );
}

#pragma vector=CC1101_VECTOR
__interrupt void CC1101_ISR(void)
{
switch(__even_in_range(RF1AIV,32)) // Prioritizing Radio Core Interrupt
{
case 0: break; // No RF core interrupt pending
case 2: break; // RFIFG0
case 4: break; // RFIFG1
case 6: break; // RFIFG2
case 8: break; // RFIFG3
case 10: break; // RFIFG4
case 12: break; // RFIFG5
case 14: break; // RFIFG6
case 16: break; // RFIFG7
case 18: break; // RFIFG8
case 20: // RFIFG9
if(receiving) // RX end of packet
{
// Read the length byte from the FIFO
RxBufferLength = ReadSingleReg( RXBYTES );
ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength);

// Stop here to see contents of RxBuffer
__no_operation();

// Check the CRC results
if(RxBuffer[CRC_LQI_IDX] & CRC_OK)
{
rec_done_flag = 1;
}
rssi = RxBuffer[RSSI_IDX]; //get RSSI
}
else if(transmitting) // TX end of packet
{
RF1AIE &= ~BIT9; // Disable TX end-of-packet interrupt
LEDR_OFF(); // Turn off LED after Transmit
transmitting = 0;
}
else while(1); // trap
break;
case 22: break; // RFIFG10
case 24: break; // RFIFG11
case 26: break; // RFIFG12
case 28: break; // RFIFG13
case 30: break; // RFIFG14
case 32: break; // RFIFG15
}
__bic_SR_register_on_exit(LPM3_bits);
}