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

📄 blinkingled.c

📁 sypress psoc express 驱动led发光的应用程序.
💻 C
字号:
//*****************************************************************************
//*****************************************************************************
//  FILENAME:  `@LIB_NAME`_BlinkingLed.c
//  Version: 1.1.0.1, Updated on 2007/05/18 at 17:38:12
//  Application: PSoC Express 2.0
//
//  DESCRIPTION:  This is driver for BLINKINGLED.
//-----------------------------------------------------------------------------
//      Copyright (c) Cypress MicroSystems 2004. All Rights Reserved.
//*****************************************************************************
//*****************************************************************************

#include "m8c.h"
#include "`@LIB_NAME`_BlinkingLed.h"
#include "cmx.h"
#include "projectproperties.h"
#include "SystemTimer.h"


BYTE BlinkingLedState[CMX_BLINKINGLED_COUNT];  // Allocate state byte for each instance
BYTE BlinkingLedCount[CMX_BLINKINGLED_COUNT];  // Allocate count byte for each instance
 
//-----------------------------------------------------------------------------
//  FUNCTION NAME: BLINKINGLED_Instantiate(pBlock)
//
//    DESCRIPTION: 
//      Initialize this instance of the BlinkingLED
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: 
//    pPBlock  == Pointer to parameter block.
//
//  RETURNS: None
//
//  SIDE EFFECTS: 
//
//  THEORY of OPERATION or PROCEDURE: 
//
////////////////////////////////////////////////////////////////////////////////

void CMX_BLINKINGLED_Instantiate(const CMX_BLINKINGLED_ParameterBlock * pPBlock)
{
    BYTE Blink_pin;
	BYTE Blink_port;
	BYTE PPChan;

	PPChan = DIOChannelPins[(pPBlock->BLINKINGLED_ChannelID)];   // Get pin and port info
	Blink_pin = pinlu[(BYTE)(PPChan & 0x0F)];              // Create pin mask
	Blink_port = portlu[(BYTE)((PPChan & 0xF0) >>4)];      // Extract port address
	GlobalSelectDisconnect(Blink_pin,Blink_port);          // Disconnect Global
	
	DiscreteDriveMode(Blink_pin, Blink_port, pPBlock->BLINKINGLED_DriveMode); // Set mode to Strong
}
//-----------------------------------------------------------------------------
//  FUNCTION NAME: BLINKINGLED_SetValue(pPBlock,  bMode)
//
//  DESCRIPTION: 
//    Sets LED mode between Off, On, and Blink.
//
//-----------------------------------------------------------------------------
//
//  ARGUMENTS: 
//    pPBlock == Pointer to Parameter block
//    bMode   == New Mode 
//               0 = Off
//               1 = On
//               2 = Blink
//
//
//  RETURNS: None
//
//  SIDE EFFECTS: 
//
//  THEORY of OPERATION or PROCEDURE: 
//
////////////////////////////////////////////////////////////////////////////////

void CMX_BLINKINGLED_SetValue(const CMX_BLINKINGLED_ParameterBlock * pPBlock, BYTE bMode)
{
    BYTE bPinPort;
    BYTE bInstance;

    bInstance = pPBlock->BLINKINGLED_INSTANCE;
        
    if (bMode >= 2) {    // If Value is 2 or great, put LED in blink mode.

       if ( (SystemTimer_bGetTickCntr() - BlinkingLedCount[bInstance]) >= pPBlock->BLINKINGLED_BlinkRate) {
          BlinkingLedCount[bInstance] = SystemTimer_bGetTickCntr();
          BlinkingLedState[bInstance] ^= 0x01;
       }
       bMode = BlinkingLedState[bInstance];
    }

    bPinPort = DIOChannelPins[(pPBlock->BLINKINGLED_ChannelID)]; 
	if ((pPBlock->BLINKINGLED_DRIVESENSE ^ bMode ) == 0) {   // Set LED to ON or OFF depending on mode.
       DISetPin(bPinPort,1);
    } else {
       DISetPin(bPinPort,0);
    }
}

⌨️ 快捷键说明

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