Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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;
write_ds1307(2,0x40) ; // <======== time set for 12 hour mode
At least this is an information we did not know before.the problem is it does not change when it comes to 13hours to 1 hour. It continues 13 onwards. . .