Академический Документы
Профессиональный Документы
Культура Документы
RTC1307
KONFIGURASI PIN
Untuk lebih jelas mengenai fungsi dan kegunaan dari IC ini terlebih dahulu akan dijelaskan
fungsi dari tiap-tiap pin pada IC keluarga DS1307, di mana diketahui bahwa IC DS1307 memiliki 8 pin
atau kaki, seperti pada Gambar 1.
1
P 2 . 0 V C C V C C
3 9 2 1 B T 1
3 8 P 0 . 0 / A P D 2 0. 0 / 2 A 2 8P 2 . 1
3 7 P 0 . 1 / A P D 2 1. 1 / 2 A 3 9P 2 . 2 B A T T E R D Y S 1 3 0 7
3 6 P 0 . 2 / AP D2 . 2 2 / A2 41 P0 2 . 3
P 0 . 3 / AP D2 . 3 3 / A2 51 P1
2
3 5 2 . 4
3 4 P 0 . 4 / AP D2 . 4 4 / A2 61 P2 2 . 5 P D 5
3 3 P 0 . 5 / AP D2 . 5 5 / A2 71 P3 2 . 6 P D 6
3 2 P 0 . 6 / AP D2 . 6 6 / A2 81 P4 2 . 7
H E A D E R 5 P 0 . 7 / AP D2 . 7 7 / A 1 5 R R T C 1
P 1 _ 01 1 0 R R T C 2
R S T P 1 _ 12 P 1 . 0 P 3 . 0 / R 1 1X D
1 P 1 _ 23 P 1 . 1 P 3 . 1 / T1 X2 D
2 P 1 . 2 P 3 . 2 / I 1N 3 T 0 V C C
P 1 _ 34
3 P 1 _ 45 P 1 . 3 P 3 . 3 / I 1N 4 T 1 V C C
4 G N D P 1 _ 56 P 1 . 4 P 3 . 4 /1 T 5 0
5 P 1 . 5 P 3 . 5 /1 T 6 1 J 1 6 .
P 1 _ 67
P 1 _ 78 P 1 . 6 P 3 . 6 / W1 7 R
J P 4 P 1 . 7 P 3 . 7 / R D 1
1 9 3 0 V C C 2
1 8 X T A L A 1 L E / P R2 9 O G 3
X T A L 2 P S E N 5 k P 2 . 5 4
X 1
3 1 R 9 5
V C C E A / V P P
9 P 2 . 4 6
R S T 7
1 2 M H z
8
C 3 A T 8 9 S 5 1 9
1 0 u 1 0
3 0 p 3 0 p R E S E T P 2 . 0 1 1
C 6 C 7 R S T P 2 . 1 1 2
P 2 . 2
C
1 3
R 2 D 3 P 2 . 3 1 4
4 K 7 1 5
1 N 4 0 0 2 1 6
C
A
D 3
H E A D E R 1 6
1 N 4 0 0 2
V C C
A
Gambar 2. Rangkaian RTC DS1307 mikrokontroller
void LCD_enable()
{
23
LCD_en = 0;
LCD_delay(1);
LCD_en = 1;
}
void LCD_init()
{
LCD_en = 1;
LCD_rs = 0;
LCD_command(0x33);
LCD_command(0x32);
LCD_command(0x28);
LCD_command(0x0C);
LCD_command(0x06);
LCD_command(0x01);
LCD_delay(256);
}
void I2C_delay(void)
{
unsigned char i;
for(i=0; i<I2C_DELAY; i++);
}
24
void I2C_clock(void)
{
I2C_delay();
SCL = 1;
I2C_delay();
SCL = 0;
}
void I2C_start(void)
{
if(SCL)
SCL = 0;
SDA = 1;
SCL = 1;
I2C_delay();
SDA = 0;
I2C_delay();
SCL = 0;
}
void I2C_stop(void)
{
if(SCL)
SCL = 0;
SDA = 0;
I2C_delay();
SCL = 1;
I2C_delay();
SDA = 1;
}
void I2C_ack()
{
SDA = 0;
I2C_delay();
I2C_clock();
SDA = 1;
}
void I2C_noack()
{
SDA = 1;
I2C_delay();
I2C_clock();
SCL = 1;
}
void DS1307_settime(unsigned char hh, unsigned char mm, unsigned char ss)
{
I2C_start();
I2C_write(DS1307_ID);
I2C_write(0x00);
I2C_write(ss);
I2C_write(mm);
I2C_write(hh);
I2C_stop();
}
26
void DS1307_setdate(unsigned char dd, unsigned char mm, unsigned char yy)
{
I2C_start();
I2C_write(DS1307_ID);
I2C_write(0x04);
I2C_write(dd);
I2C_write(mm);
I2C_write(yy);
I2C_stop();
}
Setelah membuat library RTC, maka sekarang saatnya Anda membuat program yang digunakan untuk
membaca waktu dari RTC dan ditampilkan di LCD..
Program sebagai berikut ini
//Program Bab 10.1 RTC DS1307
#include <at89x51.h>
#include "ds1307.h"
#include "lcd.h"
void PowerOn()
{
unsigned char inner, outer;
for (outer = 0x00; outer < 0x10; outer++)
{
for (inner = 0x00; inner < 0xFF; inner++);
}
LCD_init();
for (inner = 0; inner < 10; inner++)
LCD_delay(2);
}
LCD_putc(buf);
buf = value & 0x0F;
buf = buf | 0x30;
LCD_putc(buf);
}
PowerOn();
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
while(1)
{
/* Get Date & Time */
sec = DS1307_get(SEC);
min = DS1307_get(MIN);
hour = DS1307_get(HOUR);
date = DS1307_get(DATE);
month = DS1307_get(MONTH);
year = DS1307_get(YEAR);
LCD_command(0x86);
27
send2lcd(date);
LCD_putc('/');
send2lcd(month);
LCD_putc('/');
send2lcd(year);
LCD_command(0xC6);
send2lcd(min);
LCD_putc(':');
send2lcd(hour);
LCD_putc(':');
send2lcd(sec);
}
}