[an error occurred while processing this directive]
Ответ: Держи.
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)
миниатюрный аудио-видеорекордер mAVR

Отправлено Bill 30 июля 2002 г. 14:13
В ответ на: Народ пришлите пож-та пример проги на Си для програмной работы с RTC DS1307 через пины порта отправлено СашенькаА 30 июля 2002 г. 12:46

#include "I2Cmaster.h" // I2C master defice header
#include "ds1307.h" // DS1307 definitions file

/* Global variable definitions */

volatile struct _td Time_Date;

//
// ** RTC_OpInit -- the fuction initiates RTC access
//
static void RTC_OpInit(void)
{
I2C_Addr = 0; // Access to all registers of RTC
I2C_Flags &= ~FLASH_BIT; // Update I2C flags
I2C_Slave = RTC_SLAVE; // Set slave device address
}
//
// ** ClockRd -- the routine to read Real-Time Clock device
//
void ClockRd(void)
{
char *_cp = &I2C_Buffer[RTC_Seconds];
RTC_OpInit(); // Initialize the RTC access operation
I2C_RdBlock(); // Read 8 bytes from the RTC
//
// Fill the RAM locations with data
//
Time_Date.Seconds = *_cp++; // Seconds value
Time_Date.Minutes = *_cp++; // Minutes value
Time_Date.Hours = *_cp++ & (HOUR_10|HOUR_1); // Hours value
Time_Date.Date = *++_cp & (DATE_10|DATE_1); // Date value
Time_Date.Month = *++_cp & (MONTH_10|MONTH_1); // Month value
Time_Date.Year = *++_cp & (YEAR_10|YEAR_1); // Year value
}
//
// ** ClockWr -- the routine to write data to Real-Time Clock device
//
void ClockWr(void)
{
RTC_OpInit(); // Initiate access operation
I2C_Buffer[RTC_Seconds] = 0; // Clear seconds
I2C_Buffer[RTC_Minutes] = Time_Date.Minutes; // Set the minutes
I2C_Buffer[RTC_Hours] = Time_Date.Hours; // Set the hour
I2C_Buffer[RTC_Day] = 0; //
I2C_Buffer[RTC_Date] = Time_Date.Date; // Set the date
I2C_Buffer[RTC_Month] = Time_Date.Month; // Set the month
I2C_Buffer[RTC_Year] = Time_Date.Year; // Set the year
I2C_Buffer[RTC_CTRL] = CTRL_SQWE_BIT | CTRL_1HZ; // Set the RTC control register
I2C_WrBlock(); // Write the data in buffer to RTC
}


Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru