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

📄 timer.c

📁 嵌入式单片机控制温度传感的无线收发方案!
💻 C
字号:
//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;
  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;
 
 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;
}
*/

int delay_10ms(int no)
{
  for(;no>0;no--)
   for (i=0;i<700;i++) ;
   
    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -