Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

real time clock (ds1307)

Status
Not open for further replies.

vead

Full Member level 5
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Activity points
3,815
hello

I am interfacing RTC with microcontroller and LED.
actually I have prototyping KIt (cortex m0). I only need c code.
I want to control LED using real time clock via I2c pins

Set alarm for 5 second (automatically turn on LED for 5 second )
Set alarm for 3 minute (automatically turn on LED for 3 minute)
Set alarm for 1 hours (automatically turn on Led for 1 hours )

SCL connected with P3.5;
SDA connected with P3.1;
LED connected with P1.6

LED will read the data form ds1307 via i2c pins

I did google searched but I did not find related to LED. I am not using LCD
can someone explain with small example. How to write c code for minute , hours , day ?
 

you can search the forum have many ds1307 code. for LED operating use three variable for second,minute,hour when timer start increment second variable and turn on led. if second = 5 then turn the led gpio off.and for minutes increment the minute variable when second variable rich to 59.and do same like for hour.
 

ok , I want to send data from device to ds1307.

example
1. Send a start sequence
2. Send 0xD0 ( address of the DS1307 )
3. Send 0x00 (address of seconds register)
4. Send 0x10 ((10 data as 10 second)
5. Send stop sequence

Code:
void I2C_Init()
{
	SDA = 1;
	SCL = 1;
}

void I2C_Start()        // start I2C
{
	SDA = 0;
	SCL = 0;
}

I2C_Send(0xD0);      // address of the DS1307 )
I2C_Send(0x00);      // address of seconds register
I2C_Send(0x10);       // 10 data as 10 second

void I2C_Stop()    // stop I2C
{
	SCL = 0;
	SDA = 0;
	SCL = 1;
	SDA = 1;
}
how to write from device ?
 

**broken link removed**
**broken link removed**
 
  • Like
Reactions: vead

    vead

    Points: 2
    Helpful Answer Positive Rating
**broken link removed**
**broken link removed**


I saw that sample code. Now I am trying to write myself
Code:
                void I2C_Init()         //
                {
                    SDA = 1;
                    SCL = 1;
                }

                void I2C_Start()       // start I2C
                {
                    SDA = 0;
                    SCL = 0;
                }

                I2C_write()               //  send data to Ds1307
                {
                I2C_write(0xD0);      // address of the DS1307 )
                I2C_write(0x00);      // address of seconds register
                I2C_write(0x10);       // 10 data as 10 second
                }

                void I2C_Ack()
                {
                    SDA = 0;
                    SCL = 1;
                    SCL = 0;
                    SDA = 1;

                void I2C_Stop()    // stop I2C
                {
                    SCL = 0;
                    SDA = 0;
                    SCL = 1;
                    SDA = 1;
                }

                void I2C_Start()
                {
                    SDA = 0;
                    SCL = 0;
                }

                I2C_read()
                {
                I2C_write(0xD1);      // address of the DS1307 )
                I2C_write(0x00);      // address of seconds register
                I2C_write(0x10);       // 10 data as 10 second
                }

                void I2C_Nak()
                {
                    SDA = 1;
                    SCL = 1;
                    SCL = 0;
                    SDA = 1;
                }

                void I2C_Stop()    // stop I2C
                {
                    SCL = 0;
                    SDA = 0;
                    SCL = 1;
                    SDA = 1;
                }

how to set alarm for led?
 

you can do it by setting the alarm mode for ds1307 you can read its data sheet you just get all the answers you are looking for.
 

you can do it by setting the alarm mode for ds1307 you can read its data sheet you just get all the answers you are looking for.
I saw both file that you posted in post #4. I did not see the any code for LED. thats why I tried to make myself

basic algorithm to understand
1. start i2c
2 write to ds1307
3 write address of ds1307
4 write address of register
5 write address of data ( second, minute, hours )
6 stop i2c
7 start i2c
8 read from ds1307
9 read address of ds1307
10 read address of register
11 read data (seconds minute )
12 stop i2c
13 led ..............?

how does alarm set for LED ?
 

what is the reference point for the counting or start of alarm? I mean when you know that we need to start the counter for 5sec ,3min,1 hour?you need to turn on the alarm mode then set the desired timing.

and just a question do you just have these three fixed alarm 5sec,3 minute,1 hour ? what is your led functionality? if its cyclic then why you need a rtc? not clear about your application.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top