Difference between revisions of "PIC18F4520 RTC(DS1307) Interface"
(Created page with "Category:Starter PIC18F4520 In this tutorial we'll see, how to interface RTC with PIC18F4520 Starter board. For this we will be using [https://www.exploreembedded.com/pro...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 20: | Line 20: | ||
=Demo= | =Demo= | ||
− | [[file:00Interface_RTC_with_Atmega128.gif]] | + | [[file:00Interface_RTC_with_Atmega128.gif|x300px]] |
= Downloads= | = Downloads= |
Latest revision as of 18:52, 25 August 2016
In this tutorial we'll see, how to interface RTC with PIC18F4520 Starter board. For this we will be using RTC breakout which has DS1307 RTC on it. For basics of RTC just have a look at our Real Time Clock(DS1307) with AVR tutorial.
Contents
[hide]Prerequisites
Please check this tutorial for detailed explanation on DS1307 RTC.
Hookup
Starter PIC board has facility to connect LCD, we will be using 16x2 LCD for displaying the data and time.
The DS1307 RTC module will be connected I2C(SCL-RC.3,SDA-RC.4) pins of Starter board as shown in below image.
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "rtc.h" | |
#include "lcd.h" | |
int main() | |
{ | |
rtc_t rtc; | |
/*Connect RS->PB0, RW->PB1, EN->PB2 and data bus to PORTB.4 to PORTB.7*/ | |
LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7); | |
LCD_Init(2,16); | |
/*Connect SCL->PC3, SDA->PC4*/ | |
RTC_Init(); | |
rtc.hour = 0x10; // 10:40:20 am | |
rtc.min = 0x40; | |
rtc.sec = 0x00; | |
rtc.date = 0x01; //1st Jan 2016 | |
rtc.month = 0x01; | |
rtc.year = 0x16; | |
rtc.weekDay = 5; // Friday: 5th day of week considering monday as first day. | |
/*##### Set the time and Date only once. Once the Time and Date is set, comment these lines | |
and reflash the code. Else the time will be set every time the controller is reset*/ | |
RTC_SetDateTime(&rtc); // 10:40:20 am, 1st Jan 2016 | |
/* Display the Time and Date continuously */ | |
while(1) | |
{ | |
RTC_GetDateTime(&rtc); | |
LCD_GoToLine(0); | |
LCD_Printf("time:%2x:%2x:%2x \nDate:%2x/%2x/%2x",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year); | |
} | |
return (0); | |
} |
Demo
Downloads
Download the complete project folder from the below link:
Have a opinion, suggestion , question or feedback about the article let it out here!