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

📄 dc550_leddriver.c

📁 一款经典的数字电话设计资料
💻 C
字号:
/*****************************************************************************/
/*  CONFIDENTIAL                                                             */
/*  Sigpro Copyright 2003, All rights reserved                               */
/*****************************************************************************/
/*  CLIENT:  Telematrix                                                      */
/*  PROJECT: DC550 Digital Centrex Phone                                     */
/*  FILE:    dc550_leddriver.c                                               */
/*****************************************************************************/
/*  The LED Indicator Driver is expected to process commands from the        */
/*  Controller regarding the sixteen LED indicators in the DC550 hardware.   */
/*****************************************************************************/

#define __DC550_LEDDRIVER_EXTERN__
#include "dc550_leddriver.h"


/******************************************************************************
 *  LOCAL CONSTANTS
 *****************************************************************************/
// LED Blink Durations
// These numbers represent the amount of time (in interrupt counts)
// that an LED should be on and off when flashing or winking
#define LEDDRIVER_DURATION_FLASH   (TICKS_PER_SECOND/32) // 125 milliseconds
#define LEDDRIVER_DURATION_WINK    (TICKS_PER_SECOND/8)  // 500 milliseconds


/******************************************************************************
 *  GLOBAL VARIABLES
 *****************************************************************************/
// Used by the timer interrupt
// Keep this even word aligned and packed
// Any changes to this structure will have to be reflected
//   in the assembly code in the timer interrupt
struct str_ledBlinkData {
    unsigned int ctr;
    unsigned int blinkCtr;
};
struct str_ledBlinkData ledBlinkData[LED_INDICATOR_NUMBER];

// This variable is a copy of the current on/off state of
//   each LED.  The timer interrupt uses this variable to
//   set and read the existing state of each LED.
unsigned int            ledState;


/******************************************************************************
 *  FUNCTION: void leddriver_init(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is called during the initialization phase to initialize all
 *  of the LED driver variables and turn the LEDs off.
 *****************************************************************************/
void leddriver_init(void) {
    int i;

    // Make Sure Ports are Set Up Right
    // P2   - outputs: wired to 7 LEDs at a time
    // P4.5 - output: 0=LEDs selected, 1=LCD selected
    //                by default, LEDs will be selected
    // P4.6 - output: toggle to clock P2 data out to LED 0..7
    // P4.7 - output: toggle to clock P2 data out to LED 8..15
    LEDDATA_DIR = 0xFF;
    LEDDATA_OUT = 0xFF;
    LEDCTRL_DIR |= (NLED_EN | LED07CLK | LED815CLK);
    LEDCTRL_OUT &= ~(NLED_EN | LED07CLK | LED815CLK);

    // All LEDs OFF
    ledState = 0xFFFF;

    // Clear Data Structure and Turn Off all LEDs
    for (i=0; i<LED_INDICATOR_NUMBER; i++) {
        ledBlinkData[i].ctr = 0;
        ledBlinkData[i].blinkCtr = 0;
    }
}


/******************************************************************************
 *  FUNCTION: void leddriver_exec(void)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function doesn't do anything at the moment.  All LED status
 *  changes are handled by the timer interrupt.  This ensures that
 *  there won't be any jitter in the blink frequencies.  Also, this
 *  removes the real-time constraints of this function from the
 *  main loop.  The stub remains here in case there's a need later
 *  to do something here.
 *****************************************************************************/
void leddriver_exec(void) {
    return;
}


/******************************************************************************
 *  FUNCTIONS:  void leddOn(DC550LEDIndicator indicator)
 *              void leddOff(DC550LEDIndicator indicator)
 ******************************************************************************
 *  DESCRIPTION:
 *  Helper functions for turning an led on/off.  The LED won't actually
 *  get turned on/off until the next time the timer interrupt runs and
 *  updates the LED states.  This happens every 125 microseconds.
 *****************************************************************************/
static void ledOff(DC550LEDIndicator indicator)
{
    ledState |= (1 << indicator);
}

static void ledOn(DC550LEDIndicator indicator)
{
    ledState &= ~(1 << indicator);
}


/******************************************************************************
 *  FUNCTION: void leddriver_setstate(DC550LEDIndicator indicator,
 *                                    DC550LEDState      state)
 ******************************************************************************
 *  DESCRIPTION:
 *  This function is used externally to change the state of a particular
 *  indicator.  This routine will modify the variables ledBlinkData and
 *  ledState which are used by the timer interrupt to update the LED
 *  states.  The LED state change won't occur until the next time the
 *  timer interrupt runs through the LED status update code which happens
 *  every 125 microseconds.
 *
 *****************************************************************************/
void leddriver_setstate(DC550LEDIndicator indicator,
                        DC550LEDState     state)
{
    switch (state) {
    case (LED_STATE_OFF):
        ledBlinkData[indicator].ctr = 0;
        ledBlinkData[indicator].blinkCtr = 0;
        ledOff(indicator);
        break;
    case (LED_STATE_ON):
        ledBlinkData[indicator].ctr = 0;
        ledBlinkData[indicator].blinkCtr = 0;
        ledOn(indicator);
        break;
    case (LED_STATE_FLASH):
        ledBlinkData[indicator].ctr = 0;
        ledBlinkData[indicator].blinkCtr = LEDDRIVER_DURATION_FLASH;
        ledBlinkData[indicator].ctr = LEDDRIVER_DURATION_FLASH;
        break;
    case (LED_STATE_WINK):
        ledBlinkData[indicator].ctr = 0;
        ledBlinkData[indicator].blinkCtr = LEDDRIVER_DURATION_WINK;
        ledBlinkData[indicator].ctr = LEDDRIVER_DURATION_WINK;
        break;
    }
}

⌨️ 快捷键说明

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