Professional Documents
Culture Documents
I2C-RTC With PIC16F877A
I2C-RTC With PIC16F877A
I2C-RTC With PIC16F877A
/aHR0cHM6Ly93d3cucGFudGVjaHNvbHV0aW9ucy5uZXQvaG93LXRvLWludGVyZmFjZS1pMmMtcnRjLXdpdGgtcGljMTZmODc3YS1waWMtYWR2YW5jZWQtZGV2ZWxvcG1lbnQtYm9hcmQ,/)
reate/) / Contact us (/contact-us/)
(https://www.pantechsolutions.net/)
0 My Bag
0 item(s) - 0.00
(https://www.pantechsolutions.n
Home (https://www.pantechsolutions.net/) / How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
(https://www.pantechsolutions.net/wishlist/index/add/product/1329/form_key/U3PKD3
(https://www.pantechsolutions.net/catalog/product_compare/add/product/1329/
(https://www.pantechsolutions.net/sendfriend/product/send/id/1329/)
(https://www.pantechsolutions.net/media/catalog/product/cache/1/image/600x600/9df78eab33525d08d6e5fb8d27136e95/i/n/interface_i2c-
rtc_with_pic16f877a_1_1.jpg)
(https://www.pantechsolutions.net/media/catalog/product/cache/1/image/600x600/9df78eab33525d08d6e5fb8d27136e95/i/n/interface_i2c-
rtc_with_pic16f877a_1_1.jpg)
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 1/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link between integrated circuits
(ICs).I2C is a synchronous protocol that allows a master device to initiate communication with a slave device. Data is
exchanged between these devices.
RTC (Real Time Clock)
The DS1307 Serial Real-Time Clock is a low-power; full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV
SRAM. Address and data are transferred serially via a 2-wire, bi-directional bus. The clock/calendar provides seconds,
minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with
fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with
AM/PM indicator.
Interfacing I2C - RTC
Fig. 1 shows how to interface the EEPROM with microcontroller through I2C. I2C is a Master-Slave protocol. I2C has a clock
pulse along with the data. The master device controls the clock line, SCL. This line dictates the timing of all transfers on the I2C
bus. No data will be transferred unless the clock is manipulated.
I2c bus supports many devices, each device is recognized by a unique address—whether it’s a micro-controller, LCD Driver,
memory or keyboard interface and can operate as transmitter or receiver based on the functioning of the device. The controller
designed controls the RTC ds1307 device through I2C protocol. The I2C Controller here acts as a master device and controls
RTC ds1307 which acts as a slave. The read operation is accomplished by sending a set of control signals including the address
and/or data bits. The control signals must be accompanied with proper clock signals.
DATA RC4
Source Code
The Interfacing I2C – RTC with PIC16F877A (https://www.pantechsolutions.net/microcontroller-boards/pic-advanced-
development-board) program is very simple and straight forward that read date & time in RTC by using I2C & the value is
displayed in serial port. A delay is occurring in every single data read from RTC. The delay depends on compiler how it
optimizes the loops as soon as you make changes in the options the delay changes.
C Program to interface I2C – RTC with PIC16F
***************************************************************************************
Title : Program to read date & time from I2C - RTC
****************************************************************************************
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 3/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
#include
__CONFIG(0x3f72);
//Calculation For 9600 Baudrate @10Mhz unsigned char sec,min,hour,day,date,month,year; unsigned char data[7]={0x45,0x59,0x71,0x04,0x05,0x10,0
int i;
void WaitMSSP();
void i2c_init(void);
void ds1307_init(void);
void serial_init(void);
void main()
int count=0;
DelayMs(20);
ds1307_init();
serial_init();
for(i=0;i<7;i++) DS1307Write(i,data[i]);
printf("\033[2J");
DelayMs(20);
while(1)
sec=DS1307Read(0);
//Display the Hours, Minutes, Seconds(hours is taken from 5 LSB bits printf("Date: %x / %x / %x \r",date,month,year);
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 4/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
void DS1307Write(unsigned char addr, unsigned char data)
SEN=1;
SSPBUF=LC01CTRLIN;
SSPBUF=addr;
SSPBUF=data;
PEN=1;
unsigned char x;
RSEN=1;
SSPBUF=LC01CTRLIN;
SSPBUF=addr;
//Write the location (memory address of Hour, minute, etc... WaitMSSP ();
RSEN=1;
SSPBUF=LC01CTRLOUT;
RCEN=1;
ACKDT=1;
x=SSPBUF;
void WaitMSSP()
while(!SSPIF);
void ds1307_init()
TRISC3=1;
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 5/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
SSPCON=0x28;
DS1307Write(0,0x00);
void serial_init()
{ TRISC6=1;
TXSTA=0x24;
// Enable Transmission
while(!TXIF);
int delay_cnst;
while(Ms>0)
Ms--;
To compile the above C code you need the Mplab software & Hi-Tech Compiler. They must be properly set up and a project
with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the
project.
In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating
HEX file. In debugging Mode, you want to check the port output without
PIC16F/18F Advanced Development Board (https://www.pantechsolutions.net/microcontroller-boards/pic-advanced-
development-board)
.
The PICKIT2 software is used to download the hex file into your
microcontroller IC PIC16F877A (https://www.pantechsolutions.net/microcontroller-boards/pic-advanced-development-
board)
through USB port.
Testing the I2C – RTC with PIC16F/18F
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 6/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
(http://my.yotpo.com/landing_page?
Powered by
redirect=https%3A%2F%2Fwww.yotpo.com%2Fpowered-
by-
yotpo%2F&utm_campaign=branding_link_reviews_widget_v2&utm_medium=widget&utm_source=pantechsolutions.net)
WRITE A REVIEW
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 7/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
More Information
Online Retail store for Trainer Kits,Lab equipment's,Electronic components,Sensors and open Return Policy (https://www.pantechsolutions.net/return-policy/)
source hardware.
Cancellation Order (https://www.pantechsolutions.net/cancellation-order/)
holidays (https://www.pantechsolutions.net/holidays/)
rohs (https://www.pantechsolutions.net/rohs/)
Dealership (https://www.pantechsolutions.net/dealership/)
Company Resources
Careers (https://www.pantechsolutions.net/careers/)
Events (https://www.pantechsolutions.net/events/)
Contact us (https://www.pantechsolutions.net/contact-us/)
8051 BOARDS : 8051 Development Board (https://www.pantechsolutions.net/microcontroller-boards/8051-development-board) | 8051 Trainer Kit (https://www.pantechsolutions.net/microcontroller-boards/8051-lab-trainer-kit) |
8051 Project Board (https://www.pantechsolutions.net/microcontroller-boards/8051-project-board)
PIC BOARDS : PIC16F877A Development Board (https://www.pantechsolutions.net/microcontroller-boards/pic-development-board) | PIC Advanced Development board (https://www.pantechsolutions.net/microcontroller-
boards/pic-advanced-development-board)
AVR BOARDS : AVR Development Board (https://www.pantechsolutions.net/microcontroller-boards/avr-development-board)
ARM BOARDS : LPC2148 Starter Kit (https://www.pantechsolutions.net/microcontroller-boards/arm7-trainer-kit)| ARM Development Board (https://www.pantechsolutions.net/microcontroller-boards/arm7-development-board) |
ARM9 Development Board (https://www.pantechsolutions.net/microcontroller-boards/arm-9-development-board)
PSOC BOARDS : PsOC Pioneer Kit (https://www.pantechsolutions.net/microcontroller-boards/psoc4-pioneer-kit) | PsOC Development Board (https://www.pantechsolutions.net/microcontroller-boards/psoc3-development-
board)
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 8/9
6/26/2019 How to Interface I2C-RTC with PIC16F877A PIC Advanced Development Board
FPGA BOARDS : FPGA Starter Kit (https://www.pantechsolutions.net/cpld-fpga-boards/spartan3an-fpga-project-kit) | FPGA Development Board (https://www.pantechsolutions.net/cpld-fpga-boards/spartan6-fpga-project-
board) | FPGA Universal Development Board (https://www.pantechsolutions.net/cpld-fpga-boards/fpga-universal-development-board)
DSP FLOATING POINT BOARDS : TMS320F2812 Development Board (https://www.pantechsolutions.net/dsp-dsc-boards/tms320f2812-dsp-development-board) | TMS320C6745 DSP Trainner Kit
(https://www.pantechsolutions.net/dsp-dsc-boards/tms320c6745-dsp-trainer-kit) | TMS320F28335 Development Board (https://www.pantechsolutions.net/dsp-dsc-boards/tms320f28335-dsp-development-board)
DSP FIXED POINT BOARDS : TMS320C5505 Development Board (https://www.pantechsolutions.net/dsp-dsc-boards/tms320c5505-dsp-development-board)
MSP430 BOARDS : MSP430 Launchpad (https://www.pantechsolutions.net/microcontroller-boards/msp430-launchpad) | MSP430 Development Board (https://www.pantechsolutions.net/microcontroller-boards/msp430-
development-board)
ARDUINO BOARDS : Arduino UNO | Arduino Basic Kit | Netduino | Arduino Due | Arduino ADK
RASPBERRY PI : Raspberry Pi 3| Rapserry Pi Accessories
WIRELESS COMMUNICATION BOARDS : GSM Modem (https://www.pantechsolutions.net/wireless-boards/sim900a-gsm-modem) | Zigbee Board (https://www.pantechsolutions.net/wireless-boards/zigbee-module-with-
base-board ) | WiFI Board (https://www.pantechsolutions.net/module-ic-s/wi-fi-proto-board) | Bluetooth Board (https://www.pantechsolutions.net/wireless-boards/hc-05-bluetooth-module-with-base-board)
WIRED COMMUNICATION BOARDS : SPI to Ethernet Interface (https://www.pantechsolutions.net/interface-cards/serial-ethernet-card)
WEARABLE TECHNOLOGY : Neurosky Mindwave Mobile : Brainwave Starter Kit (https://www.pantechsolutions.net/sensors/brainwave-starter-kit)
ACCESSORY BOARDS : GPS Board (https://www.pantechsolutions.net/wireless-boards/l80-gps-module-with-baseboard)
MODULES : GSM Modules (https://www.pantechsolutions.net/module-ic-s/m10-gsm-module) | GPS Modules (https://www.pantechsolutions.net/wireless-boards/gps-module) | Bluetooth Modules
(https://www.pantechsolutions.net/module-ic-s/hc-05-bluetooth-module) | WIFI Modues (https://www.pantechsolutions.net/wireless-boards/esp8266-wifi-module) | RF Modules (https://www.pantechsolutions.net/module-ic-s/rf-
module-433-mhz)
SENSORS : HM2007 Speech Recognition (https://www.pantechsolutions.net/sensors/hm2007-speech-recognition) | Gesture Recognition (https://www.pantechsolutions.net/sensors/gesture-recognition) | Brain Computer
Interface (https://www.pantechsolutions.net/sensors/brainsense) | Brainsense (https://www.pantechsolutions.net/sensors/brainsense)
PROGRAMMERS AND EMULATORS : Xilinx platform usb download cable (https://www.pantechsolutions.net/xilinx-platform-usb-download-cable)|FPGA JTAG Programmer (https://www.pantechsolutions.net/fpga-jtag-
programmer)
ROBOTICS : Line Follower Robot (https://www.pantechsolutions.net/robotics/line-follower-robot) | Gesture Controlled Robot (https://www.pantechsolutions.net/robotics/gesture-control-robot) | Robotic ARM
(https://www.pantechsolutions.net/robotics/owi-robot-arm) | Android Controlled Robot (https://www.pantechsolutions.net/robotics-projects/android-controlled-arduino-robot-car)
MOTOR DRIVES : PMSM Motor Drive (https://www.pantechsolutions.net/power-electronics-and-drives/pmsm-motor-control-using-dspic) | BLDC Motor Drive (https://www.pantechsolutions.net/power-electronics-and-
drives/bldc-motor-control-using-dspic) | Three Phase Induction Motor Drive (https://www.pantechsolutions.net/power-electronics-and-drives/three-phase-induction-motor-control-using-dspic) | SRM Motor Drive
(https://www.pantechsolutions.net/power-electronics-and-drives/switched-reluctance-motor-control-using-dspic) | Stepper Motor Drive (https://www.pantechsolutions.net/power-electronics-and-drives/stepper-motor-control-
using-dspic)
MOTORS : PMSM Motor (https://www.pantechsolutions.net/motors/pmsm-motor) | BLDC Motor (https://www.pantechsolutions.net/motors/bldc-motor) | Servo Motor (https://www.pantechsolutions.net/motors/ac-servo-motor) |
Three Phase Induction Motor (https://www.pantechsolutions.net/motors/three-phase-induction-motor) |
ECE MINI PROJECTS : 8051 Projects (https://www.pantechsolutions.net/8051-projects) | ARM Projects (https://www.pantechsolutions.net/arm7-projects) | FPGA Projects (https://www.pantechsolutions.net/fpga-projects) |
VLSI Projects (https://www.pantechsolutions.net/vlsi-projects) | VHDL Projects (https://www.pantechsolutions.net/vhdl-projects) |Robotics Projects (https://www.pantechsolutions.net/robotics-projects)
EEE MINI PROJECTS: Electrical Projects | Simulink Projects
DIP PROJECTS : Image Processing Projects (https://www.pantechsolutions.net/image-processing-projects) | Video Processing Projects (https://www.pantechsolutions.net/video-processing-projects)
https://www.pantechsolutions.net/how-to-interface-i2c-rtc-with-pic16f877a-pic-advanced-development-board 9/9