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

📄 timer.c

📁 sunplus spca514 cdmp3 源码
💻 C
字号:
#include "iom163.h"
#include "timer.h"
#include "main.h"
//unsigned int CntHigh=0;
extern unsigned char tick_flag,tape_rotate_cnt;
/* clk/8 1us 8MHZ*/
void init_timer(void)
{
 	 	//
		//TCCR0= 0x00; //stop
 		//TCNT0= 254; //set count
 		//TCCR0= 0x06; //start timer: EXTERN FALLING
		
		TCCR2= 0x00; //stop 
 		ASSR= 0x00; 
 		TCNT2= CNT0VALUE; //setup
 		//OCR2= 0x9C; //set compare value
 		TCCR2= 0x07; //start

		
		TCCR1B= 0x00; //stop
		TCCR1A= 0x00;//com1x1\com1x0:disconnect from output pin
			   	 	  //FOC1A\FOC1B:0\0
					  //PWM10\PWM11:0\0 DISABLE
		
        TCNT1H = 0; //
        TCNT1L = 0; //
		
       // OCR1AH = 0x27;
       // OCR1AL = 0x10;
       // OCR1BH = 0x27;
       // OCR1BL = 0x10;
		TIMSK |= 0x61;  // TIMER0 OVERFLOW INTERRUPT/TIMER1 CAPTUER
        TCCR1B = 0x82; // CK/8 8MHZ 1uS
		
}

//#pragma interrupt_handler timer0_ovf_isr:10
//void timer0_ovf_isr(void)
//{
 // TCNT0 = 254;
  //tape_rotate_cnt = 0;
//}
//0X10
#pragma interrupt_handler timer2_ovf_isr:5
void timer2_ovf_isr(void)
{
  static unsigned char tick_counter=0;
  
  TCNT2 = CNT0VALUE; //
  
  tick_flag = TICK_20MS;
  tick_counter++;
  //if(tick_count==5)
  // tick_flag |=TICK_100MS;
  if(tick_counter>9)
  {
   tick_counter=0;
   tick_flag |= TICK_200MS;
  }
 // SEI();
}


void delay_us( unsigned int period_us )
{
  unsigned int count1, count2, diff;
  
	count1 = TCNT1H*256+TCNT1L;
	
    diff = 0;

  while (diff < period_us)
  {
	count2 =TCNT1H*256+TCNT1L;
	if ( count2 < count1 ) 
	{
	  diff = (65535 - count1) + count2 + 1;
	}
	else
	{
	  diff = (count2 - count1);
	}
  }

}

void delay_ms(unsigned int ms)
{
  while(ms--)
  {
    delay_us(1000);
  }
}

⌨️ 快捷键说明

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