#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <inttypes.h>
#include "util.h"
#include "rtc.h"
Defines | |
#define | DDRRTCSEL DDRB |
#define | PORTRTCSEL PORTB |
#define | DDRSPI DDRB |
#define | PORTSPI PORTB |
#define | RTCSEL 6 |
#define | MISO 4 |
#define | MOSI 3 |
#define | SCK 5 |
Functions | |
void | rtc_init () |
void | rtc_send (uint8_t b) |
void | rtc_over () |
uint8_t | rtc_rw (uint8_t addr, int8_t value) |
uint16_t | rtc_gettime (uint8_t ss) |
void | rtc_dump () |
#define DDRRTCSEL DDRB |
#define DDRSPI DDRB |
#define MISO 4 |
#define MOSI 3 |
#define PORTRTCSEL PORTB |
#define PORTSPI PORTB |
#define RTCSEL 6 |
#define SCK 5 |
void rtc_dump | ( | ) |
uint16_t rtc_gettime | ( | uint8_t | ss | ) |
00053 { 00054 uint16_t time = 0; 00055 00056 // address 0 for seconds, minutes; minutes, hours otherwise 00057 rtc_send(ss ? 0 : 1); 00058 00059 // data 1 00060 rtc_send(0); 00061 time = SPDR; 00062 00063 // data 2 00064 rtc_send(0); 00065 while (!(SPSR & _BV(SPIF))); 00066 time |= SPDR<<8; 00067 00068 rtc_over(); 00069 00070 return time; 00071 }
void rtc_init | ( | ) |
void rtc_over | ( | ) |
00042 { 00043 PORTRTCSEL |= _BV(RTCSEL); 00044 }
uint8_t rtc_rw | ( | uint8_t | addr, | |
int8_t | value | |||
) |
void rtc_send | ( | uint8_t | b | ) |
00036 { 00037 PORTRTCSEL &= ~_BV(RTCSEL); 00038 SPDR = b; 00039 spi_wait(); 00040 }