Blame view

Mbed_compiler/Read_RTC_I2C/main.cpp 772 Bytes
1b3a0906   mbutaye   Ajout des fichier...
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
  #include "mbed.h"
  #include "RTCDevice.h"
  
  I2C i2c(D14, D15);
  DigitalOut led1(LED1);
  Serial pc(SERIAL_TX, SERIAL_RX);
   
  char data[RTCDevice::length];
  
  int main()
  {
      pc.printf("starting..."); 
      RTCDevice rtcDevice(&pc, &i2c);
              
      if(rtcDevice.find()){              
          while(1) 
          {
              led1 = 1;
              
              rtcDevice.read(data);
              pc.printf("Time : %d%d:%d%d:%d%d\n", data[2] & 0x30 >> 4, data[2] & 0x0F, data[1] & 0x70 >> 4, data[1] & 0x0F, data[0] & 0x70 >> 4, data[0] & 0x0F); 
              pc.printf("Date : %d%d/%d%d/20%d%d\n", data[3] & 0x30 >> 4, data[3] & 0x0F, data[5] & 0x10 >> 4, data[5] & 0x0F, data[6] & 0xF0 >> 4, data[6] & 0x0F); 
  
              led1 = 0;
              wait(0.5);
          }
      }
  }