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

📄 led.c

📁 build a modbus client/server for use on the Protocessor (from FieldServer Technologies) Tools Req
💻 C
字号:
/*******************************************************************************

                                   Ledc

********************************************************************************

   Written by:   Bennie de Wet

   nSoft Developement.

********************************************************************************

 Version

  0.00aA  12 Aug 04 BDW  Cleaning up
  0.00aB  14 Aug 04 BDW  Patching in data handeling
  0.00aD  15 Sep 04 BDW  Making build compatible with new Protocessors
  0.00aG  08 Oct 04 BDW  Preping for first release to Douglas

*******************************************************************************/

#include <fst.h>

#if defined ( P18F6720 )
#include <p18f6720.h>
#elif defined (P18F6520)
#include <p18f6520.h>
#else
#error must defined P18F6X20 compiler option
#endif

//LED Ports on the Protocessor(18f6x20)
#define DDR_LEDS        DDRA
#define LEDS            PORTA
#define WORKING         PORTAbits.RA0
#define PANIC           PORTAbits.RA2  // Not connected at this time
#define LED_ON          0
#define LED_OFF         1




//=============================================================================

VOID tk_panic ( INT error )
{
   static INT tst = 0 ;
   tst++;
}


//=============================================================================

static BYTE led_state = 0x07 ;  // Leds off by default

VOID led_init()
{
   DDR_LEDS = 0 ;       // LED port all outputs
   LEDS = led_state ;
}


//=============================================================================

VOID led_on ( INT nr )
{

   BYTE mask = ~( 1 << nr ) & 0x07; // Only want first 3 bits
   led_state &= mask ;

   LEDS = led_state ;
}


//=============================================================================

VOID led_off ( INT nr )
{
   BYTE mask = ( 1 << nr ) & 0x07; // Only want first 3 bits
   led_state |= mask ;

   LEDS = led_state ;
}


//=============================================================================

VOID led_toggle ( INT nr )
{
   if ( (led_state>>nr) & 0x1 )
      {
      led_on(nr);
      }
   else
      {
      led_off(nr);
      }
}


//=============================================================================

VOID led_run ( )
{
   static UINT32 start_time = 0 ;

   if ( !start_time )
      {
      start_time = get_milliseconds();
      }

   if ( get_milliseconds () - start_time > (UINT32)200 )
      {
      led_toggle(0);
      start_time = get_milliseconds();
      }
}


//=============================================================================


⌨️ 快捷键说明

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