PDA

View Full Version : Coundown timer on LCD



chrisshortys
- 11th October 2008, 20:31
Hay, this is my first post on these forums as im pritty new to the world of prgramming. Ive done a few simple things before like making a servo track a person in a room using PIR's and using pressure sensors etc but thats about it.

What i want to do now is to create a countdown timer on a LCD display. This is only part of a much larger project im attempting but its the first step :)

Basically i want a countdown timer which i will either have several different periods which you can select from or be able to enter a custom figure. I need the circuit to start with for now the press of a button (Later im going to be using a RF signal to activate the circuit but one step at a time!). It also needs to be able to pause and then resume from its last time and to switch a transitor to turn on a buzzer/sounder.

Ive looked around on the forums but icant seem to find any countdown timers, all ive found are 24 hour clock types and the oylipmics timer. So i realy need to know if its going to be easier to make a new code or if its easier to adapt one thats out there.

Looking at other posts most people seemed to be worried about the accuracy but this isnt too big an issue for me.

Im currently using a p16f876a chip and i have got the hang of displaying messages on both lines 1 and two but thats where i need some guidance :)

Any help would be much appreciatd!

Cheers Chris

Kamikaze47
- 11th October 2008, 21:40
My advice would be to use a 32.768kHz crystal connected to the timer 1 clock input. You can then use the timer 1 interrupt to decrement your countdown.

Archangel
- 11th October 2008, 22:49
Ya know, comming from a Law Enforcement Background, in a Post 911 world where we Americans are no longer immune to the rest of the world's problems, which admittedly our CIA likely caused, I feel really insecure about this forum when sombody jumps in from nowhere and asks about countdown timers and then mentions hooking them up to r/f links or cell phones. Even if you are The ALL AMERICAN BOY, anything like that posted here might be used by BAD PEOPLE, who might otherwise lack the skill to roll their own. That said I am sure BAD PEOPLE have people who have skills, nevertheless, I cannot in good concencience assist this endeavor, which by the way if you really did those projects listed above, you should be able to do without assistance.
JS

Charles Linquis
- 11th October 2008, 22:59
Use a crystal oscillator for the PIC (any frequency) and setup timer0 to timeout once a second (if that is your countdown rate). Use Mister E's PIC multi-calc to come up with the values. Sit in a tight loop and read INTCON.2 (Timer0 overflow bit). When that bit goes high, decrement your counter and display it on the LCD, then jump back to the tight loop. You can put a test for a button push or turn on a buzzer in that tight loop as well. It will be perfectly accurate as long as whatever you do in the tight loop takes less than 1 second.

Bruce
- 11th October 2008, 23:15
See this thread: http://www.picbasic.co.uk/forum/showthread.php?t=6957&highlight=O_FLOWS

WARNING: This code is designed (you can't see it, because it's hidden
internally) to immediately blow-up-in-your-face - if used for destructive
purposes.

earltyso
- 12th October 2008, 00:25
PIC MASTERS OF THE UNIVERSE,
At the end of a long week of broken electronics at work, this forum does provide much needed comic relief. Even my wife found this thread to be hilarious. Anyway I hope we have no nasty electronic/ firmware moles on this forum trying to hook up IED's or anything like that (not pointing fingers, postulating or anything) but seriously I do appreciate a few jokes mixed in with the great work on this forum.

On another note, I thought I would let this forum know that because of a recent PIC project I worked on in the oilfield (with help form this forum of course!) I have just recieved a large wampum promotion and will be uprooting my family to another state to begin work in a new design engineering position out of the "field". THanks for your help along the way Mr. E, Bruce, Skimask, and a whole bunch of others (sorry for not mentioning you all by name) that have helped me along the way to better learn how these Microcontrollers REALLY work. I will continue my search through the galaxy of electronics one PIC at a time, may the force be with!

muddy0409
- 12th October 2008, 01:11
Hmmm....This countdown timer just HAS to be for hollywood. Who else would want to have remaining time on a display. Is the mad bomber going to hang around to watch the damn thing? At least he will then know how much longer he has to wait to meet all those virgins he has been sucked into believing all about.
Oh dear, now I've probably offended someone..Tough, get over it.

Bruce
- 12th October 2008, 01:51
I will continue my search through the galaxy of electronics one PIC at a time, may the force be with!
Avoid planet 9 - they worship AVR, and have really ugly chicks.;o}

Archangel
- 12th October 2008, 08:38
I am glad I can amuse you all, it is good to laugh. You have not seen the inter agency bulletins I have seen. Amazing what can be done with common objects, a little creativity, and a serious hate. I stand by my statements. Be well, do no harm, enjoy this hobby. Keep in mind this forum is Global, from Beirut to Boston, to Baghdad to Bristol. It is wise to keep in mind, the things you say here are read Everywhere. Muddy, an LCD is a DEBUGGING tool not just a display for the movies, logic would dictate it's removal in a device used for evil purposes. Oh and yes, This could be used for model rockets, Camera control, stage drag races, lots of legitimate uses, I just feel it prudent to think about, the sinister possibilities, and choose not to advance them.

Kamikaze47
- 12th October 2008, 08:50
So, you are saying that we should not allow anyone to learn anything that could _possibly_ have a sinister application?

Acetronics2
- 12th October 2008, 09:51
So, you are saying that we should not allow anyone to learn anything that could _possibly_ have a sinister application?

Hi Kamikaze,

The application is what you do with the thing ... Even simulating fighting ( stupid video games ... or ... ) could lead 'light minded" guys to do it for real in the real life.

