» Advertenties

Zo 5 Februari 2012, 12:45

C code -
  1. //*****************************************************************************
  2. //
  3. // File Name : ds1307.c
  4. // Title : Support for Maxim DS1307 real time clock
  5. // Author : Smoerijf.be
  6. // Target MCU : Atmel AVR Series
  7. //
  8. //*****************************************************************************
  9.  
  10. #include "i2c.h"
  11. #include "ds1307.h"
  12.  
  13. /**
  14.  *   @param     void
  15.  *   @return   void
  16.  **/
  17. void ds1307Init(void){
  18.   u08 buff[2];
  19.   // set control register
  20.   buff[0] = 0x00;
  21.   buff[1] = 0x00;
  22.   i2cSend(ds1307addr, 2, buff);
  23. }
  24.  
  25. /**
  26.  *   @param     *d     Pointer voor data opslag [3]
  27.  *   @return   void
  28.  **/
  29. void ds1307Read(u08* d){
  30.   *d = 0x00;
  31.   i2cSend(ds1307addr, 1, d);
  32.   i2cReceive(ds1307addr, 3, d);  
  33. }
  34.  
  35. /**
  36.  *   @param     p     seconds
  37.  *   @return   void
  38.  **/
  39. void ds1307SetSec(u08 p){
  40.   u08 buff[2];
  41.   buff[0] = 0x00;
  42.   buff[1] = ((p/10)<<4) | (p%10);
  43.   i2cSend(ds1307addr, 2, buff);
  44. }
  45.  
  46. /**
  47.  *   @param     p     minutes
  48.  *   @return   void
  49.  **/
  50. void ds1307SetMin(u08 p){
  51.   u08 buff[2];
  52.   buff[0] = 0x01;
  53.   buff[1] = ((p/10)<<4) | (p%10);
  54.   i2cSend(ds1307addr, 2, buff);
  55. }
  56.  
  57. /**
  58.  *   @param     p     hour
  59.  *   @return   void
  60.  **/
  61. void ds1307SetHour(u08 p){
  62.   u08 buff[2];
  63.   buff[0] = 0x02;
  64.   buff[1] = ((p/10)<<4) | (p%10);
  65.   i2cSend(ds1307addr, 2, buff);
  66. }
Laatste wijziging: Za 25 April 2009, 11:43