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
Bookmarks