PDA

View Full Version : dual 7-segment countdown timer code



dr.ragh
- 27th April 2007, 12:55
Hello guys iam a Dentist but have been into electronics as a hobby from the last 12 years

well i am not that good in coding (microcontrollers) so i need help from you Guys and the Admin as i couldnt find any thing on the net

I am building a Dual 7 - segment 20 and 40 seconds countdown timer for the dental composite curing light. here are the features that i needed

1. Dual 7- segment display
2. Countdown timer with 20 and 40 seconds delays
3. Timer should turn on \ off with the same button
4. Two different buttons for 20secs and 40 secs
5. Display should start at 20 then end at 0 same goes for 40 secs
6. Small beep when a button is pressed then after the countdown has elapsed a long beep should be heard
7. one output should go high when the timer statrs and should go low when the countdown ends ( this will drive a 5w blue led)
8. when the switch is pressed while countdown the timer should turnoff
9. when the timer is not running it should go in to sleepmode and blink an LED every 10 secs

Guys i have written a code for the above project but could only achieve the
following

1. switch is pressed then 5w led turns on and after 20secs turns off ( same goes for 40 secs)
2. beeper sounds when a button is pressed and then produces a long beep after the countdown is over

so i need help from the big brains out there to help me finish the project

dr.ragh
- 27th April 2007, 13:23
'************************************************* ***************
'* Name : Dr.RAGHUS COMPOSITE TIMER.BAS
'* Author : [DR.RAGHU]
'* Notice : Copyright (APRIL) 2007
'* : All Rights Reserved
'* Date : 4/24/2007
'* Version : 1.0
'* :
'************************************************* ***************

'FOR SW1
'LED (5W LED WILL TURN ON WITH SW1 AND BEEPER WILL BEEP ON FOR 1/3RD SEC
'LED WILL TURN OFF AFTER 20 SECS THEN BUZZER WILL BEEP for 1 SEC
'FOR SW2
'SAME AS ABOVE BUT CYCLE IS FOR 40 SECS AND BUZZER BEEPS 1 SEC AT THE END OF THE CYCLE
'INT XTL, NO OTHER CONFIGERATIONS

Set_Defaults PROTON_4 ' PROTON dev board using a 4MHz crystal
Device 16F628a

Dim BUF1 as Byte ' Working buffer 1 for button command
Dim BUF2 as Byte ' Working buffer 2 for button command
Symbol SW1 = PORTB.4
Symbol SW2 = PORTB.5

Symbol BUZ = PORTa.2 'BUZ = BUZZZER
Symbol LED = PORTA.1 'LED = 5W LUXEON LED

Delayms 500 ' Wait for PICmicro to stabilise
ALL_DIGITAL = True ' Set ports to digital mode
Clear ' Clear buffers
Low PORTa ' ALL LEDs off
TRISB = $F0 ' Set PORTB 0-3 outputs, 4-7 inputs
PORTB_PULLUPS = ON ' Enable PORTB pull-ups


Chk1: Delayms 25

Button SW1,0,40,5,BUF1,0,Chk2' Check Button 1 (Skip to 2 if Not Pressed)

TOGGLE BUZ 'TOGGLE BUZ
TOGGLE LED 'TOGGLE LED

DELAYMS 500 'DELAY 1/2 SEC
LOW BUZ 'TURNOFF BUZ & LED WILL STILL BE ON
DELAYMS 20000 'DELAY 20 SECS FOR LED

TOGGLE BUZ 'TURN ON BUZ AGAIN LED WILL STILL BE ON

DELAYMS 1000 'DELAY FOR 1SEC
LOW LED 'TURNOFF LED
LOW BUZ 'TURNOFF BUZ

Delayms 25


Chk2:

Button SW2,0,40,5,BUF2,0,CHK1 ' Check Button 2 (Skip to 1 if Not Pressed)

TOGGLE BUZ 'TOGGLE BUZ
TOGGLE LED 'TOGGLW LED

DELAYMS 500 'DELAY 1/2 SEC
LOW BUZ 'TURNOFF BUZ & LED WILL STILL BE ON
DELAYMS 40000 'DELAY 20 SECS FOR LED

TOGGLE BUZ 'TURN ON BUZ AGAIN & LED WILL STILL BE ON

DELAYMS 1000 'DELAY FOR 1 SEC
LOW BUZ 'TURNOFF BUZ
LOW LED 'TURNOFF LED2

Delayms 25

Goto Chk1 ' Do it forever

malc-c
- 27th April 2007, 13:47
Its not much help, but you're posting in the wrong forum. These forums are for MeLabs PicBasic Pro, not Proton PicBasic.

Try posting your request over at http://www.picbasic.org/forum

You might get a quicker responce

T.Jackson
- 27th April 2007, 14:10
Post a schematic and I'll give you hand if I can.

dr.ragh
- 27th April 2007, 16:24
well this is just an idea of the schematic, i have to add transistors to drive led display and for buzzer and 5w led

