#if defined(__PCH__)
#include <18F452.h>
//////// Fuses: LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,PROTECT,NOPROTECT,OSCSEN
//////// Fuses: NOOSCSEN,NOBROWNOUT,BROWNOUT,WDT1,WDT2,WDT4,WDT8,WDT16,WDT32
//////// Fuses: WDT64,WDT128,WDT,NOWDT,BORV20,BORV27,BORV42,BORV45,PUT,NOPUT
//////// Fuses: CCP2C1,CCP2B3,NOSTVREN,STVREN,NODEBUG,DEBUG,NOLVP,LVP,WRT
//////// Fuses: NOWRT,NOWRTD,WRTD,NOWRTB,WRTB,WRTC,NOWRTC,CPD,NOCPD,CPB
//////// Fuses: NOCPB,EBTR,NOEBTR,EBTRB,NOEBTRB
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
/*
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NOOSCSEN
#FUSES NOPUT
#FUSES CCP2C1
#FUSES NOSTVREN
#FUSES NODEBUG
#FUSES NOWRTD
#FUSES NOWRTB
#FUSES NOWRTC
#FUSES NOCPB
#FUSES NOEBTR
#FUSES NOEBTRB
*/
#use delay(clock=20000000)
#include "HDM64GS12_scanbang.c"
#include "graphics.c"
#include "math.h"
#include "24256.c"
#include <string.h>
/// para conteo de uptime
#define CLOCKS_PER_SECOND 1000 ///contar cada tantos milisegundos (uptime)
#define CLOCKS_PER_SECOND_2 1000 ///contar cada tantos milisegundos (grupo_start)
#include <stdlib.h>
// fin de conteo uptime
///para la eeprom interna del pic
//#include "stdlib.h"
#include "limits.h"
typedef int8 INTEE;
///fin eeprom interna del pic
//////para medir frecuencia
//#priority CCP1, TIMER1
#define BytePtr(var, offset) (char *)((char*)&var + offset)
//#byte PIR1 = 0x0C
//#bit TMR1IF = PIR1.0
//int8 gc_timer1_extension = 0;
///////fin para medir frecuencia
int m, p, l, h; //m se utiliza para el menu, p para la pantalla, l para longitud de texto, y c aun no se, h es para mantener el estado ultimo del encendido grupo
int lo = 0; //para el seteo de temperatura ultima seleccion marcada
int set_ = 0; //para el seteo de temperaturas, boton set tratar de meterlo en short
int16 t = 0; //para el uptime variable de comparacion
unsigned int16 c_state = 0; //para almacenar estado de switch start
unsigned int16 minutos5 = 0; //para el uptime variable de valor en fraciones de 5 minutos
unsigned int16 min_g = 0; // para conteo de tiempo entre encendidos de grupo
unsigned int16 time_g = 0;
//unsigned int vref = 0; // se mueve dentro de la pantalla 3
//int up_down_vref = 0;
int16 isr_ccp_delta; //para la frecuencia
float Values; //para el adc
char Texto[30];
short int dbutton4, dbutton5, dbutton6, dbutton7, start_hours, eg;
////prototipos
float read_analog(int a);
int menu(int p);
int16 read_frequency(void);
void write_eeprom16(int address1, int address2, int16 value);
int16 read_eeprom16(int address1, int address2);
void iniciar_eeprom(int e);
void Pantalla_3(int o);
int check_temp(int sen);
void buzzer();
void alertas(int tip);
///////fin de los prototipos
//_______________________________________________________________________________________
void welcome(void){
delay_ms(50);
Texto = "Empresa";
glcd_text57(0, 0, Texto, 2, ON);
Texto = "ELECTRONIC";
glcd_text57(0, 20, Texto, 2, ON);
}
//_______________________________________________________________________________________
void Pantalla_0(){
if (p == 1 || p == 2 || p == 3) {
glcd_fillScreen(OFF);
m = menu(0);
}
extern float Values;
extern float read_analog(int a);
extern char Texto[];
Texto = "----TEMPERATURAS----";
glcd_text57(0, 0, Texto, 1, ON);
Texto = "Externa:";
glcd_text57(0, 10, Texto, 1, ON);
Texto = "Interna:";
glcd_text57(0, 20, Texto, 1, ON);
Texto = "Motor";
glcd_text57(0, 30, Texto, 1, ON);
Texto = "Alternador:";
glcd_text57(0, 40, Texto, 1, ON);
Values = read_analog(0) * (5.0 * 100.0 / 1024.0);
glcd_rect(80, 17, 127, 10, YES, OFF);
if (l == 4){glcd_text57(92, 10, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 10, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 10, Texto, 1, ON);}
Values = read_analog(1) * (5.0 * 100.0 / 1024.0);
// c_state = read_analog(8);
//sprintf(Texto ,"%3.1fC", Values);
glcd_rect(80, 27, 127, 20, YES, OFF);
if (l == 4){glcd_text57(92, 20, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 20, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 20, Texto, 1, ON);}
Values = read_analog(2) * (5.0 * 100.0 / 1024.0);
glcd_rect(80, 37, 127, 30, YES, OFF);
if (l == 4){glcd_text57(92, 30, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 30, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 30, Texto, 1, ON);}
Values = read_analog(3) * (5.0 * 100.0 / 1024.0);
glcd_rect(80, 47, 127, 40, YES, OFF);
if (l == 4){glcd_text57(92, 40, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 40, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 40, Texto, 1, ON);}
p = 0;
}
//_______________________________________________________________________________________
void Pantalla_1(){
if (p == 0 || p == 2 || p == 3) {
glcd_fillScreen(OFF);
m = menu(1);
}
extern float Values;
extern float read_analog(int a);
extern char Texto[];
// extern int16 read_frequency(void);
unsigned int16 frecuencia;
Texto = "----ESTADO GRUPO----";
glcd_text57(0, 0, Texto, 1, ON);
Texto = "VCA:";
glcd_text57(0, 10, Texto, 1, ON);
Texto = "Frecuencia:";
glcd_text57(0, 20, Texto, 1, ON);
Texto = "Monoxido:";
glcd_text57(0, 30, Texto, 1, ON);
Texto = "Horas uso:";
glcd_text57(0, 40, Texto, 1, ON);
Values = read_analog(4) * (260.0 / 1024.0);
glcd_rect(80, 17, 127, 10, YES, OFF);
if (l == 4){glcd_text57(92, 10, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 10, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 10, Texto, 1, ON);}
///adicional para saber si empezar a contar despues veo donde lo meto
// if (Values > 100) {start_hours = 1; eg = 1;} else {start_hours = 0; eg = 0;} // lo saque de aca porque solo funcionaba en esta pantalla !!
frecuencia = read_frequency();
sprintf(Texto
,"%3luHz",frecuencia
); glcd_rect(80, 27, 127, 20, YES, OFF);
if (l == 4){glcd_text57(98, 20, Texto, 1, ON);}
if (l == 5){glcd_text57(92, 20, Texto, 1, ON);}
if (l == 6){glcd_text57(86, 20, Texto, 1, ON);}
Values = read_analog(5) * (5.0 * 100.0 / 1024.0);
glcd_rect(80, 37, 127, 30, YES, OFF);
if (l == 6){glcd_text57(92, 30, Texto, 1, ON);}
if (l == 7){glcd_text57(86, 30, Texto, 1, ON);}
if (l == 8){glcd_text57(80, 30, Texto, 1, ON);}
sprintf(Texto
,"%5LuHs",minutos5
); //cambiar variable a horas if minutos5 >= 60 horas++ dentro de timer glcd_rect(80, 47, 127, 40, YES, OFF);
if (l == 5){glcd_text57(92, 40, Texto, 1, ON);}
if (l == 6){glcd_text57(86, 40, Texto, 1, ON);}
if (l == 7){glcd_text57(80, 40, Texto, 1, ON);}
p = 1;
}
//_______________________________________________________________________________________
void Pantalla_2(){
if (p == 1 || p == 0 || p == 3) {
glcd_fillScreen(OFF);
m = menu(2);
}
extern float Values;
extern float read_analog(int a);
extern char Texto[];
Texto = "-------MONITOR-------";
glcd_text57(0, 0, Texto, 1, ON);
Texto = "VCA Linea:";
glcd_text57(0, 10, Texto, 1, ON);
Texto = "Bateria:";
glcd_text57(0, 20, Texto, 1, ON);
Values = read_analog(6) * (260.0 / 1024.0);
glcd_rect(80, 17, 127, 10, YES, OFF);
if (l == 4){glcd_text57(92, 10, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 10, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 10, Texto, 1, ON);}
Values = read_analog(7) * (5.0 * 100.0 / 1024.0);
glcd_rect(80, 27, 127, 20, YES, OFF);
if (l == 4){glcd_text57(92, 20, Texto, 1, ON);}
if (l == 5){glcd_text57(86, 20, Texto, 1, ON);}
if (l == 6){glcd_text57(80, 20, Texto, 1, ON);}
p = 2;
}
//_______________________________________________________________________________________
void alertas(int tip){
glcd_fillScreen(OFF);
if (tip == 1){
Texto = "TEMPERATURAS ELEVADAS";
buzzer();
glcd_text57(0,0, Texto, 1, ON);
}
if (tip == 2){
Texto = "ENCENDIENDO GRUPO...";
buzzer();
glcd_text57(0,0, Texto, 1, ON);
}
if (tip == 3){
Texto = "APAGANDO GRUPO...";
buzzer();
glcd_text57(0,0, Texto, 1, ON);
}
if (tip == 4){
Texto = "LISTO PARA ENCENDER GRUPO";
buzzer();
glcd_text57(0,0, Texto, 1, ON);
}
if (tip == 5){
Texto = "MONOXIDO EN NIVELES CRITICOS";
buzzer();
glcd_text57(0,0, Texto, 1, ON);
}
delay_ms(1500); // ver que el delay no sea muy alto o apagar grupo antes, no se
glcd_fillScreen(OFF);
m = menu(0);
}
//_______________________________________________________________________________________
void buzzer(){
int tim_;
output_high(PIN_C1);
delay_ms(2000);
output_low(PIN_C1);
while (tim_ <= 30){
output_high(PIN_C1);
delay_ms(23);
output_low(PIN_C1);
delay_ms(66);
tim_++;
}
tim_ = 0;
}
//_______________________________________________________________________________________
void Pantalla_3(int o){
unsigned int vref = 0;
if (p == 1 || p == 0 || p == 2) {
glcd_fillScreen(OFF);
m = menu(3);
}
if (o == 0){o = lo;}
if (o == 1 || o == 2){lo = o;}
//si o es 1 entonces marcar motor, si o es 2 marcar alternador
Texto = "----CONFIGURACION----";
glcd_text57(0, 0, Texto, 1, ON);
Texto = "Temp.R. Motor:";
glcd_text57(0, 10, Texto, 1, ON);
Texto = "Temp.R. Alt.:";
glcd_text57(0, 20, Texto, 1, ON);
vref = read_eeprom(7); //probar un cast de unsigned int y elinar variable vref
if (o
== 1){sprintf(Texto
,"%3u<",vref
);} //motor glcd_rect(80, 17, 127, 10, YES, OFF);
if (l == 2){glcd_text57(92, 10, Texto, 1, ON);} //92
if (l == 3){glcd_text57(98, 10, Texto, 1, ON);} //86
if (l == 4){glcd_text57(103, 10, Texto, 1, ON);} //80
vref = read_eeprom(8); //probar un cast de unsigned int y elimnar variable vref
if (o
== 2){sprintf(Texto
,"%3u<",vref
);} //alternador glcd_rect(80, 27, 127, 20, YES, OFF);
if (l == 2){glcd_text57(92, 20, Texto, 1, ON);}
if (l == 3){glcd_text57(98, 20, Texto, 1, ON);}
if (l == 4){glcd_text57(103, 20, Texto, 1, ON);}
p = 3;
//ultimo estado seleccionado:
}
//_______________________________________________________________________________________
int check_temp(int sen){ //sen1 motor, sen2 alternador
int temp1, temp2, value;
delay_ms(20);
temp1 = read_analog(2) * (5.0 * 100.0 / 1024.0); //temperatura motor
delay_ms(20);
temp2 = read_analog(3) * (5.0 * 100.0 / 1024.0); //temperatura alternador
if (sen == 1){
value = read_eeprom(7);
if (temp1 >= value){
//apagar grupo
return 1;
}
else {
return 0;
}
}
if (sen == 2){
value = read_eeprom(8);
if (temp2 >= value){
//apagar grupo
return 1;
}
else {
return 0;
}
}
}
//_______________________________________________________________________________________
void grupo(int act_){ //si act es 1 envia 1 al rele del cebador, 0 contrario.
if ((act_ == 1) && (h == 1) && (min_g >= (time_g + 7))){
h = 0;
alertas(2);
output_high(PIN_C7);
delay_ms(5000);
output_low(PIN_C7);
time_g = min_g;
}
//pantalla encendiendo grupo, menu empty meterlo al principio para que luego lea main y vuelva a la normalidad
if (act_ == 0){
alertas(3);
output_low(PIN_C5);
//stop grupo
}
if (act_ == 2){
Values = read_analog(4) * (260.0 / 1024.0);
if (Values > 100) {
start_hours = 1;
eg = 1;
}
else {
start_hours = 0;
eg = 0;
}
}
}
//_______________________________________________________________________________________
void set_vref(int up_down){ //up_down = 1 incrementa, 2 decrementa
int value;
if (up_down == 0){up_down = 0;}
if (up_down == 1){
if (lo == 1){
delay_ms(500);
value = read_eeprom(7); //motor
++value; //meter value como variable interna
write_eeprom(7,value);
}
if (lo == 2){
delay_ms(500);
value = read_eeprom(8); //alternador
++value;
write_eeprom(8,value);
}
}
if (up_down == 2){
if (lo == 1){
delay_ms(500);
value = read_eeprom(7); //motor
--value;
write_eeprom(7,value);
}
if (lo == 2){
delay_ms(500);
value = read_eeprom(8); //alternador
--value;
write_eeprom(8,value);
}
}
}
//_______________________________________________________________________________________
int menu(int p){
//extern char texto[];
if (p == 0){
Texto = "TMP | GRP | MON | -- ";
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_text57(1, 55, Texto, 1, OFF);
Texto = "TMP";
glcd_rect(1, 55, 26, 62, YES, OFF);
glcd_text57(1, 55, Texto, 1, ON);
return(0);
}
if (p == 1){
Texto = "TMP | GRP | MON | -- ";
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_text57(1, 55, Texto, 1, OFF);
Texto = " GRP ";
glcd_rect(28, 55, 62, 62, YES, OFF);
glcd_text57(1, 55, Texto, 1, ON);
return(1);
}
if (p == 2){
Texto = "TMP | GRP | MON | -- ";
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_text57(1, 55, Texto, 1, OFF);
Texto = " MON";
glcd_rect(64, 55, 98, 62, YES, OFF);
glcd_text57(1, 55, Texto, 1, ON);
return(2);
}
if (p == 3){
Texto = "UP | DN | SET | EX ";
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_text57(1, 55, Texto, 1, OFF);
return(3);
}
if (p == 4){
Texto = "UP | DN | SET | EX ";
glcd_rect(0, 54, 127, 63, YES, ON);
glcd_text57(1, 55, Texto, 1, OFF);
Texto = " SET";
glcd_rect(64, 55, 98, 62, YES, OFF);
glcd_text57(1, 55, Texto, 1, ON);
return(3);
}
}
//_______________________________________________________________________________________
float read_analog(int a) ///ingresar switch
{
float ADC_Value;
if (a == 0){
output_low(PIN_E2);
output_low(PIN_E1);
output_low(PIN_A2);
}
if (a == 1){
output_high(PIN_E2);
output_low(PIN_E1);
output_low(PIN_A2);
}
if (a == 2){
output_low(PIN_E2);
output_high(PIN_E1);
output_low(PIN_A2);
}
if (a == 3){
output_high(PIN_E2);
output_high(PIN_E1);
output_low(PIN_A2);
}
if (a == 4){
output_low(PIN_E2);
output_low(PIN_E1);
output_high(PIN_A2);
}
if (a == 5){
output_high(PIN_E2);
output_low(PIN_E1);
output_high(PIN_A2);
}
if (a == 6){
output_low(PIN_E2);
output_high(PIN_E1);
output_high(PIN_A2);
}
if (a == 7){
output_high(PIN_E2);
output_high(PIN_E1);
output_high(PIN_A2);
}
if (a == 8){
delay_ms(100);
set_adc_channel (3); //Elige canal a medir RA3
delay_us (20);
ADC_Value=read_adc(); //Capturamos señal analógica que entra por el canal previamente seleccionado (RA3)
}
else {
delay_ms(100);
set_adc_channel (0); //Elige canal a medir RA0
delay_us (20);
ADC_Value=read_adc(); //Capturamos señal analógica que entra por el canal previamente seleccionado (RA0)
}
return(ADC_Value);
}
//_______________________________________________________________________________________
void iniciar_eeprom(int e){ // funcion para limpiar la eeprom si es la primera vez que se graba el pic
#rom int 0xf00000={1,2,3,4} //eeprom graba en la posicion 0123 los valores 1234
if (read_eeprom(4) != 1 || e == 1){
write_eeprom(4,1);
write_eeprom(5,0);
write_eeprom(6,0);
write_eeprom(7,135);
write_eeprom(8,100);
}
}
//_______________________________________________________________________________________
void write_eeprom16(int address1, int address2, int16 value) //escribe sobre la eeprom ints de 16 bits
{
int8 lowerhalf = 0;
int8 upperhalf = 0;
lowerhalf = make8(value,0);
write_eeprom(address1,lowerhalf);
upperhalf = make8(value,1);
write_eeprom(address2,upperhalf);
}
//_______________________________________________________________________________________
int16 read_eeprom16(int address1, int address2) //lee sobre la eeprom ints de 16 bits
{
int16 finalvalue = 0;
int8 lowerhalf = 0;
int8 upperhalf = 0;
upperhalf = read_eeprom(address2);
lowerhalf = read_eeprom(address1);
finalvalue = make16(upperhalf,lowerhalf);
return finalvalue;
}
//_______________________________________________________________________________________
//funcion para medir frecuencia:
int16 read_frequency(){
int16 current_ccp_delta;
int16 frequency;
disable_interrupts(GLOBAL);
current_ccp_delta = isr_ccp_delta;
enable_interrupts(GLOBAL);
frequency = (int16)((5000000L/8) / current_ccp_delta);
return (frequency);
//printf("%lu Hz\n\r", frequency);
delay_ms(500);
}
//_______________________________________________________________________________________
/*
#int_timer1
void timer1_isr(void)
{
gc_timer1_extension++;
}
*/
//------------------------------------------------------
////codigo para contar segundos o segun se defina en clocks_per_second obtenido de ccs
//_______________________________________________________________________________________
#int_timer2
void updateClock()
{
#if CLOCKS_PER_SECOND >= 0x10000
static int32 t;
#elif CLOCKS_PER_SECOND >= 0x100
static int16 t;
#else
static int8 t;
#endif
/*
#if CLOCKS_PER_SECOND_2 >= 0x10000
static int32 t_2;
#elif CLOCKS_PER_SECOND_2 >= 0x100
static int16 t_2;
#else
static int8 t_2;
#endif
*/
t++;
// t_2++;
/*
if(t_2 >= CLOCKS_PER_SECOND_2){
t = 0;
min_g++;
if (min_g >= 65530){min_g = 0;}
//incremento segundero para start
}
*/
if(t >= CLOCKS_PER_SECOND)
{
t = 0;
if (start_hours){minutos5++;}
}
}
//////////// fin de codigo ccs
//________________________________________________________
#int_ccp1
void ccp1_isr(void)
{
int16 current_ccp;
static int16 old_ccp = 0;
current_ccp = CCP_1;
isr_ccp_delta = current_ccp - old_ccp;
old_ccp = current_ccp;
}
//_______________________________________________________________________________________
#int_rb
void test_detect_rb_change() {
set_tris_b(0xF0);
if (input(PIN_B4)) {dbutton4=1;}
if (input(PIN_B5)) {dbutton5=1;}
if (input(PIN_B6)) {dbutton6=1;}
if (input(PIN_B7)) {dbutton7=1;}
if (!input(PIN_B7)) {dbutton7=0;} //hay que mantener apretado dbutton 7 + 4 para entrar al menu 3
}
void clear_delta() {
dbutton4=0;
dbutton5=0;
dbutton6=0;
dbutton7=0;
}
//_______________________________________________________________________________________
void main(void)
{
clear_delta();
iniciar_eeprom(0);
setup_timer_2(T2_DIV_BY_4,250,5);
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_RB);
//enable_interrupts(GLOBAL);
glcd_init(ON); // iniciamos la lcd
glcd_fillScreen(OFF); //LIMPIAMOS LA PANTALLA
delay_ms(200);
welcome();
delay_ms(2000);
glcd_fillScreen(OFF); //LIMPIAMOS LA PANTALLA
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
// setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT);
// setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DISABLED,0,1);
// setup_ccp1(CCP_OFF);
// setup_comparator(NC_NC_NC_NC); //removido para 18f452
// setup_vref(FALSE); //removido para 18f452
////////////codigo para medir frecuencia, depurar de ccs forums
set_timer1(0);
setup_timer_1(T1_INTERNAL| T1_DIV_BY_8);
setup_ccp1(CCP_CAPTURE_RE);
// Enable interrupts.
//clear_interrupt(INT_TIMER1);
//enable_interrupts(INT_TIMER1);
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);
/////////////fin para medir frecuencia de ccs
minutos5 = read_eeprom16(5,6); //asigna al intervalo de 5 minutos el ultimo valor que se guardo en la eeprom
set_tris_a(0xEF);
set_tris_c(0x01);
set_tris_e(0x00);
m = menu(0);
eg = 0;
c_state = 0;
output_low(PIN_C1);
while (TRUE){
if(dbutton4) {
if (!dbutton7){
if (m != 3){
m = menu(0); dbutton4=0;
}
}
}
if(dbutton5) {
if (m != 3){
m = menu(1); dbutton5=0;
}
}
if(dbutton6) {
if (m != 3){
m = menu(2); dbutton6=0;
}
}
if(dbutton7) {
if (m == 3){m = menu(0);}
if (dbutton4){
m = menu(3);
dbutton4=0;
}
}
delay_ms(500);
if (m == 0){
Pantalla_0();
}
if (m == 1){
Pantalla_1();
}
if (m == 2){
Pantalla_2();
}
if (m == 3){
if (dbutton4){ //UP
if (set_ == 1){
set_vref(1);
dbutton4=0;
}
else{
Pantalla_3(1);
dbutton4=0;
}
}
if (dbutton5){ //DOWN
if (set_ == 1){
set_vref(2);
dbutton5=0;
}
else{
Pantalla_3(2);
dbutton5=0;
}
}
if (dbutton6){ //SET
set_ = 1;
if (set_ == 1){
set_ = 0;
}
dbutton6=0;
}
if (dbutton7){ //EXIT
m = menu(0);
Pantalla_0();
dbutton7=0;
}
Pantalla_3(0);
}
if ((minutos5 - t ) == 5){ /// este if debe estar dentro del rango de refresco de el while superior. debido a que tiene que coincidir con el minuto x (ver diferencia minutos5-m) [graba cada 5 minutos]
write_eeprom16(5,6,minutos5);
delay_ms(1000);
if (read_eeprom16(5,6) != minutos5){
iniciar_eeprom(1);
write_eeprom16(5,6,minutos5);
}
t = minutos5;
}
grupo(2);
if (check_temp(1)) { //motor
alertas(1);
if (eg == 1) {grupo(0);}
} //motor--
if (check_temp(2)) { //alternador
alertas(1);
if (eg == 1){grupo(0);}
} //alternador--
c_state = read_analog(8);
if (c_state < 250 ){ //llave en 0
grupo(0);
}
if ((c_state > 250) && (c_state < 850)){ //llave en contacto
output_high(PIN_C5);
if (!eg){
alertas(4); //listo para encender grupo
}
h = 1; //vuelve el estado h 1 para que se pueda intentar encender el grupo nuevamente.
}
if (c_state > 850) { //llave en uno
grupo(1);
}
}
}