Code: Select all
//******************************************************************************
// Defines
//******************************************************************************
#define adcIbat ADCBUF0 // Canal 0 ADC
#define adcVbat ADCBUF1 // Canal 1 ADC
#define adcTemp ADCBUF2 // Canal 2 ADC
#define adcIsense ADCBUF3 // Canal 3 ADC
#define startAdc ADCONbits.GSWTRG // Habilita conversaão ANO/AN1
#define dutyPwm1 PDC1 // Duty cycle PWM1
#define dutyPwm2 PDC2 // Duty cycle PWM2
#define pwmMax 7000
#define pwmMin 2500
#define _5A 103
#define _3A 62
#define _1A 20
#define _6volts 296
#define sobreCorrente 940 //671 // sobrecorrente
#define sobreVoltagem 830 //887 // sobretensão 18 volts
#define RELE LATEbits.LATE3
#define ledFalha LATEbits.LATE4
#define ledPronto LATEbits.LATE5
#define btConf PORTFbits.RF6
#define btDec PORTDbits.RD0
#define btInc PORTAbits.RA9
#define minTensaoCarga 120
#define maxTensaoCarga 160
#define minCorrenteCarga 150
#define maxCorrenteCarga 400
#define minTempoEqu 60
#define maxTempoEqu 360
#define minTensaoFloat 120
#define maxTensaoFloat 140
//*****************************************************************************
// Ligação do LCD
//*****************************************************************************
sbit LCD_RS at LATE5_bit;
sbit LCD_EN at LATE4_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISE5_bit;
sbit LCD_EN_Direction at TRISE4_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
//******************************************************************************
// Funçoes
//******************************************************************************
void initPwm(void); // Configura PWMs
void initADC(void); // Configura ADs
void initTimer1(void);
unsigned int tiraMediaValores(void);
void configuraEquipamento(void);
void gravaDados(void);
void leDadosGravados(void);
void configuraTipoCarga(void);
void quebraSulfato(void);
void rampaCarga(void);
void falhas(unsigned short cod_falha);
void mostraNumeros(unsigned int txtConv);
//void testeFlash(void);
//******************************************************************************
// Variaveis Globais
//******************************************************************************
unsigned short controleTensao=0, // Flags
contTempo=0,
erroPwm=0, // Indica que o PWM atingiu os limites pré-estabelecido
opcaoCarga=0,
emCarga=0,
falha=0,
fimDaRampa=0,
sobrecorrente=0,
batSulfatada=0,
estagio=0;
unsigned int segundos=0;
unsigned int spCorrente=0,
pwm=30,
spTensao;
unsigned int vAmostra=0,
iAmostra=0,
iSense=0;
unsigned int correnteAcumulada=0,
voltsAcumulado=0,
voltsLido=0,
correnteLida=0;
unsigned short media=0;
unsigned int contSp=0; // contador para a mudança de controle
signed int erroV,
erroI;
unsigned short pos_menu=1,
btConfPress=0,
itemEscolhido=0;
unsigned int temperatura=0,
tensao1=120, // valores colocados para testar a função de mmnue
tensao2=130, // Retirar após os testes.
tensaoFloat=0,
corrente1=150,
corrente2=400,
tempoMaxEqu=0,
tempoMaxImax=0;
unsigned short opcaoCarga1=0,
opcaoCarga2=0,
opcaoCarga3=0,
opcaoCarga4=0;
unsigned int tempoAmostra=0;
unsigned short linLCD=0,
colLcd=0;
char txt1[] = "BATERY CHARGER ";
char txt2[] = "BC800W DSP ";
char txt[6];
//******************************************************************************
// var usadas p/ gravação e leitura de dados na memória FLASH
//******************************************************************************
unsigned int *ptr1, // ponteiro p/ buffer
*ptr2; // ponteiro p/ buffer2
unsigned int Buffer[4], // Buffer dos dados de configuração, corrente, tensao, etc.
Buffer2[2];
unsigned bufferDadosSalvos[4],
bufferdadosSalvos2[3];
//******************************************************************************
// Interrupção do canal AD
//******************************************************************************
void ADC1Int() org 0x2A // end do vetor de int do canal AD
{
IFS0bits.ADIF = 0; // Clear ADC Interrupt Flag
ADSTATbits.P0RDY = 0; // Clear the ADSTAT bits
ADSTATbits.P1RDY = 0; // Par AN2/AN3
iAmostra = adcIbat; // Lê buffer do canal 0 corrente
vAmostra = adcVbat; // Lê buffer do canal 1 tensao
temperatura = adcTemp; // temperatura
iSense = adcIsense; // Lê TC da fonte p/ verificar over I
if( emCarga )
{
if(voltsLido>=spTensao) // se chegou no set point passa p/ controle de tensão
{
contSp++;
if(contSp >= 5000) // filtro p/ evitar repiques.
controleTensao=1;
}
if(voltsLido<spTensao)
contSp=0;
if (!controleTensao && tiraMediaValores()) // Controle de corrente
{
erroI = spCorrente - correnteLida;
if (erroI < -2)
{
--pwm;
if (pwm < pwmMin ) pwm=pwmMin;
}
if (erroI > 2)
{
++pwm;
if (pwm > pwmMax) pwm=pwmMax;
}
dutyPwm1 = pwm;
//********************* Verifica se houve sobretensao ou sobrecorrente ********
if(voltsLido > sobreVoltagem || CorrenteLida > sobreCorrente)
{
dutyPwm1=10;
emCarga=0;
RELE=0;
falha=1;
if(voltsLido > sobreVoltagem) // chama função falhas e informa codigo
falhas(3);
if(correnteLida > sobreCorrente)
falhas(2);
}
}
//******************************************************************************
if(controleTensao && tiraMediaValores() && fimDaRampa) // Controle de tensão
{
erroV = spTensao - voltsLido;
if (erroV < -2)
{
--pwm;
if (pwm < pwmMin ) pwm = pwmMin;
}
if (erroV > 2)
{
++pwm;
if (pwm > pwmMax) pwm = pwmMax;
}
dutyPwm1=pwm;
//************************* verifica se ouve sobrecorrent ou sobretensao *******
if(voltsLido > sobreVoltagem || correnteLida > sobreCorrente)
{
dutyPwm1=10;
emCarga=0;
RELE=0;
falha=1;
if(voltsLido > sobreVoltagem) // chama função falhas e informa codigo
falhas(3);
if(correnteLida > sobreCorrente)
falhas(2);
}
//*****************************************************************************
}
startAdc=1; // habilita nova leitura do AD por interrupção.
}
}
//******************************************************************************
// Interrupção do TIMER1
//******************************************************************************
void Timer1Int() org 0x1A
{
++contTempo;
if(contTempo==4)
{
++segundos;
contTempo=0;
}
IFS0bits.T1IF = 0; // Limpa flag de INTERRUPÇÃO
}
//******************************************************************************
// Função principal
//******************************************************************************
void main()
{
ADPCFG=0xFFF0; // Configura RB0,RB1,RB2,RB3 como analógico o resto I/O
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row
Lcd_Out(2,4,txt2); // Write text in second row
Delay_ms(2000);
TRISFBits.TRISF6=1;
TRISDBits.TRISD0=1;
TRISABits.TRISA9=1;
TRISEBits.TRISE3=0;
TRISEBits.TRISE6=0;
TRISEBits.TRISE7=0;
TRISB = 0b00001111; //1; // conforme suporte Mikroe
// testeFlash(); //***************************************************************************************************
// configuraEquipamento(); //************************************************************************************************
//******************************************************************************
if(!btInc && !btDec ) // qdo ligar o carregador com os dois botões pressionados
{ // por 3 seg. entra no modo de configuração
delay_ms(120);
if(!btInc && !btDec )
configuraEquipamento();
}
initPwm(); // configura PWM
//*** initAdc(); // configura ADC
//initTimer1(); // configura TIIMER1
//dutyPwm1=PWM_MIN; // somente p/ testes no BC800 retirar comentários depois
dutyPwm1=3000; //***************
PR1 = 1000; // P/ gerar uma Int do TIMER1 a cada 256 ms
//START_ADC=1; // somente p/ testes no BC800 retirar comentários depois
delay_ms(3000);
leDadosGravados();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"conecte os cabos");
Lcd_Out(2,1," na bateria ");
//******************************************************************************
// Loop principal
//******************************************************************************
while (1)
{
//***startAdc=1;
if(!emCarga && !falha) // se não está em carga, permite mundança
{
// START_ADC=1; // somente p/ testes no BC800 retirar comentários depois
delay_ms(30);
if(!btInc)
{
delay_ms(120);
if(!btInc)
configuraTipoCarga();
}
if(!btDec)
{
delay_ms(120);
if(!btDec)
configuraTipoCarga();
}
if(!btConf)
{
delay_ms(120);
if(!btConf)
{
btConfPress=1;
configuraTipoCarga();
}
}
if(tiraMediaValores()) // depois de tirar a média de vária leituras nO AD
{
if(voltsLido > _6volts ) // Se bat conectada e maior que 6 volts
{ // vai p/ quebra de sulfato
delay_ms(2000);
RELE=1; // liga rele da fonte
PTCONbits.PTEN = 1; // Enable the PWM Module
delay_ms(1500);
contTempo=0; // zera tempo
segundos=0; // zera segundos
estagio=1; // primeiro estagio de carga
quebraSulfato();
if(!batSulfatada)
{
rampaCarga();
emCarga=1;
}
if(batSulfatada) // se a bateria está sulfatada
falhas(1); // sinaliza falha
}
}
}
if(estagio==1)
{
if(controleTensao)
{
estagio=2;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"Estagio 2");
Lcd_Out(2,1, " Equalizando....");
}
}
if(estagio==2)
{
if(segundos > 14400) // tempo minimo de equalizacão 4 horas
{
if(correnteLida < _5A || segundos > 36000) // se atingiu a corrente minima ou 10 hrs, muda estagio
{ // ou máximo de 20 horas
estagio=3;
tensaoFloat=tensaoFloat/10;
spTensao=(tensaoFloat*788)/16;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"Estagio 3");
Lcd_Out(2,1, " Flutuacao.....");
}
}
}
}
}
//******************************************************************************
// Configura PWM
//******************************************************************************
void initPwm(void)
{
PTCONbits.PTEN = 0; // Enable the PWM Module
IOCON1bits.PENH = 1; // PWM1H is controlled by PWM module
IOCON1bits.PENL = 1; // PWM1L is controlled by PWM module
IOCON1bits.PMOD = 10; // Select Output PWM mode
PWMCON1bits.IUE = 1; // Atualizaçao instantanea do DUTY CYCLE
//*** dutyPwm1 = 100; // Duty Cycle = PDC2*1.05nsec = 672nsec
// 9000 valor máximo a ser usado
DTR1 = 2000; // Deadtime setting */
// Deadtime = DTR1*1.05 = 67.2nsec
ALTDTR1 = 2000; // Deadtime setting */
// Deadtime = ALTDTR1*1.05 = 67.2nsec
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~ PWM2 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* PWM2 I/O Control Register register */
IOCON2bits.PENH = 0;
IOCON2bits.PENL = 0;
// PMOD - 00 -> comprementar
// - 01 -> independente
// - 10 -> Push Pull
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* Configure PTPER register to produce 80kHz PWM frequency */
// PWM period counter = 4 * ( 14.55MHz / f_pwm) - 1;
PTPER = 7000; // 60 Khz com CLK 14.555
// PWM Period @30 MIPS, ??? == 80kHz
// Period = PTPER*1.05nsec = 2.499use
PTCONbits.PTEN = 1; // Enable the PWM Module
}
//******************************************************************************
// Configuração do canal AD
//******************************************************************************
void initAdc(void)
{
ADCONbits.ADON=0; // Desabilita modulo A/D p/ configuração
ADCONbits.ADSIDL = 1; // No operate in Idle Mode
ADCONbits.FORM = 0; // Output in Integer Format
ADCONbits.EIE = 1; // Enable Early Interrupt 1 - Gera int
// na primeira conversão e 0 - na segunda .
ADCONbits.ORDER = 0; // Even channel first
ADCONbits.SEQSAMP = 1; // Sequential Sampling Enabled
ADCONbits.ADCS = 0B110; // Clock Divider is set up for Fadc/16 = 15 Mhz
ADPCFG=0xFFF0; // AN0/AN1/AN2/AN3 como analogico
ADSTAT = 0; // Clear the ADSTAT register
ADCPC0bits.TRGSRC0 = 0B00010; // O software irá disparar a conversão AN0/AN1 ( SOFT individual )
ADCPC0bits.TRGSRC1 = 0b00010; // O software irá disparar a conversão AN2/AN3
ADCPC0bits.IRQEN0 = 1; // Conversão gera interrupção canais AN0/AN1
ADCPC0bits.IRQEN1 = 1; // Conversão dos canais AN2/AN3 gera int
ADCPC0bits.SWTRG0 = 1; // Trigger global por software AN0/AN1
ADCPC0bits.SWTRG1 = 1; // AN2/AN3
ADCONbits.ADON = 1; // Start the ADC module
/* Set up the Interrupts */
IFS0bits.ADIF = 0; // Limpa flag de interrupçao
IPC2bits.ADIP = 4; // Nivel 1 de prioridade de interrupão do AD
IEC0bits.ADIE = 1; // Habilita interrupção ADCI
}
//******************************************************************************
// Configura o TIMER1
//******************************************************************************
void initTimer1(void)
{
T1CONbits.TON = 1; // habilita TIMER1
T1CONbits.TSIDL = 0; // não funciona em modo IDLE
T1CONbits.TGATE = 0; //
T1CONbits.TCKPS = 0b11; // prescale 11=1:256 ,10=1:64 , 01=1:8 , 00=1:1
//T1CONbits.TCKPS1 = 1; //
T1CONbits.TSYNC = 0; // sem sincronismo com clock externo
T1CONbits.TCS = 0; // Clock interno (FOSC/4)
IPC0bits.T1IP = 1; // nivel de prioridade baixo
IFS0bits.T1IF = 0; // Limpa flag de INTERRUPÇÃO do TIMER1
IEC0bits.T1IE = 1; // habilita int do TIMER1
}
//******************************************************************************
// Tira a média das leituras dos ADs
//******************************************************************************
unsigned int tiraMediaValores(void)
{
++media;
correnteAcumulada+=iAmostra;
voltsAcumulado+=vAmostra;
if(media==8)
{
correnteLida=correnteAcumulada/8;
voltsLido=voltsAcumulado/8;
correnteAcumulada=0;
voltsAcumulado=0;
media=0;
return(1);
}
return(0);
}
//******************************************************************************
// Grava dados na memória FLASH
//******************************************************************************
void gravaDados(void)
{
Flash_Erase32(0x01F70); // Apaga bloco da flash antes de gravar novos dados
Flash_Erase32(0x01F78); // Apaga bloco da flash antes de gravar novos dados
Flash_Write_Block(0x01F70 , Buffer); // grava words
Flash_Write_Block(0x01F78 , Buffer2); // grava words
}
//******************************************************************************
// Lê os dados gravados na flash
//******************************************************************************
void leDadosGravados(void)
{
ptr1=&bufferDadosSalvos;
ptr2=&bufferDadosSalvos2;
Flash_Read4(0x01F70, ptr1);
Flash_Read4(0x01F78, ptr2);
tensao1 = bufferDadosSalvos[0];
tensao2 = bufferDadosSalvos[1];
corrente1 = bufferDadosSalvos[2];
corrente2 = bufferDadosSalvos[3];
}
//******************************************************************************
// Setup de corrente e tensão de carga
//******************************************************************************
void configuraTipoCarga(void)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_out(1,5,"Selecione");
Lcd_Out(2,4," Amp Volts");
if(!btInc)
pos_menu++;
if(!btDec)
{
pos_menu--;
if(pos_menu==0)
pos_menu=4;
}
if(pos_menu>4) pos_menu=1;
switch(pos_menu)
{
case 1: {
colLcd=7;
mostraNumeros(tensao1);
colLcd=1;
mostraNumeros(corrente1);
opcaoCarga=1;
}
break;
case 2: {
colLcd=7;
mostraNumeros(tensao1);
colLcd=1;
mostraNumeros(corrente2);
opcaoCarga=2;
}
break;
case 3: {
// Lcd_Out(2,2,"20Amp 16Volts");
colLcd=7;
mostraNumeros(tensao2);
colLcd=1;
mostraNumeros(corrente1);
opcaoCarga=3;
}
break;
case 4: {
// Lcd_Out(2,2,"20Amp 14.5Volts");
colLcd=7;
mostraNumeros(tensao2);
colLcd=1;
mostraNumeros(corrente2);
opcaoCarga=4;
}
break;
}
switch(opcaoCarga)
{
case 1:
if(btConfPress)
{
tensao1=tensao1/10;
corrente1=corrente1/10;
spCorrente=(corrente1*780)/40;
spTensao=(tensao1*788)/16;
}
break;
case 2:
if(btConfPress)
{
tensao1=tensao1/10;
corrente2=corrente2/10;
spCorrente=(corrente2*780)/40;
spTensao=(tensao1*788)/16;
}
break;
case 3:
if(btConfPress)
{
tensao2=tensao2/10;
corrente1=corrente1/10;
spCorrente=(corrente1*780)/40;
spTensao=(tensao2*788)/16;
}
break;
case 4:
if(btConfPress)
{
tensao2=tensao2/10;
corrente2=corrente2/10;
spCorrente=(corrente2*780)/40;
spTensao=(tensao2*788)/16;
}
break;
}
if(btConfPress)
{
Lcd_out(2,1, "*");
btConfPress=0;
delay_ms(2000);
Lcd_Out(1,1,"conecte os cabos");
Lcd_Out(2,1," na bateria ");
buffer[0]=spTensao;
buffer[1]=spCorrente;
gravaDados(); // grava os dados na flash
}
}
//******************************************************************************
// Função para quebra de sufato
//******************************************************************************
void quebraSulfato(void)
{
unsigned short testeSulfato=0;
unsigned int pwmSulfato=4500, //3500
correnteInicial=0;
startAdc=1;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," Quebra de ");
Lcd_Out(2,1," Sulfato ");
segundos=0; // Reinicia a contagem de tempo
contTempo=0;
dutyPwm1=pwmSulfato;
delay_ms(500);
startAdc=1;
correnteInicial=iAmostra;
if(correnteInicial < 0 )
correnteInicial=0;
while(!testeSulfato)
{
delay_ms(200);
startAdc=1;
dutyPwm1=pwmSulfato;
pwmSulfato+=10;
if(pwmSulfato > pwmMax )
pwmSulfato = 3500; // p/ recomeçar, tenta a qubra de sulfato
if(tiraMediaValores())
{
if( correnteLida < _3A )
{
if (segundos > 180)
{
batSulfatada=1; // não entra no modo de carga
RELE=0;
FALHA=1;
dutyPwm1=20;
testeSulfato=1;
}
}
if ((correnteLida - correnteInicial) > _3A )
{
batSulfatada=0;
dutyPwm1=pwmMin;
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1,"SAIU");
testeSulfato=1;
}
}
}
}
//******************************************************************************
// Gera rampa de carga
//******************************************************************************
void rampaCarga(void)
{
unsigned int spTemp=0,
spCorrenteRampa=100;
contTempo=0;
segundos=0;
emCarga=1;
estagio=1; // primeiro estagio de carga
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,4,"Estagio 1");
Lcd_Out(2,1,"Carregando......");
spTemp = spCorrente; // pega o valor se sp_I e gurada em temp
startAdc=1; // aciona conversao
while((spCorrenteRampa < spTemp ) && (!controleTensao)) // pode acontecer de mesmo na rampa a bat
{ // atingir o SP então sai da rampa
spCorrenteRampa += 1;
spCorrente = spCorrenteRampa;
delay_ms(5);
}
fimDaRampa=1;
spCorrente=spTemp; // pega valor
}
//******************************************************************************
// Mostra as falhas ocorridas e trava o sistema
//******************************************************************************
void falhas(unsigned short cod_falha)
{
Lcd_Cmd(_LCD_CLEAR);
if(cod_falha==1)
Lcd_Out(1,1," Bat. sulfatada");
if(cod_falha==2)
Lcd_Out(1,1," Sobrecorrente ");
if(cod_falha==3)
Lcd_Out(1,1," Sobretensao ");
while(1);
}
//*****************************************************************************
// Configura os Set Points p/ as opçoes de carga
//*****************************************************************************
void configuraEquipamento(void)
{
unsigned short opcaoMenu=0,
flagMenu2=0;
linLcd=1; // linha do LCD
colLcd=1; // Coluna do LCD
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1,"Configuracao....");
while(!btInc && !btDec); // fica aqui até o usuário soltar as teclas
while(1)
{
if(!btConf && flagMenu2)
{
delay_ms(150);
if(!btConf)
{
while(!btConf);
flagMenu2=0;
}
}
if(!btInc && !flagMenu2)
{
delay_ms(150);
if(!btInc)
{
opcaoMenu++;
if(opcaoMenu==7)
opcaoMenu=1;
delay_ms(30);
}
}
if(!btDec && !flagMenu2)
{
delay_ms(150);
if(!btDec)
{
opcaoMenu--;
if(opcaoMenu==0)
opcaoMenu=7;
delay_ms(30);
}
}
if(!flagMenu2) // se não marcou nenhum item, mostra opções
{
switch (opcaoMenu)
{
case 1:
Lcd_out(1,1,"Tensao 1 ");
Lcd_out(2,7,"Volts ");
mostraNumeros(tensao1);
if(!btConf)
{
delay_ms(150);
if(!btConf)
{
itemEscolhido=1;
flagMenu2=1;
delay_ms(30);
}
}
break;
//==============================================================================
case 2:
Lcd_out(1,1,"Tensao 2 ");
Lcd_out(2,7,"Volts ");
mostraNumeros(tensao2);
if(!btConf)
{
delay_ms(150);
if(!btConf)
{
itemEscolhido=2;
flagMenu2=1;
delay_ms(30);
}
}
break;
//==============================================================================
case 3:
Lcd_out(1,1,"Corrente Carga 1");
Lcd_out(2,7,"Ampers ");
mostraNumeros(corrente1);
if(!btConf)
{
delay_ms(150);
if(!btConf)
{
itemEscolhido=3;
flagMenu2=1;
delay_ms(30);
}
}
break;
//==============================================================================
case 4:
Lcd_out(1,1,"Corrente Carga 2");
Lcd_out(2,7,"Ampers ");
mostraNumeros(corrente2);
if(!btConf)
{
delay_ms(150);
if(!btConf)
{
itemEscolhido=4;
flagMenu2=1;
delay_ms(30);
}
}
break;
//==============================================================================
case 5:
Lcd_Out(1,1,"Time Equalizacao");
Lcd_out(2,7,"Minutos ");
tempoAmostra=tempoMaxEqu*10; // Somente p/ mostrar de forma coerente no LCD
mostraNumeros(tempoAmostra);
if(!btConf)
{
delay_ms(150);
if(!btConf)
{
itemEscolhido=5;
flagMenu2=1;
delay_ms(30);
}
}
break;
//==============================================================================
case 6:
Lcd_Out(1,1,"Tensao Flutuacao");
Lcd_out(2,7,"Volts ");
mostraNumeros(tensaoFloat);
if(!btConf)
{
delay_ms(150);
if(!btConf)
{
itemEscolhido=6;
flagMenu2=1;
delay_ms(30);
}
}
break;
}
}
//==============================================================================
// Muda os valores do item escolhido na seleção acima
//==============================================================================
if(flagMenu2) // se algum item foi MARCADO
{
switch(itemEscolhido)
{
case 1:
if(!btInc)
{
delay_ms(120);
if(!btInc)
{
tensao1++;
if(tensao1 > maxTensaoCarga )
tensao1=120;
}
}
if(!btDec)
{
delay_ms(120);
if(!btDec)
{
tensao1--;
if(tensao1 < minTensaoCarga)
tensao1=160;
}
}
mostraNumeros(tensao1);
break;
//==============================================================================
case 2:
if(!btInc)
{
delay_ms(120);
if(!btInc)
{
Tensao2++;
if(tensao2 > maxTensaoCarga )
tensao2=120;
}
}
if(!btDec)
{
delay_ms(120);
if(!btDec )
{
tensao2--;
if(tensao2 < minTensaoCarga)
tensao2=160;
}
}
mostraNumeros(tensao2);
break;
//==============================================================================
case 3:
if(!btInc)
{
delay_ms(120);
if(!btInc)
{
corrente1++;
if(corrente1 > maxCorrenteCarga)
corrente1=150;
}
}
if(!btDec)
{
delay_ms(120);
if(!btDec)
{
corrente1--;
if(corrente1 < minCorrenteCarga)
corrente1=400;
}
}
mostraNumeros(corrente1);
break;
//==============================================================================
case 4:
if(!btInc)
{
delay_ms(120);
if(!btInc)
{
corrente2++;
if(corrente2 > maxCorrenteCarga)
corrente2=150;
}
}
if(!btDec)
{
delay_ms(120);
if(!btDec)
{
corrente2--;
if(corrente2 < minCorrenteCarga)
corrente2=400;
}
}
mostraNumeros(corrente2);
break;
//==============================================================================
case 5:
if(!btInc)
{
delay_ms(120);
if(!btInc)
{
tempoMaxEqu++;
if(tempoMaxEqu > maxTempoEqu)
tempoMaxEqu=60;
}
}
if(!btDec)
{
delay_ms(120);
if(!btDec)
{
tempoMaxEqu--;
if(tempoMaxEqu < minTempoEqu)
tempoMaxEqu=360;
}
}
tempoAmostra=tempoMaxEqu*10; // somente para mostrar no LCD
mostraNumeros(tempoAmostra); // não será feito calculos com esse valor
break;
//=============================================================================
case 6:
if(!btInc)
{
delay_ms(120);
if(!btInc)
{
tensaoFloat++;
if(tensaoFloat > maxTensaoFloat)
tensaoFloat=120;
}
}
if(!btDec)
{
delay_ms(120);
if(!btDec)
{
tensaoFloat--;
if(tensaoFloat < minTensaoFloat)
tensaoFloat=140;
}
}
mostraNumeros(tensaoFloat);
break;
} // switch itemEscolhido
}
if(!btInc && !btConf)
{
Buffer[0]= tensao1;
Buffer[1]= tensao2;
Buffer[2]= corrente1;
Buffer[3]= corrente2;
Buffer2[0]= tensaoFloat;
Buffer2[1]= tempoMaxEqu;
Buffer2[2]= tempoMaxImax;
gravaDados();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Config. salva");
Lcd_Out(1,1,"Reinicie eqpto");
while(1); // loop infinito
}
} // while
} // void
//*****************************************************************************
// Formata numeros
//*****************************************************************************
void mostraNumeros(unsigned int txtConv )
{
WordToStr(txtConv, txt);
Lcd_chr(2, colLcd, txt[1]);
Lcd_chr(2, colLcd+1, txt[2]);
Lcd_chr(2, colLcd+2, txt[3]);
LCD_chr(2, colLcd+3, 46);
Lcd_chr(2, colLcd+4, txt[4]);
}