Forums Arduino Project Discussions pic8583 rtc

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Bitahwa Bindu 4 months ago.

  • Author
    Posts
  • #2902

    munna1
    Participant

    <table>
    <tbody>
    <tr>
    <td>1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27</td>
    <td width=”1766″>#define ConvertToBCD(x,y) (((x-‘0’) << 4) + y – ‘0’)

     

    I2C1_Init(100000);  //PCF8583 I2C is running at 100KHz

     

    I2C1_Start();           // begin I2C communications

    I2C1_Wr(0xA0);      // writing address

    I2C1_Wr( 0 );

    I2C1_Wr( 0x80 );

    I2C1_Wr( 0 );

    I2C1_Wr( ConvertToBCD(Time[6], Time[7])); // write Seconds

    I2C1_Wr( ConvertToBCD(Time[3], Time[4])); // write Minutes

    I2C1_Wr( ConvertToBCD(Time[0], Time[1])); // write Hours

     

    year = 10 * (Date[6] – ‘0’] + Date[7] – ‘0’;

    EEPROM_Write(0, year)             // write year to EEPROM adress 0

    yr = (year % 4) << 2;

    Date[0] = Date[0] + yr;

     

    I2C1_Wr( ConvertToBCD(Date[0], Date[1])); // write Day

    I2C1_Wr( ConvertToBCD(Date[3], Date[4])); // write Month

    I2C1_Stop();

    I2C1_Start();

     

    I2C1_Wr(0xA0);      // writing address

    I2C1_Wr( 0 );

    I2C1_Wr( 0 );          // enable counting

    I2C1_Stop();</td>
    </tr>
    </tbody>
    </table>
     

     
    <table>
    <tbody>
    <tr>
    <td>1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39</td>
    <td width=”1766″>#define HigherBit(x) ((x >>) + ‘0’)

    #define LowerBit(x) ((x & 0x0F) + ‘0’)

     

    unsigned char rtc, year, seconds;

     

    I2C1_Start();           // begin I2C communications

    I2C1_Wr(0xA0);      // addresses the chip

    I2C1_Wr(0x2 );

    I2C1_Start();           // begin I2C communications

    I2C1_Wr(0xA1);      // addresses for reading

    rtc = I2C1_Rd(1);    // read seconds

    Time[6] = HigherBit(rtc);

    Time[7] = LowerBit(rtc);

    seconds = 10 * (Time[6] -‘0’) + Time[7]-‘0’;

    new_time = seconds;

    rtc = I2C1_Rd(1);     //read minutes

    Time[3] = HigherBit(rtc);

    Time[4] = LowerBit(rtc);

    rtc = I2C1_Rd(1);     //read hours

    Time[0] = HigherBit(rtc);

    Time[1] = LowerBit(rtc);

    rtc = I2C1_Rd(1);     //read year/day

    Date[0] = HigherBit((rtc & 0x30));

    Date[1] = LowerBit(rtc);

    year = (rtc & 0xC0) >>6;   //Year starts from 2008

    rtc = I2C1_Rd(0)     //read weekday/month

    Date[3] = HigherBit((rtc & 0x10);

    Date[4] =LowerBit(rtc);

    I2C1_Stop();               // Stop condition I2C on bus

     

    //Year adjustment in EEPROM

    rtc = EEPROM_Read(0)                  //address 0 of EEPROM

    if (year ! 0)

    {

    rtc++;

    EEPROM_Write(0,rtc);

    }

    Date[6] = (rtc / 10) + ‘0’;

    Date[7] = (rtc % 10) + ‘0’;</td>
    </tr>
    </tbody>
    </table>
    could you please explain how are you writing to control register , in event counter when its counts meet a set point it will give alarm how do we write it.

  • #2904

    Bitahwa Bindu
    Keymaster

    Hi. Please write properly your question and the code, we can hardly see what you are writing. If you want to insert the code, click on tools menu than source code. Insert your code there and be specific with your question.

     

You must be logged in to reply to this topic.