По идее должен генерировать 100HZ.
- Код: Выделить всё • Развернуть
#define DS_HC 0x00
#define DS_SECONDS 0x01
#define DS_MINUTES 0x02
#define DS_HOURS 0x03
#define DS_DAY 0x04
#define DS_DATE 0x05
#define DS_MONTH 0x06
#define DS_YEAR 0x07
#define DS_ALARM_HC 0x08
#define DS_ALARM_SEC 0x09
#define DS_ALARM_MIN 0x0A
#define DS_ALARM_HOURS 0x0B
#define DS_ALARM_DY_DT 0x0C
#define DS_CONTROL 0x0D
#define DS_STATUS 0x0E
#define DS_TR_CH 0x0F
#define DS_ALARM_UP_TIME 0x05
#define DS_WRITE 0x80
#define DS_32kHz 0x18
#define DS_8kHz 0x10
#define DS_4kHz 0x08
#define DS_1Hz 0x00
void ds1390_write_alarm(void)
{
uint16_t i=0;
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_ALARM_HC + DS_WRITE); // select seconds register write address
SSP1Send(0xFF);
pin_high(DS_CS_PORT, DS_CS_PIN);
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_ALARM_SEC + DS_WRITE); // select seconds register write address
SSP1Send(0x80);
pin_high(DS_CS_PORT, DS_CS_PIN);
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_ALARM_MIN + DS_WRITE); // select seconds register write address
SSP1Send(0x80);
pin_high(DS_CS_PORT, DS_CS_PIN);
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_ALARM_HOURS + DS_WRITE); // select seconds register write address
SSP1Send(0x80);
pin_high(DS_CS_PORT, DS_CS_PIN);
for(i = 0; i < 100; i++);
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_ALARM_DY_DT + DS_WRITE); // select seconds register write address
SSP1Send(0x80);
pin_high(DS_CS_PORT, DS_CS_PIN);
for(i = 0; i < 100; i++);
}
void ds1390_init(void)
{
volatile unsigned char i;
pin_high(DS_CS_PORT, DS_CS_PIN);
pin_dir(DS_CS_PORT, DS_CS_PIN, OUTPUT);
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_CONTROL + DS_WRITE);
SSP1Send(0x1D); // enable osc, 32kHz sqw
//SSP1Send(DS_32kHz);
pin_high(DS_CS_PORT, DS_CS_PIN);
for(i = 0; i < 100; i++);
pin_low(DS_CS_PORT, DS_CS_PIN);
SSP1Send(DS_TR_CH + DS_WRITE);
SSP1Send(CHARGE_DISABLED);
pin_high(DS_CS_PORT, DS_CS_PIN);
ds1390_write_alarm();
}