Need help with SLEEP mode


Results 1 to 4 of 4

Threaded View

  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 04:34.

Similar Threads

  1. High Power Consumption in Sleep Mode
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th September 2014, 13:29
  2. Replies: 4
    Last Post: - 9th October 2009, 08: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, 09:00
  4. Replies: 3
    Last Post: - 27th November 2007, 08:56
  5. Sleep Mode in PBP
    By Keith in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th March 2005, 20:58

Members who have read this thread : 1

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