Monday 23 October 2017

Akses RTC dengan CVAVR DS1307

Source Code 

/*******************************************************
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
© Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 10/23/2017
Author  : 
Company :Add-Elektronik 
Comments:Add-Elektronik.blogspot.com 


Chip type               : ATmega32
Program type            : Application
AVR Core Clock frequency: 12.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*******************************************************/

#include <mega32.h>
#include <delay.h>
#include <stdio.h>
// I2C Bus functions
#include <i2c.h>

// DS1307 Real Time Clock functions
#include <ds1307.h>

// Alphanumeric LCD functions
#include <alcd.h>

unsigned char hour,min,sec;
unsigned char week_day,day,mont,year;

unsigned char temp [16];
unsigned char temp1 [16];
unsigned char buffer [16];

flash char * flash week_day_string[7]={"senin","selasa","rabu","kamis","jumat","sabtu","minggu"};

void week_day_tampil(unsigned char hari);

void main(void)
{
// Bit-Banged I2C Bus initialization
// I2C Port: PORTA
// I2C SDA bit: 1
// I2C SCL bit: 0
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();
//rtc_set_time(12,0,0);//set hour,min,sec
rtc_set_date(6,1,11,17);//set week_day,day,mont,year

// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: Off
// SQW/OUT pin state: 0
rtc_init(0,0,0);

// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf("RTC AVR 70");
delay_ms(3000);
lcd_clear();// untuk menghapus character LCD
while (1)
      {
       rtc_get_time(&hour,&min,&sec);// mengambil data waktu jam,menit,detik
       lcd_gotoxy(0,0);
       sprintf(temp,"%d:%d:%d",hour,min,sec); //%d menampilkan nilai decimal// sprintf = string
       lcd_puts(temp); // menampilkan memori "temp"
       
       rtc_get_date(&week_day,&day,&mont,&year); 
       
      lcd_gotoxy(7,1);
      sprintf(temp1,"%d:%d:%d",day,mont,2000+year);
      lcd_puts(temp1);  
       
       week_day_tampil(week_day);
      }
}


void week_day_tampil(unsigned char hari)
{
   lcd_gotoxy(0,1);
   sprintf(buffer,"%p", week_day_string[hari]);
   lcd_puts(buffer);
}

Refferensi 
[1] Code Vision AVR
[2] ATMEL Atmega32

No comments:

Post a Comment

AVR oprator (bahasa C)

1. Oprator Assignment Oprator assignment  adalah suatu oprator penugasan yang digunakan untuk memasukan nilai kedalam suatu variabel. dil...