c - PIC 18F452 Life Timer Storage -


we storing timer in eeprom_write data wipes out due unknown reason. highly appreciated. in short if have code run life-timer ( mileage meter in bike, storage last stage on system poweroff , restore last point ) in pic 18f452, kindly share us.

<pre> /* ==============================lcd en    rb0    pin # 33 rs    rb1    pin # 34 d4    rb4    pin # 37 d5    rb5    pin # 38 d6    rb6    pin # 39 d7    rb7    pin # 40 microchip */ unsigned int time = 0; unsigned int sec=0; unsigned int minutes=0; unsigned int hour=0; char select_mode=0; unsigned int lt_minutes; unsigned int lt_hour;  char txt2[]="0000000000"; char txt3[]="000000000000"; char txt4[]="0000000000"; char txt5[]="0000000000"; char txt10[]="000000000000"; char txt11[]="000000000000";  // lcd module connections sbit lcd_rs @ rb1_bit; sbit lcd_en @ rb0_bit; sbit lcd_d4 @ rb4_bit; sbit lcd_d5 @ rb5_bit; sbit lcd_d6 @ rb6_bit; sbit lcd_d7 @ rb7_bit;  sbit lcd_rs_direction @ trisb1_bit; sbit lcd_en_direction @ trisb0_bit; sbit lcd_d4_direction @ trisb4_bit; sbit lcd_d5_direction @ trisb5_bit; sbit lcd_d6_direction @ trisb6_bit; sbit lcd_d7_direction @ trisb7_bit; // end lcd module connections  //char uart_rd;  char txt8[] = "tele fun"; char txt9[] = "0900-78601";  //timer1 //prescaler 1:8; tmr1 preload = 3035; actual interrupt time : 100 ms  //place/copy part in declaration section  void inittimer1(){   t1con         = 0x31;   tmr1if_bit    = 0;   tmr1h         = 0x6d;   tmr1l         = 0x84;   tmr1ie_bit    = 1;   intcon        = 0xc0; }  void interrupt(){   if (tmr1if_bit){     tmr1if_bit = 0;     tmr1h         = 0x6d;     tmr1l         = 0x84;     //enter code here     time++;      // time 1 = 100ms, time 2 = 200ms     if (time==10){           time=0;           sec++;           if (sec==60){sec=0;minutes++;lt_minutes++;}           if (minutes==60){minutes=0;hour++;}           if (lt_minutes==60){             //eeprom_write(0x03,lt_minutes);            lt_minutes=0;           lt_hour++;           //eeprom_write(0x04,lt_hour);           }           if (lt_hour==9999){lt_hour=0;}       }   } }  void main() {    adcon0=0b00010101;   adcon1=0b10001110;   lcd_init();                      // initialize lcd   lcd_cmd(_lcd_clear);               // clear display    trise0_bit = 0;                  // set rb0 pin output   trise1_bit = 0;    lt_minutes = eeprom_read(0x03);   if ((lt_minutes>=0)&&(lt_minutes<=60))lt_minutes = eeprom_read(0x03);   else eeprom_write(0x03,0);lt_minutes = eeprom_read(0x03);   delay_ms(10);     if ((lt_hour>=0)&&(lt_hour<=9999))lt_hour = eeprom_read(0x04);   else eeprom_write(0x04,0);lt_hour = eeprom_read(0x04);   delay_ms(10);    if (lt_hour==255){lt_hour=0;}    lcd_cmd(_lcd_cursor_off);          // cursor off    inittimer1();    while (1) {                           // endless loop      if (sec==15){          eeprom_write(0x03,lt_minutes);          eeprom_write(0x04,lt_hour);        }          lcd_out(1,11,"  ");            // write text in first row         lcd_out(2,9,"   ");            // write text in first row         lcd_out(1,1,"lt");             // write text in first row         lcd_out(2,1,"rt");             // write text in first row         lcd_out(2,6,":");              // write text in first row         lcd_out(1,8,":");              // write text in first row         lcd_out(3,2,txt8);             // write text in first row         lcd_out(4,5,txt9);             // write text in first row           wordtostrwithzeros(minutes, txt2);         wordtostrwithzeros(hour, txt3);            eeprom_write(0x03,lt_minutes);          eeprom_write(0x04,lt_hour);           wordtostrwithzeros(lt_minutes, txt10);         wordtostrwithzeros(lt_hour, txt11);          lcd_chr(1,4,txt11[1]);            // lt h         lcd_chr(1,5,txt11[2]);            // lt h         lcd_chr(1,6,txt11[3]);            // lt h         lcd_chr(1,7,txt11[4]);            // lt h          lcd_chr(1,9,txt10[3]);           // lt m         lcd_chr(1,10,txt10[4]);          // lt m          lcd_chr(2,7,txt2[3]);         lcd_chr(2,8,txt2[4]);          lcd_chr(2,4,txt3[3]);         lcd_chr(2,5,txt3[4]);     }     } <code> 

if writing in eeprom @ time of power-off check how long takes write eeprom , think might loosing power totally before finished writing eeprom. putting capacitor between vcc-gnd store power might resolve if problem related hardware , missing @ time of power-off.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -