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

📄 timer.c

📁 可用来自做的AVR-USB-ISP的源码,内符电路图,用AVR M8来模拟USB接口
💻 C
字号:
/************************************************************************************************ * Project: generic * Author: Christian Ulrich
 * Contact: christian at ullihome dot de
 * * Creation Date: 2007-03-22 * Copyright: (c) 2007 by Christian Ulrich * License: GPLv2 ***********************************************************************************************/
#include <avr/io.h>#include <avr/interrupt.h>#include "timer.h"
#include "led.h"volatile uint8_t TIMER_timeout;ISR(SIG_OVERFLOW0){
  cli();
  TCNT0 = 50;  TIMER_timeout--;
  if (TIMER_timeout == 0)
#if defined(__AVR_ATmega8__)||defined(__AVR_ATmega16__)||defined(__AVR_ATmega32__)
    TCCR0 = 0; //timer aus#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega88__)
    TCCR0B = 0; //timer aus#endif
  sei();
}
void TIMER_delay(uint8_t timeout)
{
  TIMER_start(timeout);
  while (TIMER_timeout > 0);}void TIMER_start(uint8_t timeout){// 12MHz/64 = 187.5kHz --> 5.333us// overflow every 256 counts = 732.422Hz --> 1.365ms
  sei();  TIMER_timeout = timeout;  TCNT0 = 50;#if defined(__AVR_ATmega8__)||defined(__AVR_ATmega16__)||defined(__AVR_ATmega32__)
  TCCR0 |= (1<<CS00)|(1<<CS01);
  TIMSK |= (1 << TOIE0);#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega88__)
  TCCR0B |= (1<<CS00)|(1<<CS01);
  TIMSK0 |= (1 << TOIE0);#endif
}

⌨️ 快捷键说明

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