Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ------------------------------------------------------------------------------------------------
- * MSP430 Board - Portable Radio Operation - Tranmissor and Receptor!
- * Copyright ©2011 - Version 0.02
- * File: functions.h
- * Blog: http://OAKcoders.com/ (Access it)!
- * (Functions by #Utroz# & #Kaddoush#)
- * ------------------------------------------------------------------------------------------------
- */
- /* Low Power Mode */
- #ifdef __LOW_MODE_ON
- #define __ENERGY_HUNGRY LPM_3 /* Set a low power mode on BIT_SR_register - Options: (LPM_0(G.I) to LPM_4)*/
- #endif
- #include "mrfi.h"
- void __start_clock_signal(uint32_t arg);
- void __push_button_modules(void);
- void __board_mode(void);
- /* This is responsible to check Current LED Color */
- typedef int8_t __LED_status;
- /* Led Default Value */
- #define LED_RED BIT0
- #define LED_GREEN BIT1
- /* Define a LED out status */
- #define LED_OUT P1OUT
- /* This function turn LED off */
- #define TURN_LED_OFF() LED_OUT &= 0x00;
- #define LED_COLOR_CHECK() if(i == LED_RED) i++; else i--;
- /* ---------------------------
- * The line below switches a board status, if argument is a 1, it enter on first mode,
- * that is, enables the (G.I) and (LPM 3) turn on; else if result is other, then it entered only in (G.I). */
- #define LPM_0 0x00 // Only Global Interruption
- #define LPM_1 0x01 // Low Power Mode 1
- #define LPM_2 0x02 // Low Power Mode 2
- #define LPM_3 0x03 // Low Power Mode 3
- #define LPM_4 0x04 // Low Power Mode 4
- //-----------------------
- /* ------------------------------------------------------------------------------------------------
- * MSP430 Board - Portable Radio Operation - Tranmissor and Receptor!
- * Copyright ©2011 - Version 0.02
- * File: functions.c
- * Blog: http://OAKcoders.com/ (Access it)!
- * (Functions by #Utroz# & #Kaddoush#)
- * ------------------------------------------------------------------------------------------------
- */
- #include "functions.h"
- void __start_clock_signal(uint32_t arg)
- {
- /* Clock Signal */
- BCSCTL3 |= LFXT1S_2;
- TACCTL0 = CCIE; /* Enable a timer interruption */
- TACCR0 = arg; // Delay.
- TACTL = MC_1+TASSEL_1;
- }
- void __push_button_modules(void)
- {
- /* Enable the internal resistor of
- * the button */
- P1REN |= 0x04;
- /* Enable interruption on P1.2 */
- P1IE |= 0x04;
- }
- /* Set a value to low power mode */
- void __board_mode(void)
- {
- #if (__ENERGY_HUNGRY == LPM_0)
- __bis_SR_register(GIE);
- #elif (__ENERGY_HUNGRY == LPM_1)
- __bis_SR_register(GIE+LPM1_bits);
- #elif (__ENERGY_HUNGRY == LPM_2)
- __bis_SR_register(GIE+LPM2_bits);
- #elif (__ENERGY_HUNGRY == LPM_3)
- __bis_SR_register(GIE+LPM3_bits);
- #elif (__ENERGY_HUNGRY == LPM_3)
- __bis_SR_register(GIE+LPM4_bits);
- #else NULL;
- #endif
- }
- //-----------------------
- /* ------------------------------------------------------------------------------------------------
- * MSP430 Board - Portable Radio Operation - Tranmissor and Receptor!
- * Copyright ©2011 - Version 0.02
- * File: main.c
- * Blog: http://OAKcoders.com/ (Access it)!
- * (CC2500 Transmissor / Receptor by #Utroz# & #Kaddoush#)
- * ------------------------------------------------------------------------------------------------
- */
- /* Setting Defaults */
- #define __RADIO_ON /* Enable/Disable a MRFI(RADIO) - Options: (ON/OFF) */
- #define __MRFI_RX /* Enable Transmissor or Receptor - Op: (TR/RX) */
- #define __LOW_MODE_ON /* Enable/Disable Low Power Mode - Op: (ON/OFF) */
- #define __BUTTON_ON /* Enable/Disable a Push Button! - Op: (ON/OFF) */
- #include "functions.h"
- /* This variable is responsible to alternative LED */
- __LED_status i = 0x01;
- int main( void )
- {
- /* This function disable the watchdog, initialize the MCLK at 8 MHz,
- * set LED ports as outputs and the button port as input */
- BSP_Init();
- #ifdef __RADIO_ON
- /* This function initialize 6 wires between the MSP 430 and the CC2500, powers-up the
- * CC2500 and configures the CC2500 47 registers and turns on interrupts from the CC2500 */
- MRFI_Init();
- /* Wakes up the radio, it turns on the 26MHz crystal attach to it without entering
- * RX or TX mode */
- MRFI_WakeUp();
- #endif
- #ifdef __MRFI_RX
- /* Switches the radio to RX mode; from this line on, it can receive packets, in which case
- * the interruption function MRFI_RxCompleteISR is called */
- MRFI_RxOn();
- LED_OUT |= LED_RED;
- __start_clock_signal(0x9C40); /* Signal Clock modules */
- #else
- LED_OUT |= LED_GREEN;
- #endif
- #ifdef __BUTTON_ON
- __push_button_modules(); /* Starting a push button modules... */
- #endif
- #ifdef __LOW_MODE_ON
- __board_mode(); /* Enable a global interruption or/and Low Power Mode */
- #endif
- }
- /* Transmissor */
- #ifdef __MRFI_TR
- /* Push Button Interrupt */
- #pragma vector =PORT1_VECTOR
- __interrupt void Port_1 (void)
- {
- P1IFG &= ~0x04;
- mrfiPacket_t packet;
- /* The first byte is the length of the payload together with source
- * and destination address */
- packet.frame[0]=8+20;
- /* This function is responsible
- * to send packets */
- MRFI_Transmit(&packet , MRFI_TX_TYPE_FORCED);
- P1OUT ^= 0x02;
- }
- /* Receptor */
- #else
- /* This function is called when a packet is received */
- void MRFI_RxCompleteISR()
- {
- /* This functions is responsible to check delay color */
- LED_COLOR_CHECK();
- /* Turns off Led's */
- TURN_LED_OFF();
- }
- /* Push Button Interrupt */
- #pragma vector =PORT1_VECTOR
- __interrupt void Port_1 (void)
- {
- P1IFG &= ~0x04;
- LED_COLOR_CHECK();
- TURN_LED_OFF();
- }
- /* Timer Interrupt by Clock Signal */
- #pragma vector =TIMERA0_VECTOR
- __interrupt void Timer_A (void)
- {
- if(i == LED_RED) LED_OUT ^= LED_RED;
- else LED_OUT ^= LED_GREEN;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement