PDA

View Full Version : Newbie PIC program design help



ajhoward
- 14th December 2011, 09:34
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?

mackrackit
- 14th December 2011, 13:39
What part are you having trouble with? Have you written any code yet or is this still is the conceptual stage?

ajhoward
- 15th December 2011, 05:32
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?

mackrackit
- 15th December 2011, 13:12
Yes, it is doable. You may want to power the MCU with a DC to DC converter (http://www.picbasic.co.uk/forum/showthread.php?t=15759) to have a constant voltage, then the actual battery voltage can be measured. Or set up a reference voltage with a divider.

ajhoward
- 16th December 2011, 03:34
Yes, it is doable. You may want to power the MCU with a DC to DC converter (http://www.picbasic.co.uk/forum/showthread.php?t=15759) 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.

ajhoward
- 30th December 2011, 22:45
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.

mackrackit
- 31st December 2011, 03:40
Your code in the PDF is not PicBasicPro. Sorry, I do not do JAL.

ajhoward
- 31st December 2011, 06:00
Your code in the PDF is not PicBasicPro. Sorry, I do not do JAL.

Can you show me a PICBasic version?

mackrackit
- 31st December 2011, 06:51
http://melabs.com/samples/PBP-mixed/onint.htm
For a different chip.

What version of PBP do you have?

ajhoward
- 31st December 2011, 09:30
http://melabs.com/samples/PBP-mixed/onint.htm
For a different chip.

What version of PBP do you have?

PBP3 The demo version.

ajhoward
- 7th January 2012, 09:43
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

mackrackit
- 7th January 2012, 11:59
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?