Build Real Time Clock using 8051and DS1307 RTC Module اصنع ساعة باستخدام


Notes On DS1307 RTC Module

Here we are using an RTC module with clock chip DS1307 based on I2C protocol (Two Wire Protocol). The module provides details such us second, minute, hour, day of week, day of month, month and year including correction for leap year. It can operate either in 12 Hour or in 24 Hour format. Current consumption of this module is nano ampere range. Even a 3V battery can power it for 10 years maintaining an accurate clock and without any external
power.


DS1307 has a memory area of 64 bytes of which the first 8 bytes are reserved as RTC register area and the remaining 56 bytes are allotted as general purpose RAM. The details about current, date and time is stored in its register area as Binary Coded Decimals(BCD). The module communicates with the microcontroller using a serial communication protocol called I2C. The I2C bus physically consists of 2 active wires. The wires, called SDA and SCL, are both bi-directional. SDA is the Serial Data line, and SCL is the Serial CLock line. Every device connected to the bus has its own unique device address, no matter whether it is an MCU or RTC module. Each of these chips can act as a receiver or transmitter, depending on the functionality.
DS1307 will act as slave in the communication network and controller can only access the slave by initiating a start condition along with a device address. Thereafter, we need to send the register number in order to access the value inside. The interface to the 8051 is simple I2C, with SDA and SCL pins connected to the any two pins of 8051. At the software side we are using a user defined library named “I2C” for I2C communication. This library allows you to communicate with I2C / TWI devices.
I hope you understood so far!  Lets get to the circuit diagram! So given below is the circuit 
diagram to connect RTC module to 8051
ملاحظات على DS1307 RTC Module
نحن هنا باستخدام RTC Module مع شريحة الساعة DS1307 على أساس البروتوكول I2C (بروتوكول سلكين). تزودنا بالتفاصيل الاتية مثل الثانية، دقيقة، ساعة،ايام الاسبوع، ايام الشهور والشهر والسنة بما في ذلك تصحيح السنة الكبيسة. وبامكان الساعة ان تعمل بنظام 12 ساعة أو 24 ساعة. استهلاك الطاقة في الدائرة في نطاق  النانو أمبير. اي ان بطارية 3V يمكن أن تشتغل لمدة 10 سنوات مع الحفاظ على ساعة دقيقة وبدون مصدر خارجي.
DS1307 يحتوي على مساحة ذاكرة 64 بايت . أول 8 بايت محجوزة كمنطقة تسجيل RTC و 56 بايت المتبقية مخصصة كذاكرة عشوائية للأغراض العامة. يتم تخزين التفاصيل الحالية كالتاريخ والوقت في مساحة من السجل ب النظام Binary Coded Decimals(BCD) . الوحدة تتصل مع متحكم باستخدام بروتوكول الاتصالات التسلسلي الذي يدعا I2C. ويتكون الناقل   I2C bus  من سلكين نشطين . الأسلاك تسمىSDA  وSCL ، وكليهما ثنائي الاتجاه. SDA هو خط البيانات التسلسلية، و SCL هو خط  التسلسلي لكلوك الساعة . كل جهاز متصل بالناقل لديه عنوان جهاز فريد من نوعه، بغض النظر عما إذا كان وحدة  MCU or RTC. كل من هذه الرقائق يمكن أن تكون بمثابة جهاز استقبال أو جهاز إرسال، اعتمادا على وظيفة.
سوف DS1307 بمثابة SLAVE اي الخادم في شبكة الاتصالات ويمكن الوصول فقط اليها عن طريق الشروع في عنوان الجهاز. بعد ذلك، نحن نحتاج إلى إرسال رقم السجل من أجل الوصول إلى القيمة في الداخل. واجهة إلى 8051 بسيطة I2C، مع SDA وSCL الاسنان او الارجل او الدبابيس كما تسمى االخاصة بالشريحة متصلة باثنين من دبابيس 8051. بخصو البرمجيات سوف نستخدم المكتبة المعروفة  باسم "I2C" للاتصالات I2C. هذه المكتبة تسمح لنا بالتواصل مع أجهزةI2C / TWI.

Circuit Diagram – RTC Interfacing with 8051



The Program/Code Explanation




الإبتساماتإخفاء