So I had a PIC16F628A lying around and after searching the web I found a Brazilian site (I think?) with tons of interesting projects with microcontrolers. This project is based on one of them.
This is the schematic of the timer:
As I said, this project is based on an existing project, but actually my schematic is quite different and the code was almost completely rewritten. My programming abilities are little rusty, but I think the final result is quite good.
There are three buttons to operate the timer: "START/STOP", "MIN" and "SEC".
"START/STOP" is for starting and pausing the timer.
"MIN" is for adjusting the minutes. Minutes may go up to 99 and then starts again from 0.
"SEC" is for adjusting the seconds. Seconds goes up to 59 and then starts from 0.
"MIN" and "SEC" have repeat functionality.
Pressing MIN and SEC buttons simultaneously will reset the timer.
When the timer reach 00:00, the buzzer sounds 3 short and 1 long beeps and the LED lights up.
The buzzer is electromagnetic type.
After this any of these three buttons will reset the status and LED will switch off.
When timer is counting down - RB7 (pin 13) is high and when the timer is stopped - RB7 is low.
With this pin we can operate some external circuitry. In my case there will be connected a transistor which will switch on and off the UV exposure box.
Jumper J1 is for calibrating of the timer. When shorted, the timer enter in adjusting mode. With MIN and SEC buttons we can increase/decrease the value of an internal parameter thus slowing down or speeding up the timer. This value is stored in the EEPROM.
Pressing START/STOP button when in this mode will reset this parameter to its default value.
I tested the schematic on the breadboard and everything works as described.
The code is written and compiled with mikroC PRO for PIC. The options for the project are:
Oscillator: INTOSC oscillator: I/O function...
Oscillator frequency: 4.000000 MHz
Watchdog Timer: disabled
Power-up Timer: enabled
RA5/MCLR/VPP pin function: disabled
Brown-out detect: enabled
The .hex file was programmed in the microcontroller with my clone of PICkit2 using "PICkit 2 programmer" v.2.61
Link for downloading the archive with schematic, source .c file and .hex file : Timer
Use them on your own responsibility!
Some photos of the finished board:
And the schematic (same as above with added switching transistor and the buttons are different type):
How it works:
Update: June 12, 2014
Because, one of my reader ask me to publish the files of the actual device (second schematic), here the link for downloading them: Timer (PIC16F628A)(2).rar
Inside are the schematic, PCB, partlist, source file and .hex file.
Use them on your own responsibility!
Notes: the LCD display is connected via male - female pin headers. I prefer to solder the 16-pin female header on the PCB and the male pin header to the display board, but it can be done otherwise.
If there are used standard pin headers, the distance between display board and PCB is around 10mm, so there must be used low profile capacitors for C1 and C2 or they can be bend to fit under the display.
Update: February 25, 2016
There is update of the software - the changes are:
slightly different interface, the LED will light when the timer is counting. To enter in the adjustment mode it is needed only brief shorting of RA0 to the ground. pressing the START/STOP button will end the adjustment mode.
The link: Timer (PIC16F628A)
In the archive are only .C and .HEX files. The schematic and the PCB are the same and can be found in the previous update.
Update: May 1, 2016
One of my readers, Alnoor Ratansi send me a modified code for the timer with added ability to count up to 99 hours 59 min 59 sec. The software uses one additional button attached to pin 16 for adjusting hours. Thank you, Alnoor!
I haven't tried the code, so if anyone try the code, let me know if it work properly. Here you can download it: PicTimer
I found it interesting is the project for use at my home,
ReplyDeleteI like to know that sotware was used to be Compiled?
and thank you very much for sharing...!
It was compiled with mikroC pro, but I suppose the code can be modified easily for MPLAB and Microchip XC8 compiler.
DeleteIn mikroC pro there is a build-in library for LCD displays and I am not sure is there a similar library in MPLAB compilers.
I need to modify the code so that the red LED goes off when the counter reaches zero, rather than this on
ReplyDeleteand i do not know how to do.
please help me..! thanks
Greetings from Bolivia.
You can do this without modifying the code. Just connect a second LED in parallel with the output. Thats way the LED will light up when the output transistor is switched on. You must add a current limiting resistor in series with the LED - 1k or 1.8k will be fine.
DeleteThank you sir for this helpful and wonderful proJect
ReplyDeleteGracias lo Construi y funciona de maravilla
ReplyDeleteI would like change de messages to spanish lenguage, but when I compile, give me many errors. Can you help me?
ReplyDeleteThanks
Which program do you use to compile the code?
DeleteI have used .c code
DeleteThe code is designed and compiled with Mikroelektronika MicroC Pro for PIC.
DeleteYou should use the same or you have to change the code to be compatible with your program of choice.
A question what method you use to did your pcb?
ReplyDeleteIts a nice project man, thanks for sharing!
I use photoresist method. There is a ton of videos on Youtube with instructions. Here's one excellent: https://www.youtube.com/watch?v=p2kFazl-aEE
DeleteFor me,simulation in Proteus works perfectly but in real world, code never runs. What are configuration bits 0 and 1 in Pickit? Thank you!
ReplyDeleteI found the error! Pin 5 of LCD was disconnected from GND. Thank you for sharing this project.
ReplyDeleteHas anybody modified the code to add hours ?
ReplyDeleteI have modified the code to add hours. how do I upload the code
DeleteHi, you can send me the source code and the .HEX file to my email and I will upload them here. The email is shown at my "About" page.
DeleteDear sir,
ReplyDeleteshall we on this timer for 10 minutes and off repeating the process is available ?
You mean the timer to switch ON for 10 min, then switch OFF for 10 min and repeat this?
DeleteOf course it is possible if you find someone to write the code.
Bonjour,
DeleteOui, j'ai modifié le programme pour cela.
mickvarenne@free.fr
Is it possible to modify code so that last time period is stored in eeprom, for example I need to use the timer for multiple time periods of the same time eg 25 seconds and to save time re entering the 25 secs just depress the start button again.If a different time period is required hold one of the buttons in for a preset time to erase the last time period then enter new time period and then this new period is written to eeprom.
ReplyDeleteMany thanks.
Bonjour,
DeleteJ'ai modifié le programme pour garder en mémoire le dernier temps utilsé.
mickvarenne@free.fr pour le post
yes it will work on pic16f628
ReplyDeleteHello
ReplyDeleteModify the project by adding a button to decrease the minutes, also add a button to "reset" enabling the pin RA5 and applying in this "power on reset", I think that with this always reset the memory to the assigned value (977) Jumper and the function of pressing min-seg simultaneously was disabled, the problem is that when compil, sends many errors, as like I am new with C, could someone revise the code? Could also send the file in proteus for simulation, compile from micro c pro...... Regards
Hi, great job. Can you please modify the code to write to EEPROM the last selected time?
ReplyDeleteBonjour,
DeleteVous voulez dire la dernière valeur programmée?
Bonjour,
DeleteJ'ai modifié le programme, je peux vous le poster
mickvarenne@free.fr
Hello!
DeleteSee my blog "electroniquePIC.blogspot.fr"
Thank you
Greetings
Great job my friend ! Clean and beautiful project. Sadly, some download links are broken. Can you fix it ? Thanks.
ReplyDeleteThe 99 hours model doesn't have the downloand link avaible anymore.Please do something.Thank you
ReplyDeleteHello!
DeleteSee my blog "electroniquePIC.blogspot.fr"
Thank you
Greetings
Seems like none of the download links are working?What's wrong with them?
ReplyDeleteHello,
DeleteI can email you my version.
Hi,i would like very much hours version
DeleteMy email is barga_2003@yahoo.com and specify that you with this matter because i receive a lot of spams.Thanks
Hello,
ReplyDeleteI can email you my version.
Hello.
DeleteCan you e-mail to me your code (99 minutes)?
My e-mail: mr-isaac@bol.com.br.
Thanks.
Hi, Love the project. Could you please mail it for me to za.gene at gmail dot com
ReplyDeletehi
ReplyDeletegood works please send sch and hex file ubimes@gmail.com thanks
Hello i have the follow problem
ReplyDeleteafter programing the pic i See only finished on the display and 00:00
set time min and seconds is no problem
only start stop does noting i have check the 5v on pin18
and it is there also i have checked the button and it is ok
please have you any id what is wrong
Hi, Could you please repost your drop box links, In particular the code with ability to set/adjust hrs.
ReplyDeleteMany thanks Jesse
HI, Not sure if appropriate but I've changed this project to add hrs and backlight output and capability to to turn timer off if lamp(or other device) overheats. Pinout is different from posted diagram but info is in timer.c file. Thanks Jesse
ReplyDeletehttps://drive.google.com/file/d/15EEKHrzqEp3KjhXEJfiWoxHeulakHLkN/view?usp=sharing
if you can i need the first one or V1 source code if you can pls send me i can not get from the first one link yemane188@gmail.com
DeleteGreat job my friend ! Clean and beautiful project. Sadly, some download links are broken. Can you fix it ? i need source to learn...i'm newbie....Thanks.
ReplyDeletewant try this :
https://www.se.com/id/id/product-range-presentation/529-zelio-timer-relays/
The hex does not seem to work. I programmed using both winic800 and willem. programmer is a willem pcb50b
ReplyDeleteIn the schematic pin4 (RA5/~MCLR/VPP) is not connected so in the software used to burn the program you must set this pin to be IO pin and disable MCLR functionality or else the microcontroller will contiguously reset. Another solution is to solder a small 10k resistor between this pin and VDD (+5V).
DeletePaddy you can try my version that does work, https://drive.google.com/file/d/15EEKHrzqEp3KjhXEJfiWoxHeulakHLkN/view?usp=drivesdk
ReplyDeleteSeems that your links work. However, please add a diagram. Thanks.
DeleteHi,
DeleteIn the updates at the bottom of the article there are three links. the first of them have the schematic and the PCB.
This comment has been removed by the author.
DeleteХристо (August 14, 2020 at 2:28 AM) << Thank you for your response. I got your diagram and photos. May I get your C source and HEX file? I shall program with MikroC for PIC or MPLAB X. I want to use your timer for the Geyser (water heater). I need only 99 minutes and seconds. Prof. A.H.M. Asadul Huq, Dhaka University, Bangladesh.
DeleteYour timer project is very interesting. But currently your Timer related links are not working. Please give me pointer to a link, where i can get the timer source and Hex file. Thanks. Prof. A.H.M. Asadul Huq, Dhaka University, Bangladesh.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@Goahead << Seems that your 99 hour timer works now in my Proteus simulation (I had to change the push button active time to 500 ms in simulation). I want to start the timer once it gets power, automatically, without applying any trigger on the start button. Would you please tell me where should I modify the code or the circuit? Thanks in advance.
ReplyDeleteHi,
DeleteYou can add these lines just before the "while" loop:
start = 1;
LED = 0; // to light the LED
OUT = 1; // to switch the output high
seconds = 0;
minutes = 0;
hours = 0;
cnt = 0;
You can remove the duplicating lines from the beginning of the "main" procedure.
Hope this will work for you. This program was written very long time ago and it shows :(
I wouldn't write it like that now.
This comment has been removed by the author.
DeleteThis comment has been removed by the author.
DeleteSo the timer starts and then stops because the hours, minutes and seconds are 0. So in order to work as you want you should read from EEPROM these values before the main loop. Also you should store these values in the EEPROM after changing them.
DeleteNow in the EEPROM, the first byte is flag that there was written the OneSecond value. The next 2 bytes are the value of OneSecond. You can make the same arrangement for the time values - the forth byte to be flag that there was written "time" and next 3 bytes will hold the time values. And then you can read the flag and if the flag is 1 you read time values and start the timer. If the flag is different then you don't start the timer.
I don't have time to write the code, so you should do it yourself.
Thanks a lot for your idea. I shall try to implement your idea.
DeleteSir can I add hour with this program
ReplyDeleteOf course you can. There are unused pins, so you can add a button for the hours. And you should modify the code accordingly.
DeleteIf you want to change the code only to display the hour:min:sec you can do that too.
DeleteOkay. Sir thank you
DeleteThis program gives output on LCD like
DeleteOne second; 0972
RES - +
I don't know why it is come
This program gives output on LCD like
ReplyDeleteOne second; 0972
RES - +
I don't know why it is come
Your timer is in adjustment mode. It enter this mode when jumper J1 is connected. To run in normal mode you should disconnect the jumper (remove the jumper cap).
DeleteSir I use hour showing .hex file on my simulation . Successfull it runs but
ReplyDeleteHour is automatically increase where I add button please guide me sir
Sorry, I don't have time for this project.
DeleteThanks for the circuit. I've started doing the PCB layout. Just one question regarding the internal oscillator, if using an external crystal would I have to modify this line 'Oscillator: INTOSC oscillator: I/O function...'? Thanks, Dave
ReplyDeleteYes, you should modify this line, so the microcontroller can switch to external crystal clock source. If you put 4MHz crystal, the timer should work without additional changes, but if you use higher frequency crystal, then you have to recalculate some variables in the code.
DeleteDo you happen to have the gerbers for you pc board for your count down timer and are they available to us?
ReplyDeleteDoes this timer go down to 1 second? I gather that the lowest time is 59 seconds. I am looking for one that will go down to say 10 seconds (or 1 second) and also drive a relay to turn on/off another device.
ReplyDeleteYes, it can be set with 1 second accuracy. The lowest time is 1 second, not 59 seconds. And about the gerber files - the project was created with Eagle many, many ears ago and since then I move on to other platforms - KiCad and EasyEDA, so I don't know if I can unearth this old project and convert it and then produce gerber files. The PCB is very simple, so it is not difficult to create it from scratch.
DeleteThis comment has been removed by the author.
ReplyDeleteI asked for gerbers because that is usually what is offered and needed to make the boards. If you have the Eagle project files that is even better. Assuming you are willing to share them. Whether it is Eagle, KiCad, or EasyEda does not matter.
DeleteYou might consider sharing the gerbers on PCBWay in their "shared projects" area as I understand the author (you) get a royalty if someone orders the boards from them. Certainly not the same as selling boards yourself. One thing I found disappointing with their shared projects is that most do not link back to where build information may be found (this web page for your project).
Thank you.