This is the first circuit I built with the PIC16F84. It can best be described as an egg timer with only the timekeeping code in place. It's got 4 pushbuttons, a character LCD and a buzzer. I started building this clock because I wanted to build my own Alarm clock. That project moved to another page, and this project will be made into a short period timer that automatically turns of a device (battery-charger, UV-case) after a preset time.
The clock is controlled with four pushbuttons. The firmware of this project is not completed, all it does at this time is offer a way to set current and alarm time, and drive a pin high when the two times match. However, this is a usable base to extend the project to function as the purpose above, as the timekeeping code and the user interface code are already there.
Current version info
With the 'func' button you can switch between current time and alarm time. With the Set button you can move the cursor to the right. When you press Set once, the cursor appears on hours-tens, when you press it again, the cursor moves to hours-units, followed by minutes-tens and minutes-units. When the cursor is on minutes-units and the set button is pressed, the cursor disappears and the clock is back in show-time-mode. The alarm time is set the same way. With the Up-Down buttons you can increase/decrease the number on the cursor position. The alarm (buzzer on A4) beeps the entire minute when the alarm time is equal to the real time.
On power-up you see this
when you press set, a cursor apears below the number you can set with the up/down buttons, to set the next digit, press set again.
when you press 'Func' the display shows the alarm time, and you can set the time with set/up/down. To return to the main screen, press Func. again.
You can see I used point-to-point wiring to build the prototype.
Technical side and Schematic
I used a LCD because I have a lot of them (multiplexed seven-segment LED displays would have worked too, but I only had 2 more left), and a LCD only requires 6 wires (I control it in 4-bit mode), which you can also share with the pushbuttons, so you'll only need another input pin for the switches. In the final design will use most significant bits of port B as databus for the LCD. (I leave RB6-RB7 unconnected now, for the ISP, which isn't necessary, even now).
The LCD is connected to the PIC with a 4 bits databus and two control signals (Enable and Register Select, PIC pin 6 and 11) The pushswitches S1, S2, S3, S4 are connected to the PIC with pull-up resistors, that way they are active-low. The PIC also has a crystal and capacitors connected as a heartbeat, and a pull-up resistor on the reset (MCLR) pin to keep it out of reset state (witch is 0V).
The clock uses Roman's zero error method to keep track of time. I used a part of Vasile's Cucu clock firmware (the interrupt timekeeping procedure) to start from. (thank you Vasile!)
I haven't done any long-period accuracy testing yet (only 10 minute tests without proper calibration, and it seemed to work fine), but according to Vasile it has 2 seconds error in a month when calibrated the right way.
Calibrating the clock involves measuring the crystal output oscillation with a good frequency meter, one with high input impedance (at least 1M/15pF), and setting the variables according to the measurement.