blinker


Closed Thread
Results 1 to 7 of 7

Thread: blinker

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    3

    Default blinker

    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

  2. #2
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Sleep

    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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by nlirette View Post
    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?
    Code:
    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:
    Code:
    @  sleep
    and it worked, and would not without the " @ " perhaps someone else can explain to us both as to why.
    Edit
    Code:
    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?
    Last edited by Archangel; - 26th July 2009 at 07:34.
    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.

  4. #4
    Join Date
    Jul 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default blinker

    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

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


    Did you find this post helpful? Yes | No

    Default

    Throw the worthless simulator away and use a real chip, get real compiler errors, flash real LEDs and see what works. IMHO
    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.

  6. #6
    Join Date
    Jul 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default blue

    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

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


    Did you find this post helpful? Yes | No

    Default

    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)
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Serin serout problem
    By lerameur in forum mel PIC BASIC Pro
    Replies: 336
    Last Post: - 6th February 2007, 04:25

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