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

📄 lights.c

📁 eaayarm101自制小车源代码 周立功公司原创
💻 C
📖 第 1 页 / 共 2 页
字号:
//! \return None.
//
//*****************************************************************************
void
LightsOn(void)
{
    //
    // Turn on both headlights.
    //
    LightLeftOn();
    LightRightOn();
}

//*****************************************************************************
//
//! Turns the headlights off.
//!
//! This function will turn off both headlights; if either headlight is already
//! off it will remain off.
//!
//! \return None.
//
//*****************************************************************************
void
LightsOff(void)
{
    //
    // Turn off both headlights.
    //
    LightLeftOff();
    LightRightOff();
}

//*****************************************************************************
//
//! Turns the left headlight on.
//!
//! This function will turn on the left headlight; if it is already on it will
//! remain on.
//!
//! \return None.
//
//*****************************************************************************
void
LightLeftOn(void)
{
    //
    // Disable the comparator interrupt.
    //
    HWREG(COMP_BASE + COMP_O_INTEN) = 0;

    //
    // Turn off the GPIO output.
    //
    HWREG(HL_LEFT_PORT + GPIO_O_DATA + (HL_LEFT_PIN << 2)) = 0;

    //
    // Indicate that the left headlight is on.
    //
    g_ucLights |= FRONT_LEFT;
}

//*****************************************************************************
//
//! Turns the left headlight off.
//!
//! This function will turn off the left headlight; if it is already off it
//! will remain off.
//!
//! \return None.
//
//*****************************************************************************
void
LightLeftOff(void)
{
    //
    // Disable the comparator interrupt.
    //
    HWREG(COMP_BASE + COMP_O_INTEN) = 0;

    //
    // Turn on the GPIO output.
    //
    HWREG(HL_LEFT_PORT + GPIO_O_DATA + (HL_LEFT_PIN << 2)) = HL_LEFT_PIN;

    //
    // Indicate that the left headlight is off.
    //
    g_ucLights &= ~(FRONT_LEFT);
}

//*****************************************************************************
//
//! Turns the right headlight on.
//!
//! This function will turn on the right headlight; if it is already on it will
//! remain on.
//!
//! \return None.
//
//*****************************************************************************
void
LightRightOn(void)
{
    //
    // Disable the comparator interrupt.
    //
    HWREG(COMP_BASE + COMP_O_INTEN) = 0;

    //
    // Turn off the GPIO output.
    //
    HWREG(HL_RIGHT_PORT + GPIO_O_DATA + (HL_RIGHT_PIN << 2)) = 0;

    //
    // Indicate that the right headlight is on.
    //
    g_ucLights |= FRONT_RIGHT;
}

//*****************************************************************************
//
//! Turns the right headlight off.
//!
//! This function will turn off the right headlight; if it is already off it
//! will remain off.
//!
//! \return None.
//
//*****************************************************************************
void
LightRightOff(void)
{
    //
    // Disable the comparator interrupt.
    //
    HWREG(COMP_BASE + COMP_O_INTEN) = 0;

    //
    // Turn on the GPIO output.
    //
    HWREG(HL_RIGHT_PORT + GPIO_O_DATA + (HL_RIGHT_PIN << 2)) = HL_RIGHT_PIN;

    //
    // Indicate that the right headlight is off.
    //
    g_ucLights &= ~(FRONT_RIGHT);
}

//*****************************************************************************
//
//! Sets the headlights to automatic mode.
//!
//! This function will put the headlights into automatic mode, where they will
//! come on if it is too dark (i.e. at "night") and turn off if it is too light
//! (i.e. during the "day").
//!
//! \return None.
//
//*****************************************************************************
void
LightsAutomatic(void)
{
    //
    // Enable the comparator interrupt.
    //
    HWREG(COMP_BASE + COMP_O_INTEN) = COMP_INT_0;

    //
    // Call the comparator interrupt handler (to get the initial state set).
    //
    CompIntHandler();
}