Hunting is just supposed to bring you food ... not adrenaline peaks.


Quite everything in this world could have a sinister application.

we just should not help if knowing the final use leads to violence ...

but how to always know ???

Alain

Kamikaze47
- 12th October 2008, 10:03
Quite everything in this world could have a sinister application.

This is exactly my point ^^^.

I'm saying that we shouldn't withhold helping someone learn something just because it could possibly be used for a sinister application, because that would apply to almost everything.

I agree that we should not help if we _know_ that the final use is for violence, but certainly in this case, there is no reason for us to assume that that is true.

I guess I just assume the best in people unless I see evidence to the contrary. I definitely believe in innocent until proven guilty.

chrisshortys
- 12th October 2008, 11:35
Hay there again, well after reading through the thread and at first feeling like i was accused of 911 myself :O and then reading peoples reactions it seems to of gone a bit far.
If i was said crazy crazy bomb bomb man i dont think i would bother with all this coding jargon. Maplins and RS and similar people (radio shack for you americans among us) proberly sell things that would be alot more reliable.

I'm an electronics apprentice and im trying to improve my background knowledge and find some intresting projects along the way. With any luck this will also be used towards my BTEC HNC at the end of next year.

Anyway back on topic and away from my dating agency advert^.

I'm going to give some of the proposed codes on here a try today and shall report back on findings :) although i have neverused the timer commands on pics ive always used loops adding 1 to b1 and checking values etc.

muddy0409
- 12th October 2008, 12:58
Yes, unless you need really accurate timer, then the "add 1 to b1 and check value" sort of thing would be good enough for almost any project. I personally have only had timer experience with Mel's olympic timer and modified it somewhat to count either up or down, depending on another pin's level. I still haven't really nutted out the timer function or the interrupt bizzo, 'cos I figure I can simply use the modified Mel's timer for whatever I want. I don't think I really need to know EXACTLY why/how a PIC does what it does, I just need to know that it WILL do what it does. I have picked the timer and interrupt sections out of the original and simply use them when I need to. See?, plagerism is alive and well!!

chrisshortys
- 12th October 2008, 13:04
See this thread: http://www.picbasic.co.uk/forum/showthread.php?t=6957&highlight=O_FLOWS

WARNING: This code is designed (you can't see it, because it's hidden
internally) to immediately blow-up-in-your-face - if used for destructive
purposes.

So far ive played around with this code. All seems good, the timer is in pure seonds atm so 120 secs etc but thats my next task to get it displaying in the correct format :)
Ive so far moddified bits of the above links coding but nothing major, i need to expand the protoype board im using as atm all i have is the chip, osc, LCD and a pull up resistor :p

chrisshortys
- 13th October 2008, 23:11
Yes, unless you need really accurate timer, then the "add 1 to b1 and check value" sort of thing would be good enough for almost any project. I personally have only had timer experience with Mel's olympic timer and modified it somewhat to count either up or down, depending on another pin's level. I still haven't really nutted out the timer function or the interrupt bizzo, 'cos I figure I can simply use the modified Mel's timer for whatever I want. I don't think I really need to know EXACTLY why/how a PIC does what it does, I just need to know that it WILL do what it does. I have picked the timer and interrupt sections out of the original and simply use them when I need to. See?, plagerism is alive and well!!

Okay well after trying to get my head around this coding for several hours im going to have to ask for some help!
I ended up using the very very well written but advanced coding in the oylimpic timer. First of all i set up the programe running normally and checked that all options and modes etc were working fully.

I then started looking into making the programe count down instead of up so i set a value in the LCD display in the minutes and seconds incase it needed. (I dont know if there is a registry file which this info also needs to be placed into?)

I then looked at the coding and found the commands to change the seconds to 60 and minutes etc and change them to what i believe to be right:

' Timer Interrupt Handler
' =======================
TickCount:
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...
Hundredths=Hundredths-1
' Increment 10mS Seconds Counter
If Hundredths<0 then
Hundredths=99
Seconds=Seconds-1
' Increment the Seconds
If Seconds<0 then
Seconds=59
Minutes=Minutes-1
' Increment the Minutes
If Minutes<0 then
Minutes=59
Hours=Hours-1
' Increment the Hours

If Hours>99 then
' Handle any Overflow
Hours=0
OverFlowError=1


Now im stuck. When i boot the programe up i get the time showing which ive set. I then start the timer and the tenth of seconds count down like i want them too! However it doesnt role over into the seconds.

Any help appreciated!

skimask
- 13th October 2008, 23:15
Now im stuck. When i boot the programe up i get the time showing which ive set. I then start the timer and the tenth of seconds count down like i want them too! However it doesnt role over into the seconds

Write a chunk of code that does this...
Take a byte variable, assign a value of ZERO to it, subtract one from that value and display it. For example:


temp var byte
temp = 0
temp = temp - 1
lcdout $fe , 1 , DEC temp

What's the result?
Is it what you expect?

chrisshortys
- 14th October 2008, 13:09
off the top of my head as im at work atm i would say that the result would remain zero as my old mentor told me that pbp doesnt do negative numbers?

Now thats where i believe the coding which reads:
If seconds <0 then
Seconds = 59 ?
Now that keeps the numbers rolling but i cannot see were the code which adjusts the next number sequence works.
I already have the hundredths of secs running downwards and everytime it reachs 0 it goes back to 99 i just dont see how to get it to affect the seconds.

Kamikaze47
- 14th October 2008, 13:12
as far as pbp is concerned, if temp is a byte variable and temp=0, then temp-1 = 255.