⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evboard.c

📁 本程序是基于Zigbee协议的无线温度传感器网络系统
💻 C
字号:
/*
  V0.1 Initial Release   10/July/2006

*/

#include "wx_lrwpan.h"
#include "evbConfig.h"

/*
*2006/08/16 WXL 2.0
*/


/******************************************************************************
* Joystick
*
******************************************************************************/
#define JOYSTICK_PUSH         P2_0
#define JOYSTICK_PRESSED()    JOYSTICK_PUSH
#define INIT_JOYSTICK_PUSH() \
    do {                     \
        P2DIR &= ~0x01;      \
        P2INP |= 0x01;       \
    } while (0)

BOOL joystickPushed( void );



#define JOYSTICK              P0_6
#define INIT_JOYSTICK()       IO_DIR_PORT_PIN(0, 6, IO_IN)
#define ADC_INPUT_JOYSTICK    0x06


#ifdef LRWPAN_RFD
void keyinit(void)
{
	INIT_JOYSTICK();
        IO_DIR_PORT_PIN(0, 1, IO_IN);
	IO_DIR_PORT_PIN(1, 7, IO_IN);
}

UINT8 ScanKey(void)
{
	UINT8 tt;
        if(KEY_CANCEL == 0)return K_CANCEL;
	else if(KEY_OK == 0)return K_OK;
        else
        {
                tt = halAdcSampleSingle(ADC_REF_AVDD, ADC_8_BIT, ADC_INPUT_JOYSTICK);
                if(tt<0x20)return K_UP;
                else if(tt<0x30)return K_DOWN;
                else if(tt<0x39)return K_RIGHT;
                else if(tt<0x50)return K_LIFT;
                else return K_CENTRED;
        }

}
#endif //LRWPAN_RFD



JOYSTICK_DIRECTION getJoystickDirection( void );


EVB_SW_STATE sw_state;



JOYSTICK_DIRECTION getJoystickDirection( void ) {
    INT8 adcValue, i;
    JOYSTICK_DIRECTION direction[2];


    for(i = 0; i < 2; i++){
       adcValue = halAdcSampleSingle(ADC_REF_AVDD, ADC_8_BIT, ADC_INPUT_JOYSTICK);

       if (adcValue < 0x20) {
          direction[i] = UP;
       } else if (adcValue < 0x29) {
          direction[i] = DOWN;
       } else if (adcValue < 0x35) {
          direction[i] = RIGHT;
       } else if (adcValue < 0x45) {
          direction[i] = CENTRED;
       } else if (adcValue < 0x50) {
          direction[i] = LEFT;
       } else {
          direction[i] = CENTRED;
       }
    }

    if(direction[0] == direction[1]){
       return direction[0];
    }
    else{
       return CENTRED;
    }
}

#ifdef LRWPAN_COORDINATOR
void Bk1KeyInit(void)
{
	INIT_JOYSTICK();
        IO_DIR_PORT_PIN(0, 4, IO_IN);
	IO_DIR_PORT_PIN(0, 5, IO_IN);
}


/*********************************************************************************
//函数名:JOYSTICK_DIRECTION Bk1ScanKey(void)
//输入:无
//输出:无
//功能描述:按键扫描
*********************************************************************************/
JOYSTICK_DIRECTION Bk1ScanKey(void)
{
        if(KEY_CANCEL == 0)return CANCEL;
	else if(KEY_OK == 0)return OK;
        else return CENTRED;
}
#endif

#define SW_POLL_TIME   MSECS_TO_MACTICKS(100)

UINT32 last_switch_poll;
//poll the switches
void evbPoll(void){

//only do this if the slow timer not enabled as reading
//the joystick takes a while. If the slowtimer is enabled,
//then that interrupt is handing polling
#ifndef LRWPAN_ENABLE_SLOW_TIMER
  if ( halMACTimerNowDelta(last_switch_poll) > SW_POLL_TIME) {
   evbIntCallback();
   last_switch_poll = halGetMACTimer();
  }
#endif

}

//init the board
void evbInit(void){
  halInit();
  INIT_JOYSTICK();
  sw_state.val = 0;
  INIT_LED1();
  INIT_LED2();
}

void evbLedSet(BYTE lednum, BOOL state) {
    switch(lednum) {
       case 1:    if (state) LED1_ON(); else LED1_OFF(); break;
       case 2:    if (state) LED2_ON(); else LED2_OFF(); break;
    }
}

BOOL evbLedGet(BYTE lednum){
  switch(lednum) {
       case 1:    return(LED1_STATE());
       case 2:    return(LED2_STATE());
    }
  return(FALSE);
}


//if joystick pushed up, consider this a S1 button press
//if joystick pushed down, consider this a S2 button press
//does not allow for both buttons to be pressed at once
//tgl bits are set if the state bits become different

void evbIntCallback(void){

  JOYSTICK_DIRECTION x;
  x = getJoystickDirection();
  if (x == CENTRED) {
    sw_state.bits.s1_val = 0;
    sw_state.bits.s2_val = 0;
  }
  else  if (x == UP) sw_state.bits.s1_val = 1;
  else if (x == DOWN) sw_state.bits.s2_val = 1;
  if (sw_state.bits.s1_val != sw_state.bits.s1_last_val) sw_state.bits.s1_tgl = 1;
  if (sw_state.bits.s2_val != sw_state.bits.s2_last_val) sw_state.bits.s2_tgl = 1;
  sw_state.bits.s1_last_val = sw_state.bits.s1_val;
  sw_state.bits.s2_last_val = sw_state.bits.s2_val;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -