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

📄 timer0.c

📁 AVR Mega88 + nRF24L01 wireless 2.4GHz >> Driver nRF24L01 >> AVRSTUDIO project
💻 C
字号:
#include <avr/io.h>
#include <avr/interrupt.h> 
#include "timer0.h"
#include "myDef.h"

volatile unsigned int CountMilliseconds = 0;

SIGNAL(SIG_OVERFLOW0)
{

 TCNT0 -= INTS_PER_milSECOND;
 
 CountMilliseconds = milseconds;

 if(milseconds>=65535)
 {
 	milseconds=0;
 }else
    milseconds++;
 
 
}

enum {
  STOP             = 0,
  CK               = 1,
  CK8              = 2,
  CK64             = 3,
  CK256            = 4,
  CK1024           = 5,
  T0_FALLING_EDGE  = 6,
  T0_RISING_EDGE   = 7
};

void Timer0_Init(void)
{
// Timer/Counter 0 initialization
// (for system Clock = 12.000.000)
// Clock source: System Clock
// Mode: Normal top=FFh
// OC0 output: Disconnected
 TCCR0B = CK1024;
 TCNT0 = INTS_PER_milSECOND;  // reload

//   12000000/1024 = 11718.75
//   Fosc / second  =  1/11718.75 = 85.3us
//   caculate 1ms reload (1/1000)/64us = 0.001/(85.3*10-6) = 11.7 ~ 12
//   TCNT0 = 12 for timer0 count 1ms        
//   default  INTS_PER_milSECOND = 12

// OCR0  = 0x00;
// Tier(s)/Counter(s) Interrupt(s) initialization
 TIMSK0 |= 0x01;
}


⌨️ 快捷键说明

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