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

Discussion in 'Embedded Systems and Microcontrollers' started by munap, May 26, 2013.

  1. munap

    Thread Starter Member

    Nov 23, 2012
    33
    0
    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.

    Code ( (Unknown Language)):
    1.     if((PORTA.f1==1) & (mode>0)){
    2.      EEPROM_Write(0x00, minutes);
    3.      EEPROM_Write(0x01, hours);
    4.  
    5.      //editClock();
    6.      //while(PORTA==0b00000010){delay_ms(100);} //wait for PB2 release button
    7.      }
    8.      if((PORTA.f2==0) & (mode>0)){
    9.      minutes=EEPROM_Read(0x00);
    10.      hours=EEPROM_Read(0x01);
    Please ignore the comment, a further explanation would help me very much.
     
  2. munap

    Thread Starter Member

    Nov 23, 2012
    33
    0
    Code ( (Unknown Language)):
    1.  
    2. void main() {
    3.   //Delay_ms(500);
    4.   mode=0;
    5.   Init_Main();               // Perform initialization
    6.   while (1) {                // Endless loop
    7.     if(mode==0){
    8.     Read_Time();             // Read time from RTC(DS1307)
    9.     Transform_Time();        // Format date and time
    10.     Display_Time();          // Prepare and display on LCD
    11.     }
    12.     if(PORTA.f0==1){
    13.      mode++;
    14.      if(mode>6){
    15.       mode=0;
    16.       //Dec2Bcd(a);
    17.       seconds=Dec2Bcd(seconds);minutes=Dec2Bcd(minutes);hours=Dec2Bcd(hours);
    18.       date=Dec2Bcd(date);month=Dec2Bcd(month);year=Dec2Bcd(year);
    19.       I2C1_Start();I2C1_Wr(0xD0); I2C1_Wr(0);
    20.       I2C1_Wr(seconds);I2C1_Wr(minutes);I2C1_Wr(hours);
    21.       I2C1_Wr(day);I2C1_Wr(date);I2C1_Wr(month);I2C1_Wr(year);I2C1_Stop();
    22.       Lcd_Cmd(_LCD_CURSOR_OFF);
    23.       }
    24.      else{Lcd_Cmd(_LCD_BLINK_CURSOR_ON); }
    25.      switch(mode){
    26.       //seconds, minutes, hours, day, date, month, year
    27.       case 0:break;
    28.       case 1:Lcd_Out(1,11,".");break;
    29.       case 2:Lcd_Out(1,8,".");break;
    30.       case 3:Lcd_Out(1,5,":");break;
    31.       case 4:Lcd_Out(2,5,":");break;
    32.       case 5:Lcd_Out(2,8,":");break;
    33.       case 6:Lcd_Out(2,11,":");break;
    34.      }
    35.      while(PORTA.f0==1){delay_ms(100);} //wait for PB1 release button
    36.      }
    37.     if((PORTA.f1==1) & (mode>0)){
    38.      EEPROM_Write(0x00, minutes);
    39.      EEPROM_Write(0x01, hours);
    40.  
    41.      //editClock();
    42.      //while(PORTA==0b00000010){delay_ms(100);} //wait for PB2 release button
    43.      }
    44.      if((PORTA.f2==0) & (mode>0)){
    45.      minutes=EEPROM_Read(0x00);
    46.      hours=EEPROM_Read(0x01);
    47.      
    48.  
    49.  
    50.      //editClock();
    51.      //while(PORTA==0b00000010){delay_ms(100);} //wait for PB2 release button
    52.      }
    53.   }
    54. }
    The earlier code not complete, here i put whole coding w/o the subroutine,hope someone can give a bit enlightment here.
     
  3. sairfan1

    Member

    May 24, 2012
    46
    1
    add Delay_Ms(20); after every write eeprom statement or wait for write process complete by while(EECON1.WR);
     
    munap likes this.
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
    munap likes this.
Loading...