View previous topic :: View next topic |
Author |
Message |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
make i2c ds1307 realtime clock work |
Posted: Thu Nov 17, 2011 10:55 am |
|
|
Hi,
How to make DS1307 real time clock work...
How to set time and how to get time?
Any example program for ccs c-compiler?
I know you guys have done it before and I'm happy if
you tell me how ... for sure I can spend lot of time to do it myself.
( I'm electronic hobbyist ... no business)
I know those functions i2c I read from ccs c manual
but how to make them really work ?
brgds
-arto- |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 17, 2011 12:57 pm |
|
|
There is a ds1307 driver in the CCS Code Library forum. Use it.
There is a schematic of the ds1307 circuit in the ds1307 data sheet.
Use it. Make sure you have the 4.7K pullup resistors, and make sure
you have the 3v lithium battery on the Vbat pin. All of this is shown
in the schematic. |
|
 |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Tue Nov 29, 2011 10:17 am |
|
|
PCM programmer wrote: | There is a ds1307 driver in the CCS Code Library forum. Use it.
There is a schematic of the ds1307 circuit in the ds1307 data sheet.
Use it. Make sure you have the 4.7K pullup resistors, and make sure
you have the 3v lithium battery on the Vbat pin. All of this is shown
in the schematic. |
OK,
but in my hardware SCL = pin0 port C and SDA is pin1 portC
so I can't use those ready made I2C functions... |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9466 Location: Greensville,Ontario
|
|
Posted: Tue Nov 29, 2011 10:50 am |
|
|
Yes you can..
at the top of the driver ,just change the defines for which pins are used for the RTC clk and data. |
|
 |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Tue Nov 29, 2011 11:02 am |
|
|
temtronic wrote: | Yes you can..
at the top of the driver ,just change the defines for which pins are used for the RTC clk and data. |
please tell me exactly how?
those ready made I2C functions are for pins RC3 and RC4
( Iuse PIC18F452 IC)
thank's for your answer
sorry I'm beginner in getting RTCclock module to work ... |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9466 Location: Greensville,Ontario
|
|
Posted: Tue Nov 29, 2011 12:48 pm |
|
|
First copy the 1307 'driver' to my_1307.c
In 'my_1307.c'...
place the following code
#define RTC_SDA PIN_B1
#define RTC_SCL PIN_B2
#use i2c(master, sda=RTC_SDA, scl=RTC_SCL)
...before you see these lines...
BYTE bin2bcd(BYTE binary_value);
BYTE bcd2bin(BYTE bcd_value);
void ds1307_init(void)
{
..........
Just replace B1 and B2 with YOUR I2C pins !!
This will tell the compiler to use YOUR pins and create correct software I2C code.
Be sure to include 'my_1307.c' and remoce the original 1307 driver ! |
|
 |
|