Simple clock display program sharing based on DS1307

At present, most of the digital electronic clocks for household use can only display information such as hours and minutes, and have a single function, and most of them use LED digital tubes as display devices, which consume large power and cannot satisfy consumers.

Introduction to DS1307

The AM/PM flag determines whether the clock operates in 24-hour or 12-hour mode. The chip has a built-in power sensing circuit with brownout detection and battery switching.

It is a low-power, full-BCD code clock calendar real-time clock chip with 56 bytes of non-volatile RAM. The address and data are transmitted through a two-wire bidirectional serial bus. The chip can provide information such as seconds, minutes and hours. The number of days per month can be adjusted automatically. And have leap year compensation function

Features:

It can count seconds, hours, minutes, days of the month, months, days of the week, and has leap year compensation. The annual cap is 2100.

56 bytes of non-volatile RAM

Two-wire serial interface

Programmable square wave output

Automatic power failure detection and switching circuit

In battery backup mode, power consumption is less than 500nA

Industrial grade operating temperature: -40 to 80

8-pin DIP and SOIC package

Simple clock display program sharing based on DS1307

Let's share the simple clock display program based on DS1307 for everyone:

* Coder: NUIST_XKFYT

* E-mail: (Welcome to get help info about this program)

* Date: 2016-7-17

*

* Device: STC89C54RD, DS1307Z+

* FuncTIon: Easy Clock Display

* Note:

* 1.DS1307 four-bit fixed address bit is 1101, three-bit programmable address bit is 000

*/

#include "STC89C5xRC.h" /* can be replaced with "reg52.h" or "AT89x52.h" */

#include "intrins.h"

//#include "TIme.h" /* Cannot call the standard library function in Keil v4 */

#define uchar unsigned char

#define uint unsigned int

/* DS1307 operation instruction*/

#define DS1307_WRITE 0xD0

#define DS1307_READ 0xD1

#define DS1307_DISABLE 0x80

#define DS1307_ENABLE 0x7F

#define DS1307_12HOUR_MODE 0x20

#define DS1307_24HOUR_MODE 0xDF

/* DS1307 internal device address */

#define ADDR_SEC 0x00

#define ADDR_MIN 0x01

#define ADDR_HOUR 0x02

#define ADDR_DAY 0x03

#define ADDR_DATE 0x04

#define ADDR_MONTH 0x05

#define ADDR_YEAR 0x06

#define ADDR_COR 0x07

/* Module comes with AT24C02" reserved interface * /

//#define AT24C02_WRITE 0xA0

//#define AT24C02_READ 0xA1

Sbit I2C_SCL = P1^0;

Sbit I2C_SDA = P1^1;

Uchar min = 0;

Uchar sec = 0;

Uchar code tab[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

/* Re-customize the tm structure in TIme.h*/

Struct tm

{

Uchar tm_sec; /* seconds – the value range is [0,59] */

Uchar tm_min; /* min - the value range is [0,59] */

Uchar tm_hour; /* when - the value range is [0,23] */

Uchar tm_mday; /* Date in a month - the value range is [1,31] */

Uchar tm_mon; /* Month (starting from January, 0 for January) - The value range is [1,12] */

Uchar tm_year; /* year*/

Uchar tm_wday; /* week – the value range is [1,7] */

};

/* delay 5us */

Void delay_5us(void)

{

_nop_();

}

/* delay par*1ms */

Void delay_ms(uint par)

{

Uchar cnt = 0;

While(par--)

For(cnt = 120;cnt 》 0;cnt--);

}

Void I2C_Start(void)

{

I2C_SDA = 1;

I2C_SCL = 1;

Delay_5us(); /* The actual delay is 4.7us*/

I2C_SDA = 0; /* When SCL is high, SDA is the falling edge indicating the start signal*/

Delay_5us();

}

Void I2C_Stop(void)

{

I2C_SDA = 0;

I2C_SCL = 1;

Delay_5us();

I2C_SDA = 1; /* When SCL is high, SDA is a rising edge to indicate the end signal*/

Delay_5us();

}

Void I2C_Ack(void)

{

Uchar cnt = 0;

I2C_SCL = 0; /* Waiting for a response while SCL is high*/

Delay_5us();

While((I2C_SDA == 1)&&(cnt " 250)) /* If the response is 0, the slave will send a response signal to the host*/

Cnt++; /* wait for a while*/

I2C_SCL = 0;

Delay_5us();

}

Void I2C_noAck(void)

{

I2C_SCL = 1; /* When the scl is high, the master sends a 1, non-acknowledgement signal to the slave*/

Delay_5us();

I2C_SDA = 1;

I2C_SCL = 0;

Delay_5us();

}

Void I2C_sendByte(uchar dat)

{

Uchar cnt = 0;

Uchar dat_buf = 0;

Dat_buf = dat;

For(cnt = 0;cnt " 8;cnt++)

{

Dat_b

Wireless Charger Car Phone Holder

Wireless Charger Car Phone Holder,In Car Phone Holder Wireless Charger,Car Phone Holder And Charger,Phone Car Mount With Wireless Charger

Ningbo Luke Automotive Supplies Ltd. , https://www.nbluke.com

Posted on