The timer described here was originally dreamed up to allow the heating to be forced on for a programmable period without requiring re-adjustment of the 24hr/7day time clock. Although some clocks have a 1 hour boost facility, this device was made to be programmable from 10 mins to 10hrs, and to be able to be mounted in a living room, while the main timer is in the boiler room. However, the circuit is really presented as a starting point example for driving a 7-segment display and a relay to switch the mains. The software makes use of interrupt programming to keep the time based on the 50Hz mains. Readers in non 50Hz (less civilised?) countries will be pleased to read that modification for other frequencies is a trivial matter!
As with the programmer, this project requires reasonable soldering abilities, patience and maybe a couple of weekends to build and test. A meter is likely to be essential, access to a 'scope is extremely useful if it does not work, but failing that a couple of diagnostic LEDs can be made to reveal most of the problems you could encounter, if you follow the recipe verbatim. The latest (2004) version of the code has options for 60Hz countries.
The C sources, hex files and programmer code all together counter.zip
Introduction and Software Description
Timerflowchart.png the main software loop flowchart (printable version looks poor on -screen)
Timerflowchart2.png the interruopt routine flowchart (printable version looks poor on -screen))
Assembly instructions (long…)
Circuit description:-
Reading the buttons
By using internal pull-up resistors on the 'B' port of the PIC all that is needed is a simple push to make contact to ground for the UP and Down buttons. A spare pin on the B port is used to activate a fast counting test mode (this saves waiting hours to check the correct carry sequence from hours to minutes). This shown is in more detail in the software description.
Driving the7 segment display
The 7 segment display is a high brightness part from Kingbright.
The 16F872 data sheet from Arizona Microchip.
Useful files
The complier and instructions are here (note these are not mine, the free issue from B Knudsen Data -please note their copyright terms - not for commercial use.) complier.zip
Unzipping all the C code files to be assembled into a directory with the cc5 compiler simplifies the operation. By running the batch file compile.bat the compiler is invoked with the correct arguments.
Say you unzipped this archive into a directory called "PIC" on the C drive. Make sure that these files are present
counter.c, (the code proper to be compiled)
16f872.h (specific constants for the chip we are using - port adresses and bit patterns etc) so leave these alone!
compile.bat (a text file whicjh invokes the compiler 'cc5xfree.exe' with the right options)
cc5x.exe or cc5xfree.exe (the compiler from B Knudsen data)
All of these except the exe file are plain ascii files, and can be viewed / changed with DOS edit or windows wordpad, or any other plain text editor. But, if you are not confident with C, save the good copies somewhere else before making changes to the code. Its fairly easy to make version that fails to compile!!!
In a DOS session (sometimes called command prompt)
At the prompt type cd \pic (this sets the current directory to c:\pic)
Assuming you have dos set up normally the prompt will now be
C:\PIC>
To compile the file counter.c type "compile counter.c" and press return.
Assuming that counter.c is in the directory, and all is well you will be rewarded by the creation of the counter.hex file for the programmer , and the counter.asm, and counter.lst files which are not needed, but may be read with the PIC data sheet to show you which low level instructions are being fed to the PIC, and which parts of the Hex file they relate to.
The hex file can now be programmed into the PIC chip itself either using a commercial programmer, or if you have built my programmer, just use picprog.exe to transfer the hex to the chip…..
Assuming picprog.exe is in your c:\pic directory too all you need to do is
Type "picprog counter.hex" and pres return.
When prompted switch on the programmer, and the chip should be programmed successfully without further effort..
To use the design as is, there is no need to waste time compiling, as I have provided both C code and ready assembled HEX. If you wish to edit the C code but have trouble getting the B Knudsen Data compiler to run you can compare the hex files made by your system with these ready prepared ones as a reference. Hex files may be viewed with a text editor. But, as the first part of each line is an address and line length information, and the last entry on each line is a check sum, and some quantities are in byte reversed, order hand editing for all but the simplest one byte change is tedious. Good information on the "intel hex" file format is available from the web and I wont discuss it further here.
General notes
The power supplies must be AC -the 50HZ is an essential part of the timing. Any battery driven version of this would have to use a crystal instead of the RC and set the interrupt counter to divide town from this.
I built this into a standard UK double socket back box -assembly pictures are in the (rather long) word document.assembly.doc
The front panel was printed on a colour printer and laminated up in a hot melt laminator. By cutting the display hole in the paper before lamination, a clear window of plastic laminate is formed that protects the display. This also covers the countersunk screw heads that old the PCB in place on the blanking plate which is the front cover.
If you want my front panel, it’s a power point document.front.ppt (the second copy is a drilling template, glue to the cover plate and drill out the holes for the switches and display to poke through.)
Disclaimer :-
I'd welcome comments on this design, although you must realise its not possible for me to guarantee any 'get you going' service -Its my hobby, not my job! I can respond to Emails, usually within a few days, but otherwise-you are on your own I'm afraid. Good luck.
Emails to pic@pjnet.freeserve.co.uk
This part of the website is very much under construction -I know it's not all there yet, but please bear with me -it is coming
Web Search terms: hobby homebrew, pic, picprog, timer, counter, 7 segment,display driver, PIC interrupts, DIY programmer, G7VZY, 16F872, PIC16F872, Mike P-J, Page-Jones, Michael Page-Jones, P-Jtronics,