T.Jackson
- 28th April 2007, 02:47
well this is just an idea of the schematic, i have to add transistors to drive led display and for buzzer and 5w led

I see many similarities with Proton Vs PBP, and I also see many differences. I've personally never used Proton.

Give the Proton forum a go, if you don't have any luck there, perhaps I could give you some PBP code. This of course will need to be converted across to Proton.

Also I might add that sometimes the internal pull ups can be a bit inadequate. I
base this statement mostly on the published material that I've read. I never use internal pull ups.

skimask
- 28th April 2007, 04:33
well this is just an idea of the schematic, i have to add transistors to drive led display and for buzzer and 5w led

Ya know, a cheap, surplus 8x2 LCD from ebay (or something) would probably cost the same as the 7 segment LCD, less wiring to set up, a LOT easier to code, and you can get them in a relatively decent size (as in big and easy to see) and backlit. Plus, you'd have extra character space to put more characters on there, and with the extra pins not used up by the 7 segment display, you could add more features in the future. Not to mention not having to add the extra transistors+bias resistors (or mosfets).
Just a thought...

paul borgmeier
- 29th April 2007, 06:16
Also I might add that sometimes the internal pull ups can be a bit inadequate. I
base this statement mostly on the published material that I've read. I never use internal pull ups.

interesting ... I love internal pullups and have NEVER had a problem when using them in "clean" environments (e.g., low current / battery powered). If one has a noisy environment (e.g., autos), then of course they may not be strong enough to keep the pins high, BUT neither would an equivalent 25k-100k resistor. In this latter case, the failure of the weak pullups is not the fault of the internal weak pullups but of the designer. Internal pullups work as advertised and I have never seen published material that suggest otherwise. My suggestion is to understand them, use them when they are appropriate, and skip them when they are not.

T.Jackson
- 29th April 2007, 07:46
Most of the PIC-based projects in the Silicon Chip magazine don't make usage
of internal pull ups. I've spent the last 10yrs following the magazine very, very closely. I've spent the last 5yrs contributing projects to them on a part time basis. Never tried using internal pull ups - possibly because of this fact. (By the way, I think they're much higher than 25K)

skimask
- 29th April 2007, 08:17
From a few of the datasheets, parameter D070...

PortB weak pull up current
50uA minimum - 400uA maximum @ 5v, pin @ Vss. A few of the datasheets say 250uA typical

This would suggest anywhere from 12.5K to 100K of resistance per PortB pin, with a 20K typical. A bit of a wide range. Fine for a switch matrix, I'm thinking a bit sloppy for anything else...

mister_e
- 29th April 2007, 15:43
i've said that hundreds of time on many forums... they're good for lazy prototyping and/or in a well shielded enclosure. In harsh environment, they could (and sure they will) be a real pain in the... but on the flip side, it may work good... and maybe long enough to cover the warranty time :D

i NEVER use pull-up, never use the 'Set your pin as output and let'em floating in the air' The theory is hum hum good, but... will your design will always be powered? What happen with those pull-up when you remove the power... they're software enable after all!

Archangel
- 30th April 2007, 02:26
will your design will always be powered? What happen with those pull-up when you remove the power... they're software enable after all!
That's an excellent point, I never thought of.
JS

precision
- 30th April 2007, 04:50
i've said that hundreds of time on many forums... they're good for lazy prototyping and/or in a well shielded enclosure. In harsh environment, they could (and sure they will) be a real pain in the... but on the flip side, it may work good... and maybe long enough to cover the warranty time :D

i NEVER use pull-up, never use the 'Set your pin as output and let'em floating in the air' The theory is hum hum good, but... will your design will always be powered? What happen with those pull-up when you remove the power... they're software enable after all!

Please explain what is the problem in pullup, if chip have pullup feature ?
i ever useing OUTPUT PORTB.0 , is this wrong way ? Please tell what we must...


.

mister_e
- 30th April 2007, 05:18
it can be useful in few situation : tight space, mass production with tight budget, Push-button handling, prototyping, etc etc. They're weak, and may cause some problem (noise, ESD, strange behaviour, etc etc) one day or another. I got few ESD and erratic problems in the past with that in noisy environment, since i add external one, no more problem!

It's a long debate, some never ever had problem with... too bad i no longer take the risk.

precision
- 30th April 2007, 05:37
Thanks, one more Q. please
what should we use instead of output pin / input pin. I mean tbe best way to make input output pin ?

.

BobK
- 30th April 2007, 13:19
Hi Precision,

I think what Mister E is saying is always use an external resistor either in a pull up or pull down situation. Don't make an unused pin an output and just leave it floating. Look at the data sheet for the particular PIC you are using and search for the state of the pins ON RESET. If you are leaving a number of pins unused and they start as inputs on powerup or on reset then you need to make sure they are properly terminated with a pullup or pulldown resistor.

HTH,

BobK