cpu.c

来自「利用winavr开发的一款三段式充电器的源码」· C语言 代码 · 共 68 行

C
68
字号
/*****************************************************************
** Project:		充电器
** file : 			cpu.c
** date : 			20081205
** author:
** version:		v1.0		   
** description:		底层硬件初始化
** ---------------------------------------------------------------
** date : 			 
** author:
** version:		 	   
** description:		 
******************************************************************/


#include "main.h"
  
void  TimerInit(void)
{

#if defined (__AVR_ATmega48__)  || defined(__AVR_ATmega88__) 
  /*t0 initailize*/
  TCCR0B  =  0x00; 									//stop
  //TCCR0 |= (1<<CS02)|(1<<CS00);                   //1024 div
  TCCR0B  = (1<<CS02);                               //256 div
  TCNT0  = T0_BGN_VAL;                              //load the bgein val
  TIMSK0  |=(1<<TOIE0);                              //enable the t0 overflow intterrupt
	
  /*t1 intialize*/
  TCCR1B  	=  0x00; 								//stop
  TCCR1B  	|= (1<<CS11); 							//8分频 1MHZ   最小节拍1us
  TCNT1     = (65535 - 50000);						//50ms中断一次						
  TIMSK1  |=(1<<TOIE1);                              //enable the t0 overflow intterrupt

#elif defined (__AVR_ATmega8__)

  /*t0 initailize*/
  TCCR0  =  0x00; 									//stop
  //TCCR0 |= (1<<CS02)|(1<<CS00);                   //1024 div
  TCCR0  = (1<<CS02);                               //256 div
  TCNT0  = T0_BGN_VAL;                              //load the bgein val
  TIMSK  |=(1<<TOIE0);                              //enable the t0 overflow intterrupt
	
  /*t1 intialize*/
  TCCR1B  	=  0x00; 								//stop
  TCCR1B  	|= (1<<CS11); 							//8分频 1MHZ   最小节拍1us
  TCNT1     = (65535 - 50000);						//50ms中断一次						
  TIMSK  |=(1<<TOIE1);                              //enable the t0 overflow intterrupt
#endif

}
















⌨️ 快捷键说明

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