PDA

View Full Version : blinker



nlirette
- 25th July 2009, 15:39
i wrote this code

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

' using a 12F683 pic, pin 7 will toggle on and off every 3 minutes
' and pin 6 will toggle opposite
' when pin 7 is on, pins 2 and 3 will blink LED for short period
' every 10 seconds (pin 2 + pin 3 -)
' when pin 6 goes on (pin 7 off) pins 2 and 3 will reverse polarity
' and blink for short period every 10 seconds(pin 3 + pin 2 -)
' this will loop while power is on the chip

define osc 20 ' makes the internal oscillator 2 MHZ ( default 4 MGH )
XX var byte ' makes xx a variable

PORTB.0 = 1 ' pin 7
PORTB.1 = 1 ' pin 6
PORTB.5 = 1 ' pin 2
PORTB.4 = 1 ' pin 3

loop: ' label

High 0 ' set pin 7 on
low 1 ' set pin 6 low
low 4 ' set pin 3 low

for xx = 1 to 18 ' blink the LED on pins 2 and 3
HIGH 5
pause 25
LOW 5
pause 2000
next xx

Low 0 ' set pin 7 low
high 1 ' set pin 6 on
low 5 ' set pin 2 low

for xx = 1 to 18 ' blink the LED on pins 2 and 3 (reverse polarity)
high 4
pause 25
low 4
pause 2000
next xx

Goto loop ' Go back to loop and blink LED forever

End

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

what i would like to do is put the PIC to sleep in
the for next area of the program
when i replace the "pause 2000" to "sleep 10" it does not work
i want to save battery drain using the low power feature (sleep) of the chip
any reason why the sleep doesn't work?
Norman

Bill Legge
- 26th July 2009, 05:31
One of the reasons that the command SLEEP will not work my be that you have not turned the Watchdog Timer ON.

I think there are two ways to turn the WDT on:

1. Some option in your programmer - i.e. one of the selection boxes along with CODE PROTECT, OSCILLATOR selection and so on?

2. By setting the CONFIGURATION register/word in you pic. You will need to read the Microchip Data Steet for the correct details.

Good luck

Bill Legge

Archangel
- 26th July 2009, 07:19
what i would like to do is put the PIC to sleep in
the for next area of the program
when i replace the "pause 2000" to "sleep 10" it does not work
i want to save battery drain using the low power feature (sleep) of the chip
any reason why the sleep doesn't work?
Norman
Hi Norman,
Welcome to this forum !
Does the circuit work using the For next loop ? What happens when you tell it to sleep ? Does it sleep and fail to awaken, or just never sleeps?


define osc 20 ' makes the internal oscillator 2 MHZ ( default 4 MGH )

20 ? for 2 ? Also You should get the habit of using all UPPERCASE for defines, a requirement for MPASM.
I am not a SLEEP expert, I have seen it done this way:


@ sleep

and it worked, and would not without the " @ " perhaps someone else can explain to us both as to why.
Edit


PORTB.0 = 1 ' pin 7
PORTB.1 = 1 ' pin 6
PORTB.5 = 1 ' pin 2
PORTB.4 = 1 ' pin 3

12F683 does not have a PortB it uses GPIO . Are you doing this in a simulator?

nlirette
- 27th July 2009, 02:15
Thanks for the replies
I am using it in a simulator
when i use sleep, all i get is a square wave approx 2 hz from all outputs
the sleep command should just put the chip to sleep i thought
i am not sure how to turn the watch dog timer on and off
Norman

Archangel
- 27th July 2009, 06:49
Throw the worthless simulator away and use a real chip, get real compiler errors, flash real LEDs and see what works. IMHO

nlirette
- 27th July 2009, 13:22
Ahhh.
I'm new to microchips but not new to electronics
Thanks
I will build my circuit and program the chip
Very good suggestion
As I say... better to ask and find out
then to not ask and never find out
Thanks again...
Any idea how to turn the watchdog timer on and off
using pic basic pro??
Any good books etc...
Norman

mackrackit
- 27th July 2009, 13:59
Books are not much better than simulators. That is until Bruce finishes his.
This forum is the best place to find info on PBP. And it is free.

First go to the FAQ section and use the better search tool. 99% of questions ask today have been asked and answered, but some are hard to find.

Save your money and start readind every post on this forum.
Pay close attention to Melanie, Bruce, Darrel and Steve(mr.e)