This project is a firmware application designed for the PIC16F877A microcontroller to function as a clock. It displays the time on 7 segment display. The firmware is developed using the MPLAB X IDE and the XC8 compiler.
- MPLAB X IDE
- XC8 Compiler
- PIC16F877A Microcontroller
- Open the project in MPLAB X IDE.
- Ensure the XC8 compiler is selected.
- Build the project to generate the
.hexor.coffile. - Alternatively, you can build the project using Visual Studio Code with the MPLAB extension. Set the project output file path, name, and extension using
Ctrl+Shift+Pand selecting "Edit Project Properties".
Necessary components that can't be changed:
- PIC16F877A microcontroller: To run the program.
- LM016L LCD display: To display output.
- Quartz Crystal and 2 1nF non-polarized capacitors.
Optional components depending on your circuit:
- Button: For setting the time.
- LED: To indicate the clock is running.
- OP-47 Op-Amp: For amplifying sensory input.
- RLY-SPNO Magnetic Relay: To provide stable 5V to CCP pin.
- Rheostat: To adjust op-amp potential according to sensor input.
- APDS-9002 Miniature Surface-mount Light Photo Sensor: For detecting ambient light.
- 5 Resistors.
After building the project, upload the generated .hex or .cof file to the PIC16F877A microcontroller using a suitable programmer. The file can be found in either of the following paths:
- In case of using MPLAB X IDE: dist\default\debug\PIC_Clock.X.debug.cof
- In case of using Visual Studio Code (if the file name was set as default): out\PIC_Clock\default.hex
-
Connect the microcontroller and the necessary components as per the circuit diagram, it is important to note:
- The first half of the variable
displayPortgives the BCD output of the digit. - The other half of
displayPortis for enabling the digits (from 1 to 4). - We can provide 25Hz 5V clock signal input, before turning PIC on, for external clock sync.
- The first half of the variable
-
Power on the system.
-
The LCD will display the current time.
-
Use the button to set the time if needed.
- Ensure all connections are secure and correct.
- Verify the microcontroller is programmed with the correct
.hexor.coffile. - Check the power supply to the microcontroller and other components.
- If the LCD does not display correctly, check the connections and contrast settings.