dual 7-segment countdown timer code


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Apr 2007
    Posts
    9

    Unhappy dual 7-segment countdown timer code

    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

  2. #2
    Join Date
    Apr 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Smile Guys This Is My Code In Proton Basic

    '************************************************* ***************
    '* 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

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    Post a schematic and I'll give you hand if I can.

  5. #5
    Join Date
    Apr 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Schematic

    well this is just an idea of the schematic, i have to add transistors to drive led display and for buzzer and 5w led
    Attached Images Attached Images  

  6. #6
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dr.ragh View Post
    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.
    Last edited by T.Jackson; - 28th April 2007 at 02:49.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dr.ragh View Post
    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...

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile internal weak pullups work as advertised

    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.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  9. #9
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    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)
    Last edited by T.Jackson; - 29th April 2007 at 07:51.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Pull up resistor value

    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...

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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

    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!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Good Point

    Quote Originally Posted by mister_e View Post
    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
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  13. #13
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    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

    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...


    .
    Last edited by precision; - 30th April 2007 at 04:54.

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    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 ?

    .

  16. #16
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    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

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. WRITE not working
    By servo260 in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 29th December 2004, 02:02
  4. Driver code for 14 segment LED display
    By Durward Searcy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th December 2004, 20:08
  5. Multiplex two 7 segment display
    By Fernando Santos in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th July 2003, 13:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts