Saludos,
Estoy realizando un proyecto con un pic 16f873a, el cual consiste en controlar un purificador de aire, sensa la red electrica y caundo hay alto o bajo voltaje apaga las salidas del microcontrolador. Tambien sensa unas fotoresistencias e indica cuando una lampara falla. Este tiene un LCD4x20(8bits), la idea es guardar en la memoria eeprom del micro la cantidad de horas que haya trabajado el purificador y desplegar el valor en el lcd, el problema es que el programa escribe bien en la eeprom pero no es capaz de leer nuevamente el valor y desplegarlo en el lcd. Les dejo el codigo para que por favor si alguno sabe donde esta el inconveniente me ayude
#include <16f873A.h>
#device ADC=16
#use delay(clock=20000000,restard_wdt)
#fuses HS,NOPROTECT,noWDT
#byte intcon=0x0b //byte de control de interrupciones
#byte adcon0=0x1f //byte de configuracion del conversor de A/D
#byte adcon1=0x9f //byte de configuracion del conversor de A/D
#byte porta=0x05 //byte de puerto_a
#byte portb=0x06 //byte de puerto_b
#byte portc=0x07 //byte de puerto_c
float v_res=0.00228885, v_red=0;
int ad_sel=0,x,y,flag_fail,cont_fail;
int8 tmr_display,minutos;
int16 lamp_1,lamp_2,lamp_3,lamp_4,
lamp_error=12752,v_errormin=39321,
v_errormax=56797,pid_v=0,reset_flag_low=45875,reset_flag_high=54613,
cont=0,horas=0,total_fail=0;
int32 v_red1=0,cont1=0;
#include "LCD4x20_8B.c"
#int_timer2
void Timer_Horas(void)
{
if(bit_test(portc,4))
{
cont++;
cont1++;
if(cont==60000)
{
minutos=minutos+1;
cont=0;
}
restart_wdt();
}
}
#int_timer0
void isr_Timer0()
{
tmr_display++;
set_timer0(98);
}
void voltaje(void)
{
if((v_red1<=v_errormin)||(v_red1>=v_errormax))
{
flag_fail=1;
cont_fail=1;
write_eeprom(0,horas);
write_eeprom(1,horas>>8);
}
if((v_red1>=reset_flag_low)&&(v_red1<=reset_flag_high))
{
total_fail=total_fail+cont_fail;
cont_fail=0;
flag_fail=0;
}
}
void Desplegar(void)
{
lcd_gotoxy(0,2);
printf(lcd_putc," ");
int16 tmpEEPROM=0;
lcd_gotoxy(1,1);
printf(lcd_putc,"***VOLTAJE %f***",v_red);
if(minutos>=60)
{
horas=horas+1;
minutos=0;
}
tmpEEPROM=read_eeprom(1);
tmpEEPROM<<=8;
tmpEEPROM|=read_eeprom(0);
tmpEEPROM=horas;
lcd_gotoxy(5,2);
printf(lcd_putc,"HORAS %Lu",tmpEEPROM);
lcd_gotoxy(5,2);
printf(lcd_putc,"HORAS %Lu",horas);
lcd_gotoxy(2,3);
printf(lcd_putc," FALLAS VOLTAJE %Lu",total_fail);
if((lamp_1<=lamp_error)||(lamp_2<=lamp_error)||(lamp_3<=lamp_error)||(lamp_4<=lamp_error))
{
lcd_gotoxy(1,4);
printf(lcd_putc,"***FALLA LAMPARA***");
}
else
{
lcd_gotoxy(1,4);
printf(lcd_putc," ");
}
}
void read_ad(void)
{
ad_sel++;
if(ad_sel==1)
{
set_adc_channel(0);
delay_us(30);
if(v_red==0)
{
v_red1=read_adc();
v_red=v_red1*v_res;
}
else if(pid_v>=1000)
{
v_red=v_red1*v_res;
pid_v=1;
}
else
{
v_red1=v_red1+read_adc();
v_red1=v_red1/2;
}
pid_v++;
}
else if(ad_sel==2)
{
set_adc_channel(1);
delay_us(30);
lamp_1=read_adc();
}
else if(ad_sel==3)
{
set_adc_channel(2);
delay_us(30);
lamp_2=read_adc();
}
else if(ad_sel==4)
{
set_adc_channel(3);
delay_us(30);
lamp_3=read_adc();
}
else if(ad_sel==5)
{
set_adc_channel(4);
delay_us(30);
lamp_4=read_adc();
ad_sel=0;
}
return;
}
void main(void)
{
restart_wdt();
setup_wdt(WDT_18MS);
set_tris_a(255);
set_tris_b(0);
set_tris_c(0b00010000);
lcd_init();
portb=0;
portc=0;
intcon=0b11000000;
adcon0=0b10000001;
adcon1=0b01000010;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
enable_interrupts(int_timer0);
setup_timer_2(T2_DIV_BY_4, 125, 10);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
restart_wdt();
while(true)
{
read_ad();
if(tmr_display>=250)
{
desplegar();
Voltaje();
tmr_display=0;
}
if((bit_test(portc,4))&&(flag_fail==0))
{
bit_set(portc,0);
bit_set(portc,1);
bit_set(portc,2);
bit_set(portc,3);
}
else
{
bit_clear(portc,0);
bit_clear(portc,1);
bit_clear(portc,2);
bit_clear(portc,3);
}
if(bit_test(porta,4)||(horas==8000))
{
horas=0;
write_eeprom(0,0);
write_eeprom(1,0);
}
v_red=v_red1*v_res;
restart_wdt();
}
}
Estoy realizando un proyecto con un pic 16f873a, el cual consiste en controlar un purificador de aire, sensa la red electrica y caundo hay alto o bajo voltaje apaga las salidas del microcontrolador. Tambien sensa unas fotoresistencias e indica cuando una lampara falla. Este tiene un LCD4x20(8bits), la idea es guardar en la memoria eeprom del micro la cantidad de horas que haya trabajado el purificador y desplegar el valor en el lcd, el problema es que el programa escribe bien en la eeprom pero no es capaz de leer nuevamente el valor y desplegarlo en el lcd. Les dejo el codigo para que por favor si alguno sabe donde esta el inconveniente me ayude
#include <16f873A.h>
#device ADC=16
#use delay(clock=20000000,restard_wdt)
#fuses HS,NOPROTECT,noWDT
#byte intcon=0x0b //byte de control de interrupciones
#byte adcon0=0x1f //byte de configuracion del conversor de A/D
#byte adcon1=0x9f //byte de configuracion del conversor de A/D
#byte porta=0x05 //byte de puerto_a
#byte portb=0x06 //byte de puerto_b
#byte portc=0x07 //byte de puerto_c
float v_res=0.00228885, v_red=0;
int ad_sel=0,x,y,flag_fail,cont_fail;
int8 tmr_display,minutos;
int16 lamp_1,lamp_2,lamp_3,lamp_4,
lamp_error=12752,v_errormin=39321,
v_errormax=56797,pid_v=0,reset_flag_low=45875,reset_flag_high=54613,
cont=0,horas=0,total_fail=0;
int32 v_red1=0,cont1=0;
#include "LCD4x20_8B.c"
#int_timer2
void Timer_Horas(void)
{
if(bit_test(portc,4))
{
cont++;
cont1++;
if(cont==60000)
{
minutos=minutos+1;
cont=0;
}
restart_wdt();
}
}
#int_timer0
void isr_Timer0()
{
tmr_display++;
set_timer0(98);
}
void voltaje(void)
{
if((v_red1<=v_errormin)||(v_red1>=v_errormax))
{
flag_fail=1;
cont_fail=1;
write_eeprom(0,horas);
write_eeprom(1,horas>>8);
}
if((v_red1>=reset_flag_low)&&(v_red1<=reset_flag_high))
{
total_fail=total_fail+cont_fail;
cont_fail=0;
flag_fail=0;
}
}
void Desplegar(void)
{
lcd_gotoxy(0,2);
printf(lcd_putc," ");
int16 tmpEEPROM=0;
lcd_gotoxy(1,1);
printf(lcd_putc,"***VOLTAJE %f***",v_red);
if(minutos>=60)
{
horas=horas+1;
minutos=0;
}
tmpEEPROM=read_eeprom(1);
tmpEEPROM<<=8;
tmpEEPROM|=read_eeprom(0);
tmpEEPROM=horas;
lcd_gotoxy(5,2);
printf(lcd_putc,"HORAS %Lu",tmpEEPROM);
lcd_gotoxy(5,2);
printf(lcd_putc,"HORAS %Lu",horas);
lcd_gotoxy(2,3);
printf(lcd_putc," FALLAS VOLTAJE %Lu",total_fail);
if((lamp_1<=lamp_error)||(lamp_2<=lamp_error)||(lamp_3<=lamp_error)||(lamp_4<=lamp_error))
{
lcd_gotoxy(1,4);
printf(lcd_putc,"***FALLA LAMPARA***");
}
else
{
lcd_gotoxy(1,4);
printf(lcd_putc," ");
}
}
void read_ad(void)
{
ad_sel++;
if(ad_sel==1)
{
set_adc_channel(0);
delay_us(30);
if(v_red==0)
{
v_red1=read_adc();
v_red=v_red1*v_res;
}
else if(pid_v>=1000)
{
v_red=v_red1*v_res;
pid_v=1;
}
else
{
v_red1=v_red1+read_adc();
v_red1=v_red1/2;
}
pid_v++;
}
else if(ad_sel==2)
{
set_adc_channel(1);
delay_us(30);
lamp_1=read_adc();
}
else if(ad_sel==3)
{
set_adc_channel(2);
delay_us(30);
lamp_2=read_adc();
}
else if(ad_sel==4)
{
set_adc_channel(3);
delay_us(30);
lamp_3=read_adc();
}
else if(ad_sel==5)
{
set_adc_channel(4);
delay_us(30);
lamp_4=read_adc();
ad_sel=0;
}
return;
}
void main(void)
{
restart_wdt();
setup_wdt(WDT_18MS);
set_tris_a(255);
set_tris_b(0);
set_tris_c(0b00010000);
lcd_init();
portb=0;
portc=0;
intcon=0b11000000;
adcon0=0b10000001;
adcon1=0b01000010;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
enable_interrupts(int_timer0);
setup_timer_2(T2_DIV_BY_4, 125, 10);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
restart_wdt();
while(true)
{
read_ad();
if(tmr_display>=250)
{
desplegar();
Voltaje();
tmr_display=0;
}
if((bit_test(portc,4))&&(flag_fail==0))
{
bit_set(portc,0);
bit_set(portc,1);
bit_set(portc,2);
bit_set(portc,3);
}
else
{
bit_clear(portc,0);
bit_clear(portc,1);
bit_clear(portc,2);
bit_clear(portc,3);
}
if(bit_test(porta,4)||(horas==8000))
{
horas=0;
write_eeprom(0,0);
write_eeprom(1,0);
}
v_red=v_red1*v_res;
restart_wdt();
}
}