合泰单片机智能充电器主程序HT46R47 - main

更新时间:2023-11-19 23:34:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

#include \

//---------------def----------------------- //pa

#define _pac0 _13_0 #define _pac1 _13_1 #define _pac2 _13_2 #define _pac3 _13_3 #define _pac4 _13_4 #define _pac5 _13_5 #define _pac6 _13_6 #define _pac7 _13_7 //pb

#define _pbc0 _15_0 #define _pbc1 _15_1 #define _pbc2 _15_2 #define _pbc3 _15_3 //pd

#define _pdc0 _19_0

#define CN_DOWN _pa1 #define JM _pa4 #define LED_GREEN _pa5 #define LED_RED _pa6 #define FAN _pa7 #define PWM_IO _pd0

#define C_SAMP 0x00 #define BT_SAMP 0x01 #define V_SAMP 0x02

#define TIM_PRE 7200 //pre 2H-7200 #define TIM_NOML 43920 //CC/CV 12.2H=13H

#define OVER_VOLTAGE 0x0c5 //43.57V

#define LOW_VOLTAGE 0x068 //24V 0x06b //#define OVER_CURRENT 0x0062 //3.9A 10.5A #define PRE_CHARGER 0x088 //30V #define FULL_DOWN_V 0x0b5 //40V #define FULL_CURRENT 0x05f //0.2A

#define N20C_NTC 0x0ec //-20度 #define _0C_NTC 0x0d7 //0度

#define _45C_NTC 0x089 //45度 0x07e

//---------------var----------------------- unsigned int adcvalue; unsigned int I_by;

unsigned char chargermode;

unsigned char T_Mode; //T mode unsigned int ChargingTimeValue; // bit StartTimeFlg;

bit ChargingT_OverFlg; unsigned char Tcount; unsigned char SecondCnt; bit UnLoad; bit Start_5S; bit Flg_5S;

unsigned char Cnt5s; //5 seconds //---------------ex fuction----------------

extern unsigned int ADCStart(unsigned char chanl);

//delay 1ms Fsys=4Mhz 实测1ms void Delay1ms(void) {

unsigned int va;

for(va=0;va<60;va++) {;} }

//delay N ms

void DelayNms(unsigned int ms) {

unsigned int vb;

for(vb=0;vb

Delay1ms(); } }

//---------------------------------------------- // 上电自校准电压 IV

// 自校电压是否在空载范围内 void s1_VI(void)

{

while(1) {

adcvalue = ADCStart(V_SAMP); //voltage

if(((adcvalue<0x01ff)||(adcvalue==0x01ff))&&((adcvalue>0x0000)||(adcvalue==0x0000))) {

break; } } }

//------------------------------------------------

// 校正OP电流否正常,条件打开0.05A校正电流

// 实测I-V OP放大电压, 0x0074 4.2A=0X0141 【0X0141-0X0074=D205, // 4200/205=20.5mA/位AD void s1_VI1(void) {

while(1) {

adcvalue = ADCStart(C_SAMP); //current

if(((adcvalue<0x01ff)||(adcvalue==0x01ff))&&((adcvalue>0x0000)||(adcvalue==0x0000))) {

I_by = adcvalue; break; } } }

//system initial

void SYS_Inital(void) {

//IOport -------------- CN_DOWN = 0; JM = 0; FAN = 0;

PWM_IO = 0; LED_GREEN = 0; LED_RED = 1; _pb3 = 0;

_pac1 = 0; _pac4 = 0; _pac7 = 0; _pdc0 = 0;

_pac5 = 0; _pac6 = 0;

_pbc0 = 1; _pbc1 = 1; _pbc2 = 1; _pbc3 = 0;

//var ---------------------- chargermode = 0x01; Tcount = 0; SecondCnt = 0;

//Timer -------------------

_tmrc = 0x87; //timer mode Ftimer=Fsys/128 _tmr = (256-250); //32*250=8ms

//PWM ---------------------

_pwm = 0xfc; //set pwm duty cycle

//voltage current just self----- s1_VI();

DelayNms(1000); s1_VI1(); }

//---------------------相关保护 void ToPretect(void) {

//---------------短路保护 //---------------低压保护 /*

adcvalue = ADCStart(V_SAMP); //voltage

if(adcvalue<=LOW_VOLTAGE) //Low voltage {

adcvalue = ADCStart(C_SAMP); //current if(adcvalue>20) {

PWM_IO = 0; JM = 0;

chargermode = 0x05; //error return; }

Fsys=4M Ttimer=32us } */

//---------------过压保护

if(adcvalue>=OVER_VOLTAGE) //over voltage {

PWM_IO = 0; JM = 0;

chargermode = 0x05; //error return; }

//---------------过流保护 /*

adcvalue = ADCStart(C_SAMP); //current if(adcvalue>=OVER_CURRENT) //over current {

PWM_IO = 0; JM = 0;

chargermode = 0x05; //error return; } */ }

//------------------main----------- void main() {

SYS_Inital();

_intc=0x05; // EMI ETI enable _ton = 1; //start timer

while(1) {

switch(chargermode) {

case 0x01://start

T_Mode = chargermode; ChargingTimeValue = 0; StartTimeFlg = 0;

ChargingT_OverFlg = 0;

FAN = 0;

LED_GREEN = 0;

本文来源:https://www.bwwdw.com/article/zpov.html

Top