time.c

来自「AVR的SPI的通信例子」· C语言 代码 · 共 51 行

C
51
字号

#include "time.h"
#include <iom16.h>

volatile unsigned char SampleTimeFlag;
volatile unsigned long DelayTime;
volatile unsigned char InDelayTime;
volatile unsigned char TimeOver;


//TIMER0 initialisation - prescale:1024
// WGM: Normal
// desired value: 10mSec
// actual value:  9.984mSec (0.2%)
void Timer0Init(void)
{
 TCCR0 = 0x00;      //stop
 TCNT0 = 0xB9;      //set counter //for 7.3728MHz
 TIMSK|=0x01;       //Enable interrupt
 TCCR0 = 0x05;      //start timer
}


#pragma vector=TIMER2_OVF_vect
__interrupt void Timer2_ovf_isr(void)
{
 TCNT2 = 0x64; //reload counter value
 SampleTimeFlag=1;
}

//TIMER2 initialize - prescale:256
// WGM: Normal
// desired value: 5mSec
// actual value:  4.965mSec (0.7%)
void Timer2Init(void)
{
 TCCR2 = 0x00; //stop
 ASSR  = 0x00; //set async mode
 TCNT2 = 0x64; //setup
 OCR2  = 0x9C;
 TCCR2 = 0x06; //start
 SampleTimeFlag=0;
 TIMSK |=1<<TOIE2;
}






⌨️ 快捷键说明

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