How to switch between 12/24 hour format RTC DS1307

Status
Not open for further replies.
It will easy for us to at least to track and find out the issue if you could post the code.
 

the code is attached is below . . .

Code C - [expand]
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
unsigned short read_ds1307(unsigned short address)
      {
        unsigned short read_data;
        I2C1_Start();
        I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
        I2C1_Wr(address);
        I2C1_Repeated_Start();
        I2C1_Wr(0xD1); //0x68 followed by 1 --> 0xD1
        read_data=I2C1_Rd(0);
        I2C1_Stop();
        return(read_data);
      }
      void write_ds1307(unsigned short address,unsigned short write_data)
      {
        I2C1_Start(); // issue I2C start signal
        //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
        I2C1_Wr(0xD0); // send byte via I2C (device address + W)
        I2C1_Wr(address); // send byte (address of DS1307 location)
        I2C1_Wr(write_data); // send data (data to be written)
        I2C1_Stop(); // issue I2C stop signal
      }
 
      unsigned char MSB(unsigned char x)           //Display Most Significant Bit of BCD number
      {
        return ((x >> 4) + '0');
      }
      unsigned char  LSB(unsigned char x)          //Display Least Significant Bit of BCD number
      {
        return ((x & 0x0F) + '0');
      }
       void main()
      {
       I2C1_Init(100000);     //DS1307 I2C is running at 100KHz
       PORTA = 0 ;
       ADCON1 = 0x06;         // Configure all ports with analog function as digital
       TRISA = 0b000111;
       TRISB = 0 ;
       TRISC = 0b00011000 ;
       PORTC = 0 ;
       PORTB = 0 ;
       I2C1_Start() ;
       I2C1_wr(0x0D) ;
       I2C1_wr(0) ;
       I2C1_wr(0x80) ;
       I2C1_wr(0x51) ;
       I2C1_wr(0x71) ;
       I2C1_Stop() ;
       write_ds1307(7,0x50) ; // SQWE output 1Hz
      write_ds1307(2,0x40) ; // <========  time set for 12 hour mode
       oldstate = 1 ;       
 
       do {. . . . 
 
      . . . .         }
            second = read_ds1307(0);
            minute = read_ds1307(1);
            hour = read_ds1307(2);
            hr = hour & 0b00011111;



some parts copied from the web....
 
Last edited by a moderator:

can you give comments for each statement what u have understood so far
 

Hi,

You wanted to switch the clock to 12h mode.

And with
Code:
      write_ds1307(2,0x40) ; // <========  time set for 12 hour mode
You did it.

Well done.

****
But still it seems you are not satified with this solution.
If this is the case, then re-read my post#18.

Klaus
 
the problem is it does not change when it comes to 13hours to 1 hour. It continues 13 onwards. . .
 

Hi,

the problem is it does not change when it comes to 13hours to 1 hour. It continues 13 onwards. . .
At least this is an information we did not know before.

We can´t see this as long as you don´t show us.

--> Please show us exactely the 8 bit that you read from the clock hours register. Without changing anything.
(We need to see ALL related bits. The "13" doesn´t tell much, because we don´t see the setup the clock is running currently)

Best is to read ALL related registers from the clock and show - without change. Best in binary or HEX.

Klaus
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…