timer.c.bak

来自「嵌入式单片机控制温度传感的无线收发方案!」· BAK 代码 · 共 69 行

BAK
69
字号
//ICC-AVR application builder : 2008-7-29 14:35:46
// Target : M8
// Crystal: 4.0000Mhz
#include "confg.h"

unsigned int i=0,count=0,flag=0;
int number;

//TIMER0 initialisation - prescale:1024
// WGM: Normal
// desired value: 10mSec
// actual value: 9.984mSec (0.2%)
void timer0_init(void)
{

  TCCR0 = 0x00; //stop
 TCNT0 = 0x64; //set count
 TCCR0 = 0x04; //start timer
}


#pragma interrupt_handler time0:10
void time0(void)
{
  TCNT0 = 0x64; //set count
  count++;
  if(count==number) 
  {
  TIMSK=0x00;
  CLI();
  flag=1;
  }
}
//call this routine to initialise all peripherals
void init_devices1(void)
{
 
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 timer0_init();
 count=0;
 flag=0;
 
 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x01; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}
int delay_10ms(int no)
{
  number=no;
  init_devices1();
 while(1) 
 {
  if(flag==1)
  break;
  }
  return 0;
}


void delay_us(uint us)
{
  uint m;
  for (m=0;m<us;m++)
  {NOP();NOP();NOP();NOP();NOP();NOP();
  }
}

⌨️ 快捷键说明

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