RTC 1338 Nboard
Dependencies: mbed
main.cpp@0:ba08f73d8087, 2017-02-27 (annotated)
- Committer:
- gr66
- Date:
- Mon Feb 27 13:07:21 2017 +0000
- Revision:
- 0:ba08f73d8087
RTC 1338 Nboard
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gr66 | 0:ba08f73d8087 | 1 | #include "IHM.h" |
gr66 | 0:ba08f73d8087 | 2 | |
gr66 | 0:ba08f73d8087 | 3 | IHM ihm; //clase IHM |
gr66 | 0:ba08f73d8087 | 4 | I2C i2c(PB_7,PB_6); |
gr66 | 0:ba08f73d8087 | 5 | Serial pc(USBTX, USBRX); // I/O terminal PC |
gr66 | 0:ba08f73d8087 | 6 | int main() |
gr66 | 0:ba08f73d8087 | 7 | { |
gr66 | 0:ba08f73d8087 | 8 | ihm.LCD_clear(); |
gr66 | 0:ba08f73d8087 | 9 | ihm.LCD_gotoxy(0,1); |
gr66 | 0:ba08f73d8087 | 10 | ihm.LCD_printf("HTC DS 1338 "); |
gr66 | 0:ba08f73d8087 | 11 | wait(2); |
gr66 | 0:ba08f73d8087 | 12 | ihm.LCD_clear(); |
gr66 | 0:ba08f73d8087 | 13 | int address = 0xd0; |
gr66 | 0:ba08f73d8087 | 14 | // init RTC |
gr66 | 0:ba08f73d8087 | 15 | char data[8]= {0x00,0x30,0x59,0x23,0x1,0x31,0x12,0x16}; // reg de départ/ss/mm/hh/js/jj/mm/aa |
gr66 | 0:ba08f73d8087 | 16 | data[0]=0x00; |
gr66 | 0:ba08f73d8087 | 17 | i2c.write(address, data, 8,false); |
gr66 | 0:ba08f73d8087 | 18 | |
gr66 | 0:ba08f73d8087 | 19 | |
gr66 | 0:ba08f73d8087 | 20 | while(1) { |
gr66 | 0:ba08f73d8087 | 21 | // lecture RTC |
gr66 | 0:ba08f73d8087 | 22 | data[0]=0; |
gr66 | 0:ba08f73d8087 | 23 | wait(1); |
gr66 | 0:ba08f73d8087 | 24 | i2c.write(address, data, 1,false); |
gr66 | 0:ba08f73d8087 | 25 | i2c.read(address, data, 7,false); |
gr66 | 0:ba08f73d8087 | 26 | |
gr66 | 0:ba08f73d8087 | 27 | |
gr66 | 0:ba08f73d8087 | 28 | ihm.LCD_gotoxy(0,0); |
gr66 | 0:ba08f73d8087 | 29 | ihm.LCD_printf("%02x:%02x:%02x",data[2],data[1],data[0]); |
gr66 | 0:ba08f73d8087 | 30 | ihm.LCD_gotoxy(1,0); |
gr66 | 0:ba08f73d8087 | 31 | ihm.LCD_printf("%02x/%02x/%02x",data[4],data[5],data[6]); |
gr66 | 0:ba08f73d8087 | 32 | |
gr66 | 0:ba08f73d8087 | 33 | } |
gr66 | 0:ba08f73d8087 | 34 | } |