MikroC compiler - store rtc(ds1307) in eeprom(internal)

Thread Starter

munap

Joined Nov 23, 2012
33
Hello,

i'm doing rtc and eeprom project using PIC16F877A. But programming using mikroc and c languange very new to me. So i ask for guide,please help me.
Here some code that i got stuck for while,please show my mistake please.

Rich (BB code):
    if((PORTA.f1==1) & (mode>0)){
     EEPROM_Write(0x00, minutes);
     EEPROM_Write(0x01, hours);

     //editClock();
     //while(PORTA==0b00000010){delay_ms(100);} //wait for PB2 release button
     }
     if((PORTA.f2==0) & (mode>0)){
     minutes=EEPROM_Read(0x00);
     hours=EEPROM_Read(0x01);
Please ignore the comment, a further explanation would help me very much.
 

Thread Starter

munap

Joined Nov 23, 2012
33
Rich (BB code):
void main() {
  //Delay_ms(500);
  mode=0;
  Init_Main();               // Perform initialization
  while (1) {                // Endless loop
    if(mode==0){
    Read_Time();             // Read time from RTC(DS1307)
    Transform_Time();        // Format date and time
    Display_Time();          // Prepare and display on LCD
    }
    if(PORTA.f0==1){
     mode++;
     if(mode>6){
      mode=0;
      //Dec2Bcd(a);
      seconds=Dec2Bcd(seconds);minutes=Dec2Bcd(minutes);hours=Dec2Bcd(hours);
      date=Dec2Bcd(date);month=Dec2Bcd(month);year=Dec2Bcd(year);
      I2C1_Start();I2C1_Wr(0xD0); I2C1_Wr(0);
      I2C1_Wr(seconds);I2C1_Wr(minutes);I2C1_Wr(hours);
      I2C1_Wr(day);I2C1_Wr(date);I2C1_Wr(month);I2C1_Wr(year);I2C1_Stop();
      Lcd_Cmd(_LCD_CURSOR_OFF);
      }
     else{Lcd_Cmd(_LCD_BLINK_CURSOR_ON); }
     switch(mode){
      //seconds, minutes, hours, day, date, month, year
      case 0:break;
      case 1:Lcd_Out(1,11,".");break;
      case 2:Lcd_Out(1,8,".");break;
      case 3:Lcd_Out(1,5,":");break;
      case 4:Lcd_Out(2,5,":");break;
      case 5:Lcd_Out(2,8,":");break;
      case 6:Lcd_Out(2,11,":");break;
     }
     while(PORTA.f0==1){delay_ms(100);} //wait for PB1 release button
     }
    if((PORTA.f1==1) & (mode>0)){
     EEPROM_Write(0x00, minutes);
     EEPROM_Write(0x01, hours);

     //editClock();
     //while(PORTA==0b00000010){delay_ms(100);} //wait for PB2 release button
     }
     if((PORTA.f2==0) & (mode>0)){
     minutes=EEPROM_Read(0x00);
     hours=EEPROM_Read(0x01);
     


     //editClock();
     //while(PORTA==0b00000010){delay_ms(100);} //wait for PB2 release button
     }
  }
}
The earlier code not complete, here i put whole coding w/o the subroutine,hope someone can give a bit enlightment here.
 

THE_RB

Joined Feb 11, 2008
5,438
The MikroC library function EEPROM_Write() contains inbuilt checking for write completion before it will initiate a new write.

The OP's problem is the really bad general state of the code. He needs to separate it into modules that handle the clock time updating, display handling, button and clock set handling, and eeprom storage code.

If they were properly separated they could be checked and tested individually.
 
Top