//*****************************************************************************
//
//! Turns up the trip point on the headlights.
//!
//! This function turns up the trip point for the headlights when in automatic
//! mode.  A higher trip point causes the headlights to turn on/off at a higher
//! ambient light level.
//!
//! \return None.
//
//*****************************************************************************
void
LightTripPointUp(void)
{
    //
    // See if the trip point is already at the maximum.
    //
    if(g_ucLightTripPoint != 15)
    {
        //
        // Increase the light trip point.
        //
        g_ucLightTripPoint++;

        //
        // Adjust the comparator reference voltage.
        //
        HWREG(COMP_BASE + COMP_O_REFCTL) = (COMP_REFCTL_EN | COMP_REFCTL_RNG |
                                            g_ucLightTripPoint);
    }
}

//*****************************************************************************
//
//! Turns down the trip point on the headlights.
//!
//! This function turns down the trip point for the headlights when in
//! automatic mode.  A lower trip point causes the headlights to turn on/off at
//! a lower ambient light level.
//!
//! \return None.
//
//*****************************************************************************
void
LightTripPointDown(void)
{
    //
    // See if the trip point is already at the maximum.
    //
    if(g_ucLightTripPoint != 0)
    {
        //
        // Decrease the light trip point.
        //
        g_ucLightTripPoint--;

        //
        // Adjust the comparator reference voltage.
        //
        HWREG(COMP_BASE + COMP_O_REFCTL) = (COMP_REFCTL_EN | COMP_REFCTL_RNG |
                                            g_ucLightTripPoint);
    }
}

//*****************************************************************************
//
//! Turns the tail lights on.
//!
//! This function will turn on both tail lights; if either tail light is
//! already on it will remain on.
//!
//! \return None.
//
//*****************************************************************************
void
TailLightsOn(void)
{
    //
    // Turn on both tail lights.
    //
    TailLightLeftOn();
    TailLightRightOn();
}

//*****************************************************************************
//
//! Turns the tail lights off.
//!
//! This function will turn off both tail lights; if either tail light is
//! already off it will remain off.
//!
//! \return None.
//
//*****************************************************************************
void
TailLightsOff(void)
{
    //
    // Turn off both tail lights.
    //
    TailLightLeftOff();
    TailLightRightOff();
}

//*****************************************************************************
//
//! Turns the left tail light on.
//!
//! This function will turn on the left tail light; if it is already on it will
//! remain on.
//!
//! \return None.
//
//*****************************************************************************
void
TailLightLeftOn(void)
{
    //
    // Turn off the GPIO output.
    //
    HWREG(TL_LEFT_PORT + GPIO_O_DATA + (TL_LEFT_PIN << 2)) = 0;

    //
    // Indicate that the left tail light is on.
    //
    g_ucLights |= BACK_LEFT;
}

//*****************************************************************************
//
//! Turns the left tail light off.
//!
//! This function will turn off the left tail light; if it is already off it
//! will remain off.
//!
//! \return None.
//
//*****************************************************************************
void
TailLightLeftOff(void)
{
    //
    // Turn off the GPIO output.
    //
    HWREG(TL_LEFT_PORT + GPIO_O_DATA + (TL_LEFT_PIN << 2)) = TL_LEFT_PIN;

    //
    // Indicate that the left tail light is off.
    //
    g_ucLights &= ~(BACK_LEFT);
}

//*****************************************************************************
//
//! Turns the right tail light on.
//!
//! This function will turn on the right tail light; if it is already on it
//! will remain on.
//!
//! \return None.
//
//*****************************************************************************
void
TailLightRightOn(void)
{
    //
    // Turn on the GPIO output.
    //
    HWREG(TL_RIGHT_PORT + GPIO_O_DATA + (TL_RIGHT_PIN << 2)) = 0;

    //
    // Indicate that the right tail light is on.
    //
    g_ucLights |= BACK_RIGHT;
}

//*****************************************************************************
//
//! Turns the right tail light off.
//!
//! This function will turn off the right tail light; if it is already off it
//! will remain off.
//!
//! \return None.
//
//*****************************************************************************
void
TailLightRightOff(void)
{
    //
    // Turn off the GPIO output.
    //
    HWREG(TL_RIGHT_PORT + GPIO_O_DATA + (TL_RIGHT_PIN << 2)) = TL_RIGHT_PIN;

    //
    // Indicate that the right tail light is off.
    //
    g_ucLights &= ~(BACK_RIGHT);
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

⌨️ 快捷键说明

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