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

📄 i_output.c

📁 充电器源代码 才有AVR CPU 控制 可以对大部分电池充电
💻 C
字号:
/******************************************************************************
*  name: i_output.c
*  author: fengzai(panda)
*  date: 2006.1.7
*  describe: 输出确定的电流
*******************************************************************************/

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "adc.h"
#include "i_output.h"

//定时T1初始化
void timer1_init(void)
{
	TCCR1B = 0x00;//停止定时器
	TIMSK |= 0x00;//中断允许
	TCNT1H = 0x00;
	TCNT1L = 0x00;//初始值
	OCR1AH = 0x01;
	OCR1AL = 0xFF;//匹配A值
	OCR1BH = 0x01;
	OCR1BL = 0xFF;//匹配B值
	ICR1H  = 0x00;
	ICR1L  = 0x63;//输入捕捉匹配值
	TCCR1A = 0x93;
	TCCR1B = 0x09;//启动定时器
}


/*----------------------------------------------------------------------------
* pwm输出函数, 0-1023 共2^10级
* pwm_n 0-1023
------------------------------------------------------------------------------*/
void pwm_output(unsigned int pwm_n)
{
 unsigned char temp_L,temp_H;

 temp_H = (unsigned char)(pwm_n>>8);
 temp_L = (unsigned char)((pwm_n<<8)>>8);

 OCR1AH = temp_H;
	OCR1AL = temp_L;//匹配A值
}

/*-----------------------------------------------------------------------------
*  电流控制函数,按设定的电流进行充电,OK!
*----------------------------------------------------------------------------*/
void current_control(unsigned int i)
{
  unsigned int pwm_t=PWM_CURRENT_SATRT;
  unsigned int i_t=0;  //存放临时电流大小
  pwm_output(1024);
  //_delay_ms(1000);
  //_delay_ms(1000);
  //_delay_ms(1000);
  //_delay_ms(1000);
  //_delay_ms(1000);   //等待5s钟
  while(i_t<i)
  {
    pwm_t -= CURRENT_CONTROL_T ;
    pwm_output(pwm_t);
    //_delay_ms(100);
    i_t = charge_current();  //测量电流多大
    send_int(i_t);
    send_int(pwm_t);
  }
}

/*------------------------------------------------------------------------------
*  涓流控制函数,电流上升较慢
*-----------------------------------------------------------------------------*/
void purling_current_control(unsigned int i)
{
  unsigned int pwm_t = PWM_CURRENT_SATRT;
  unsigned int i_t=0;  //存放临时电流大小
  pwm_output(1024);
  //_delay_ms(1000);
  //_delay_ms(1000);
  //_delay_ms(1000);
  //_delay_ms(1000);
  //_delay_ms(1000);   //等待5s钟
  while(i_t<i)
  {
    pwm_t -= PURLING_CURRENT_CONTROL_T ;
    pwm_output(pwm_t);
    //_delay_ms(100);
    i_t = charge_current();  //测量电流多大
    send_int(i_t);
    send_int(pwm_t);
  }
}


/*------------------------------------------------------------------------------
*   end of file
*-----------------------------------------------------------------------------*/



⌨️ 快捷键说明

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