Newbie PIC program design help


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2011
    Posts
    7

    Default Newbie PIC program design help

    Hi there,

    I have a PIC12F675 and am trying to write a program in basic. What I have is a reed switch, which is attached to a door. When the door opens the reed switch closes. There is a continuous tone buzzer connected to the output of the micro. Now after a period of 10 seconds I want the micro to beep the buzzer approx 1 sec high 1.5 sec low continuously while the door is open. If the door is closed regardless of if the door alarm has been activated or not, it will end the program and return the micro back to sleep mode. The other part is I want a analogue input to monitor the battery voltage, when the battery voltage drops below 1V every time the door is opened the micro will make the buzzer emit a long 2 sec beep immediately after the door is opened until the battery have been changed, while maintaining the usual timing function of the door open. Can anyone help me out with that?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    What part are you having trouble with? Have you written any code yet or is this still is the conceptual stage?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    I haven't started the source code yet. I have kids and just can't get the time to learn the basic language. I have also been doing some reading on JAL, I know vbscript and find a lot of similarities, but I just can't find the time to put anything together yet, so yes it is still in the conceptual stage. Is my idea feasible though?. With the voltage monitoring, the input would need to be connected to its own vcc, is this ok directly or would it need to go through I diode do you think?

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Yes, it is doable. You may want to power the MCU with a DC to DC converter to have a constant voltage, then the actual battery voltage can be measured. Or set up a reference voltage with a divider.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Dec 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Quote Originally Posted by mackrackit View Post
    Yes, it is doable. You may want to power the MCU with a DC to DC converter to have a constant voltage, then the actual battery voltage can be measured. Or set up a reference voltage with a divider.
    I think I will scratch the battery monitor idea. I'll just go with the basic timer in JAL I think.

  6. #6
    Join Date
    Dec 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Quote Originally Posted by mackrackit View Post
    What part are you having trouble with? Have you written any code yet or is this still is the conceptual stage?
    What do you think of this?. I don't know how to use sleep and interrupt on change though.
    Attached Images Attached Images  
    Attached Images Attached Images

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Your code in the PDF is not PicBasicPro. Sorry, I do not do JAL.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Dec 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Quote Originally Posted by mackrackit View Post
    Your code in the PDF is not PicBasicPro. Sorry, I do not do JAL.
    Can you show me a PICBasic version?

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    http://melabs.com/samples/PBP-mixed/onint.htm
    For a different chip.

    What version of PBP do you have?
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Dec 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Quote Originally Posted by mackrackit View Post
    http://melabs.com/samples/PBP-mixed/onint.htm
    For a different chip.

    What version of PBP do you have?
    PBP3 The demo version.

  11. #11
    Join Date
    Dec 2011
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    Quote Originally Posted by ajhoward View Post
    PBP3 The demo version.
    Sorry for the noob answer...the pbp3 demo version doesn't support 12f675, no wonder I didn't hear back from you..sorry. I have proton ide 3.5.2.7. I have a code which close to what I need, but I think is something wrong with, because it doesn't seem to work, and it needs to modified a bit. I need it to have a 10 second delay before the flashing begins, and it needs to continue flashing until the switch goes open again, which would then return to sleep, ready for the next interrupt caused by the switch to begin the process again. This code doesn't seem to do anything...I have tried heaps of other codes on my pic and they work fine.

    'A change from Vdd to Vss on GPIO.4 will cause the 12F675 to wake up
    'It will then blink a LED 10 times and go back to sleep
    'Front end setup
    Device = 12F675
    Config WDT_OFF,PWRTE_ON,CP_OFF,MCLRE_OFF,BODEN_OFF
    TRISIO=24 'sets GPIO.3 and GPIO.4 as inputs and all others as outputs (or 011000)
    CMCON=7 'turns off comparator function [CMCON0=7]
    ADCON0=0 'no ADC - doesn't seem necessary but may be a good idea
    ANSEL=0 'no ADC input - IMPORTANT if using ports in digital mode
    VRCON=0 'turns off voltage reference to minimize sleep current
    INTCON=8 'Enables port change interrupt ie GPIE
    IOCB=16 'sets GPIO.4 for Interrupt on change [IOC=16]
    OPTION_REG.6=0 'INT on falling edge
    OPTION_REG.7=0 '00000000 WPU enabled,
    WPU=38 '00100110 = 38 set unused ports 1,2 and 5 tied to weak pull-up resistors
    'Define Variables
    wakeup VAR GPIO.4 'input, interrupt on change.
    LED VAR GPIO.0 'LED output
    x VAR Byte
    'Initial settings
    LED=0
    'Program
    START:
    INTCON.0=0
    DelayMS 100
    @ Sleep
    DelayMS 100
    For x= 1 To 10
    LED=1
    DelayMS 500
    LED=0
    DelayMS 500
    Next x
    GoTo START
    End
    Last edited by ajhoward; - 7th January 2012 at 09:47.

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Newbie PIC program design help

    You did not hear back because you did not state a further problem...
    Anyway, if you have Proton then the best place to get answers is here
    http://www.protonbasic.co.uk/

    I am not real familiar with Proton syntax but this does look odd
    TRISIO=24
    Should there be a hex modifier in there someplace?
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

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