BASIC4MCU | AVR | 타이머 | 코드비젼 - RTC ( DS1307 )
페이지 정보
작성자 키트 작성일2017-08-29 09:31 조회5,957회 댓글0건본문
Maxim/Dallas Semiconductor DS1307 Real Time Clock Functions |
These functions are intended for easy interfacing between C programs and the DS1307 I2C bus real time clock (RTC).
The prototypes for these functions are placed in the file ds1307.h, located in the .\INC subdirectory. This file must be #include -ed before using the functions.
The I2C bus functions prototypes are automatically #include -ed with the ds1307.h.
Prior to #include -ing the ds1307.h file, you must declare which microcontroller port and port bits are used for communication with the DS1307 through the I2C bus.
Example:
/* the I2C bus is connected to ATmega8515 PORTB */
/* the SDA signal is bit 3 */
/* the SCL signal is bit 4 */
#asm
.equ __i2c_port=0x18
.equ __sda_bit=3
.equ __scl_bit=4
#endasm
/* now you can include the DS1307 Functions */
#include <ds1307.h>
The DS1307 Functions are:
void rtc_init(unsigned char rs, unsigned char sqwe, unsigned char out)
this function initializes the DS1307 chip.
Before calling this function the I2C bus must be initialized by calling the i2c_init function.
This is the first function that must be called prior to using the other DS1307 Functions.
The rs parameter specifies the value of the square wave output frequency on the SQW/OUT pin:
• 0 for 1Hz
• 1 for 4096Hz
• 2 for 8192Hz
• 3 for 32768Hz.
If the sqwe parameter is set to 1 then the square wave output on the SQW/OUT pin is enabled.
The out parameter specifies the logic level on the SQW/OUT pin when the square wave output is disabled (sqwe=0).
Refer to the DS1307 data sheet for more information.
void rtc_get_time(unsigned char *hour, unsigned char *min, unsigned char *sec)
this function returns the current time measured by the RTC.
The *hour, *min and *sec pointers must point to the variables that must receive the values of hours, minutes and seconds.
Example:
/* the I2C bus is connected to ATmega8515 PORTB */
/* the SDA signal is bit 3 */
/* the SCL signal is bit 4 */
#asm
.equ __i2c_port=0x18
.equ __sda_bit=3
.equ __scl_bit=4
#endasm
#include <ds1307.h>
void main(void) {
unsigned char h,m,s;
/* initialize the I2C bus */
i2c_init();
/* initialize the DS1307 RTC */
rtc_init(0,0,0);
/* read time from the DS1307 RTC */
rtc_get_time(&h,&m,&s);
/* ........ */
}
void rtc_set_time(unsigned char hour, unsigned char min, unsigned char sec)
this function sets the current time of the RTC.
The hour, min and sec parameters represent the values of hour, minutes and seconds.
void rtc_get_date(unsigned char *date, unsigned char *month, unsigned char *year)
this function returns the current date measured by the RTC.
The *date, *month and *year pointers must point to the variables that must receive the values of date, month and year.
void rtc_set_date(unsigned char date, unsigned char month, unsigned char year)
this function sets the current date of the RTC.
http://iranmicro.ir/Online/Help/CodeVision/index.html?ds1621functions.htm
코드비젼 CodeVisionAVR Online Help 입니다.
위 소스를 정리 하면..
// Example:
#include <mega8515.h>
#asm
.equ __i2c_port=0x18 ; ATmega8515 PORTB
.equ __sda_bit=3 ; the SDA signal is bit 3
.equ __scl_bit=4 ; the SCL signal is bit 4
#endasm
#include <ds1307.h>
void main(void) {
unsigned char h,m,s;
unsigned char year,mon,date;
i2c_init(); // initialize the I2C bus
rtc_init(0,0,0); // initialize the DS1307 RTC
rtc_set_time(12,0,0);
rtc_set_date(1,1,12);
while(1){
rtc_get_time(&h,&m,&s); // read time from the DS1307 RTC
rtc_get_date(&date, &mon, &year); // read day from the DS1307 RTC
}
}
//128이라면
.equ __i2c_port=0x18 ; ATmega8515 PORTB
//이 부분만 신경쓰면 됩니다.
1302와 크게 다른 것 같지 않군요
쓰기 함수는 <ds1307.h>를 보면 됩니다.
댓글 0
조회수 5,957등록된 댓글이 없습니다.