time0.c

来自「车载NI_MH快速充电器」· C语言 代码 · 共 50 行

C
50
字号
/********************************************************************************/
//		
// 		builder : 2007-04-10
// 		Target  : ATMEAG 48V
// 		Crystal : 内部 8.00 MHz
//
//		PWM 模块
		
/********************************************************************************/

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/interrupt.h>


#define		uchar	unsigned char
#define		uint	unsigned int


//TIMER0 initialize - prescale:8
// desired value: 1Hz
// actual value: Out of range
void timer0_init(void)	// PWM
{
 	TCCR0B = 0x00; //stop
 	TCNT0  = 0x01; //set count
 	TCCR0A = 0x23; 
 	OCR0A  = 0xff;
}

/*---------------------------------------------------------------
   			PWM 占空比设置 
----------------------------------------------------------------*/

void Pwm_set(uchar pwm)
{
	OCR0B = pwm;
	
	if(TCCR0B == 0)
 	{	
 		TCCR0A = 0x23;//0x23; 
 		TCCR0B = 0x01; 	//start timer
 		
 	}
}

/**************************  the end   ********************************/

⌨️ 快捷键说明

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