{"id":21729982,"url":"https://github.com/asankasovis/pic_digital_clock","last_synced_at":"2025-03-20T23:21:54.030Z","repository":{"id":264346963,"uuid":"799564428","full_name":"asankaSovis/PIC_Digital_Clock","owner":"asankaSovis","description":"⏰ This project intended to create a digital clock using the PIC16F877a from Assembly. The design uses MAX6972 for driving a display and DS1302 to get the real-time clock. Three MAX6972s drive 12 5x7 dot-matrix displays. All code is written in Assembly to get an understanding of the PIC assembly.","archived":false,"fork":false,"pushed_at":"2024-11-23T15:09:53.000Z","size":537,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T20:08:23.773Z","etag":null,"topics":["assembly","assembly-language","digital-cl","ds1302","max6952","pic16f877a"],"latest_commit_sha":null,"homepage":"https://asankasovis.github.io/","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asankaSovis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-12T14:20:08.000Z","updated_at":"2024-11-23T15:09:57.000Z","dependencies_parsed_at":"2024-11-23T16:20:48.264Z","dependency_job_id":"e2206793-0e1e-46b8-81f2-709d522bb985","html_url":"https://github.com/asankaSovis/PIC_Digital_Clock","commit_stats":null,"previous_names":["asankasovis/pic_digital_clock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asankaSovis%2FPIC_Digital_Clock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asankaSovis%2FPIC_Digital_Clock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asankaSovis%2FPIC_Digital_Clock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asankaSovis%2FPIC_Digital_Clock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asankaSovis","download_url":"https://codeload.github.com/asankaSovis/PIC_Digital_Clock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244706661,"owners_count":20496604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","assembly-language","digital-cl","ds1302","max6952","pic16f877a"],"created_at":"2024-11-26T04:10:46.568Z","updated_at":"2025-03-20T23:21:54.005Z","avatar_url":"https://github.com/asankaSovis.png","language":"Assembly","funding_links":["https://www.paypal.com/donate/?hosted_button_id=4EWXTWQ9FUFLA"],"categories":[],"sub_categories":[],"readme":"# PIC Digital Clock ⏰\n\n![Poster](.sources/Poster.png)\n\n💸 Please consider donating on [PayPal](https://www.paypal.com/donate/?hosted_button_id=4EWXTWQ9FUFLA) to keep this project alive.\n\n---\n\nThis project intended to create a digital clock using the PIC16F877a from Assembly. The design uses MAX6972 for driving a display and DS1302 to get the real-time clock. Three MAX6972s drive 12 5x7 dot-matrix displays. All code is written in Assembly to get an understanding of the PIC assembly.\n\n## Prerequisites ⏰\n\nTo understand this project, somewhat knowledge of the PIC assembly is required. A good resource is the PIC16F877a [documentation](https://ww1.microchip.com/downloads/en/devicedoc/39582b.pdf). Somewhat knowledge of communication protocols is also required. This is crucial to understand how to communicate with the MAX6972 and DS1302. The specifics of the communication can be found in their respective documentation: [MAX6972](https://www.analog.com/media/en/technical-documentation/data-sheets/MAX6952.pdf) and [DS1302](https://www.analog.com/media/en/technical-documentation/data-sheets/DS1302.pdf).\n\nFor development, [VS Code](https://code.visualstudio.com/download) is used. ASM Code Lens extension is optional for syntax highlighting in VS Code for Assembly. [Proteus 8](https://www.labcenter.com/) is used for simulation. For compiling the code, [XC8](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8) is used which is the compiler set provided by PIC for all their chips.\n\n## Getting Started ⏰\nThe first step is to install all the prerequisites given above. This example is done in Ubuntu but any other operating system is compatible given you follow the correct install instructions provided by the vendors of these applications. Finally, clone or download this repository to your computer.\n\n## Repository Content ⏰\n\nThe repository contains the assembly code for the digital clock in the **digital_clock.S** file. The compiled hex code is in the **digital_clock.hex** file. All other files titled **digital_clock** are intermediate compiler files. The proteus simulation is in the **Digital_Clock.pdsprj** file.\n\n## Compiling the Code ⏰\n\nThe code is already compiled and the output hex file is titled **digital_clock.hex**. To recompile, first find where the PIC assembler is installed. In Ubuntu, this is in */opt/microchip/xc8/v2.46/pic-as/bin/pic-as*. For other operating systems, refer to the documentation. Once found, open a terminal within the repository and enter the below command to validate that the compiler exists.\n\n```\n/opt/microchip/xc8/v2.46/pic-as/bin/pic-as --version\n```\n\nThis should output something similar to below.\n\n```\nMPLAB XC8 PIC(R) Assembler V2.46\nBuild date: Jan  4 2024\nCopyright (C) 2024 Microchip Technology Inc.\n```\n\nTo compile, enter the command below.\n\n```\n/opt/microchip/xc8/v2.46/pic-as/bin/pic-as -mcpu=16F877A ./digital_clock.S\n```\n\nThis should output something similar to below.\n\n```\n::: advisory: (2100) using the C99 standard library with the selected device may result in larger code and data usage\n\nMemory Summary:\n    Program space        used    CEh (   206) of  2000h words   (  2.5%)\n    Data space           used     0h (     0) of   170h bytes   (  0.0%)\n    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)\n    Configuration bits   used     1h (     1) of     1h word    (100.0%)\n    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)\n```\n\n## Simulation ⏰\n\nOpen Proteus 8 and open the **Digital_Clock.pdsprj** in the **Proteus_Simulation** folder. Double-click on the PIC16F877a and in the *Edit Component* menu, click on the folder icon next to the *Program File:* option.\n\n![Program File: option](.sources/program_file.png)\n\nNavigate to the repository and choose the **digital_clock.hex** file and click **OK**. Click on the **Run the simulation** button in the bottom-left corner.\n\n![Run the simulation option](.sources/run_the_simulation.png)\n\nThis should run the simulation and show the program running in the PIC.\n\n![Simulation](.sources/simulation.png)\n\n## Hardware ⏰\n\nThe proteus simulation makes use of several hardware components.\n- PIC16F877a * 1\n- MAX6952 * 2\n- DS1302 * 1\n- 5x7 Blue Matrix Display * 12\n- Generic Diode * 2\n- 2N3904 Transistor * 1\n- Oscilloscope * 1\n\n![Components](.sources/components.png)\n\nThe PIC16F877a will be the microcontroller that controls the system. The three MAX6952 will drive the 5x7 matrix displays individually. These three MAX6952s are daisy-chained together for easy communication.\n\nThe DS1302 is also connected to the PIC16F877a. It goes through a simple voltage translator. This is because the PIC16F877a expects signals in 5V while the DS1302 communicates at 2V.\n\nThe four signals present: MAX6952 Chip Select, DS1302 Chip Select, Common Clock and Common Data are connected in that order to the Yellow, Blue, Red and Green leads of the oscillator.\n\n## Firmware ⏰\n\nThe program first initializes the MAX6952 chips. Next, it enters a loop where it first sends commands, receives data from the DS1302 and sends data to individual MAX6952s. Remember, each MAX6952 can handle 4 digits. However, since we have the chips daisy-chained, only one of each digit of the 3 chips can be controlled at once. Also, each parameter: hours, minutes, seconds, date, month and year is taken for two digits.\n\n### Data RX/TX\n\nIn the first stage, the date and seconds are received. The 2 digits of the date and 1st digit of the seconds are loaded to the first digits of each MAX6952 by bit-shifting.\n\nIn the second stage, the minutes are received. The 2 digits of the minutes and 2nd digit of the seconds are loaded to the second digits of each MAX6952 by bit-shifting.\n\nIn the third stage, the month and hour are received. The 2 digits of the month and 1st digit of the hour are loaded to the second digits of each MAX6952 by bit-shifting.\n\nIn the fourth stage, the year is received. The 2 digits of the year and 2nd digit of the hour are loaded to the third digits of each MAX6952 by bit-shifting.\n\n### DS1302 Communication\n\nIn DS1302, communication is done by first sending 8 bits with the command and then receiving the reply as 8 bits. This is the form below.\n\n![DS1302 Communication](.sources/ds1302_com.png)\n\nEach command/data will correspond to each parameter as given below.\n\n![DS1302 Commands](.sources/ds1302_chart.png)\n\nFor example, to read the seconds, command **0x81 (1000 0001)** is sent. In the next immediate clock cycle, 8 bits are read from the data line. These 8 bits are first filtered by **0x0F (0000 1111)** to get the lower digit and then nibble rotated, filtered by **0x07 (0000 0111)** to get the upper digit. This is true for hours, minutes, dates, months and years as well.\n\n\u003e Note that for higher 4 bits, (the upper digit) bit 7 is always discarded. This is to be safe from reading CH and 12/24 status as part of the number. However, this means that for years, after 2079, the value rolls back to 2000. This is a bug that exist in this code, however, it won't be affected until 2080.\n\nAdditionally, **0x30 (0011 0000)** is added to get the correct character code of the number for the MAX6972, which has the digits at an offset of 0x30. Refer to *table 14. Character Map* in the MAX6952 datasheet.\n\n### MAX6952 Communication\n\nCommunication to MAX6952 happens similarly. However, instead of sending 8 bits and receiving 8 bits, 16 * 3 bits are sent. Each 16 bits corresponds to an 8-bit command-data pair for each chip.\n\n![MAX6952 Communication](.sources/max6952_com.png)\n\nThis is because the three MAX6952s are daisy-chained together. All bits must shift across to the last chip's last digit one after the other.\n\n![MAX6952 Schematic](.sources/max6952_layout.png)\n\nThere are four commands we send to each MAX6952.\n- Configuration - 0x04\n- Intensity 10 - 0x01\n- Intensity 32 - 0x02\n- D0 address - 0x20\n- D1 address - 0x21\n- D2 address - 0x22\n- D3 address - 0x23\n\nThe configuration is to configure the display. The default 0f 0x81 is sent along with the command. Intensity 10 and 32 are defaulted to 0xFF for maximum brightness. Additionally, 0xFF is sent to all D0, D1, D2 and D3 to clear the displays. This concludes the initialization.\n\nFor each digit, the resulting digit from the DS1302 is sent with the command corresponding to the relevant address of the digit. Refer to *table 4. Register Address Map* in the MAX6952 datasheet.\n\n## License ⏰\n\n\u003e PIC Digital Clock is licensed under the GNU General Public License v3.0.\n\nPermissions of this strong copyleft license are conditioned on making available the complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights.\n\n### Permissions\n\n✔️ Commercial Use | Modification | Distribution | Patent Use | Private Use\n\n### Limitations\n\n❌ Liability | Warranty\n\n### Conditions\n\nℹ️ License and Copyright Notice | State Changes | Disclose Source | Same License\n\nRefer to the [License declaration](./LICENSE) for more details.\n\n`© 2024 Asanka Sovis`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasankasovis%2Fpic_digital_clock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasankasovis%2Fpic_digital_clock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasankasovis%2Fpic_digital_clock/lists"}