Need help with SLEEP mode


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2007
    Posts
    13

    Default Need help with SLEEP mode

    Hi,

    I have a PIC 18F4525 connected to a LCD screen (16X2). When I turn on the power, I want the PIC to be in SLEEP mode forever until a button, which is connected to one of the pins of the PIC, is pressed.

    Once the button is pressed, the PIC will perform some operation and display the desired result on the LCD screen for 2 minutes.

    After displaying the result for 2 minutes, I want the PIC to go back into SLEEP mode....until the button is pressed again.

    I am using "@ SLEEP" command to make the PIC go into SLEEP mode forever. Is this right ???

    Please help me with this code.



    DEFINE OSC 8 .................................................. ... 'Set the frequency of the PIC

    '******Setting up the LCD display******

    DEFINE LCD_DREG PORTB ................................ 'Set LCD Data port
    DEFINE LCD_DBIT 4 ................................ 'Set starting Data bit
    DEFINE LCD_RSREG PORTB ................................ 'Set LCD Register Select port
    DEFINE LCD_RSBIT 0 ................................ 'Set LCD Register Select pin
    DEFINE LCD_EREG PORTB ................................ 'Set LCD Enable port
    DEFINE LCD_EBIT 1 ................................ 'Set LCD Enable pin
    DEFINE LCD_BITS 4 ................................ 'Set LCD in 8 bit data mode
    DEFINE LCD_LINES 2 ................................ 'Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2000 ................................ 'Set command delay time in us
    DEFINE LCD_DATAUS 50 ................................ 'Set data delay time in us


    @_CONFIG_CONFIG1H_OSC_INTIO67_1H

    OSCCON = %01110010 ................................ 'Set the frequency of internal osc as 8 MHz
    TRISB=0 ................................ 'Set Port B as output

    b0 var byte
    b0=100


    LCDOut $FE, 1
    PAUSE 500 ................................ 'Wait for LCD to initialize


    pic_sleep:


    IF PORTD.7=1 THEN ................................ 'Button is connected to Port D pin 7

    LCDOut $FE, 1
    LCDOut " LCD TEST " ................................ 'Display line1
    LCDOut $FE, $C0 ................................ 'Move to line 2
    LCDOut " b0 = ", DEC b0 ................................ 'Display b0 on LCD
    Pause 10000 ................................ 'Display the result for 10 seconds
    LCDOut " " ................................ 'Make the LCD screen blank



    ELSE
    @ SLEEP ................................ 'If button is not pressed, PIC should continue to be in SLEEP mode and the LCD screen should remain blank

    LCDOut $FE, 1
    'LCDOUT " "
    'LCDOut $FE, $C0
    'LCDOUT " "

    ENDIF
    GOTO pic_sleep

    END
    Last edited by aggie007; - 27th November 2007 at 05:34.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    957


    Did you find this post helpful? Yes | No

    Default

    My feeling is your code won't work ( I cant say for sure since I havent used the 4525 yet ). However, point to note is that the PIC has to be waken out of sleep to check the button you specified on PortD.7 In your application, I suggest you look at the 'interrupt on change' function on portb. When your button gets pressed, the sleep terminates and you perform the activity you desire. Then again ------ sleep.

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


    Did you find this post helpful? Yes | No

    Default

    you could still turn the internal osc to 32KHz (OSCCON) and poll the switches. Not sure of the pro/cons of this against SLEEP...
    Steve

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

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,620


    Did you find this post helpful? Yes | No

    Post

    Hi,

    Did you had a look here ...???

    http://www.picbasic.co.uk/forum/showthread.php?t=7540

    You'll find ALL that you need ... and more !!!

    Note for the "sleep at power on " you'll need FIRST to config LCD and processor ( without any LCD activating ) before entering a REAL sleep mode ...

    user won't see anything "alive" ... but your processor will have to work a bit at power on !!!

    Alain
    Last edited by Acetronics2; - 28th November 2007 at 11:01.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. High Power Consumption in Sleep Mode
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th September 2014, 14:29
  2. Replies: 4
    Last Post: - 9th October 2009, 09:01
  3. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 10:00
  4. Replies: 3
    Last Post: - 27th November 2007, 09:56
  5. Sleep Mode in PBP
    By Keith in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th March 2005, 21:58

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