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

📄 timac1.c

📁 示波器DIY全套资料
💻 C
字号:
#include "eOscope.h"
#include "TIMaC1.h"
#include "CPLDaC1.h"
#include "KBDaC1.h"
typedef struct TIM__tstKeyTag
{
  uint8_t biKey1:1;
  uint8_t biKey2:1;
} TIM__tstKey;

TIM__tstTimeBase TIM__stTimeBase[] = TIM__astTimeBase;

SIGNAL (SIG_OUTPUT_COMPARE3A)
{
  uint8_t u8KeysBuffer;
  static TIM__tstKey stOneTime;

  u8KeysBuffer = CPLD_u8ReadKeys();

  /* Key Trig Down - Continuous */
  if ((u8KeysBuffer & KBD_nTrigDown) == 0)
  {
    if (u8Trigger > EOS_nScreenLimitLow + 1)  
    {
      u8Trigger--;
      u8TrigSemaphore = 1;
    }
    else
    {
      u8Trigger = EOS_nScreenLimitLow;
    }
  }

  /* Key Trig Up - Continuous */
  if ((u8KeysBuffer & KBD_nTrigUp) == 0)
  {
   if (u8Trigger < EOS_nScreenLimitHigh - 2)  
    {
      u8Trigger++;
      u8TrigSemaphore = 1;
    }
    else
    {
      u8Trigger = EOS_nScreenLimitHigh;
    }
  }

  /* Key Time Down - One shot */
  if ((u8KeysBuffer&KBD_nTimeDown) == 0)
  {
    if (stOneTime.biKey1 == 0)
    {
      if (u8IndexTime > 0)
      {
        u8IndexTime--;
      }
      u8TimeSemaphore = 1;
      stOneTime.biKey1 = 1;
    }
  }
  else
  {
    stOneTime.biKey1 = 0;
  }

  /* Key Time Up - One shot */
  if ((u8KeysBuffer&KBD_nTimeUp) == 0)
  {
    if (stOneTime.biKey2 == 0)
    {
      if (u8IndexTime < (sizeof(TIM__stTimeBase)/sizeof(TIM__tstTimeBase))-1)
      {
        u8IndexTime++;
      }
      u8TimeSemaphore = 1;
      stOneTime.biKey2 = 1;
    }
  }
  else
  {
    stOneTime.biKey2 = 0;
  }

  /* Key Offset Down - Continuous */
  if ((u8KeysBuffer & KBD_nOffsetDown) == 0)
  {
    if (TIM__u8OffsetLevel < 255) 
    {
      TIM__u8OffsetLevel++;
    }
  }

  /* Key Offset Up - Continuous */
  if ((u8KeysBuffer & KBD_nOffsetUp) == 0)
  {
    if (TIM__u8OffsetLevel > 0) 
    {
      TIM__u8OffsetLevel--;
    }
  }
}


/* Init procedure for Timer/counter3 */
void TIM_vInitTimer3(uint16_t u16Rate)
{
  TCCR3A&=(~(1<<WGM30));            /* Mode 12: CTC*/
  TCCR3A&=(~(1<<WGM31));
  TCCR3B|=(1<<WGM32);
  TCCR3B|=(1<<WGM33);

  TCCR3B|=(1<<CS30);                /* clock/1024 prescaler */
  TCCR3B&=(~(1<<CS31));
  TCCR3B|=(1<<CS32);

  ICR3 = u16Rate;                   /* counter TOP = u16Rate */

  ETIMSK|=(1<<OCIE3A);              /* enable Timer/Counter1 compare B match */
}


void TIM_vDelay(uint8_t u8Steps)
{
  for (; u8Steps > 0; u8Steps--)
  {
    asm volatile("nop\n\t"::);
  }
}


/* Description: Enables a PWM output for OC1A pin of port D
The value of pulse width itself will be written  using additional macro (see TIMaC1.h)
*/
void TIM_vInitPwmOnTimer1A(void)
{
  /* Set PWM pin as output */
  DDRD |= (1<<TIM__u8PwmOut);


/* Mode 5: FastPWM with OCR as PWM register */
  TCCR1A |= (1<<WGM10);
  TCCR1A &= (~(1<<WGM11));
  TCCR1B |= (1<<WGM12);
  TCCR1B &= (~(1<<WGM13));

/* clock/1 prescaler */
  TCCR1B |= (1<<CS10);
  TCCR1B &= (~(1<<CS11));
  TCCR1B &= (~(1<<CS12));

/* Enable OC1A output for FastPWM mode */
  TCCR1A |= (1<<COM1A0);
  TCCR1A |= (1<<COM1A1);

/* Initial PWM value: middle position for scope trace */
  TIM__u8OffsetLevel = TIM__nInitPwmLevel;

}

⌨️ 快捷键说明

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