PDA

View Full Version : Getting a 18F2525 to wake up from sleep with change of input



BobP
- 24th February 2018, 19:04
Hi All,

Been working on this all day and I must be doing something silly!

I want to wake up the 18F2525 from sleep by a change in port B.

Any help appreciated as I am quickly tearing my hair out.

Thanks
Bob


DEFINE OSC 20
INCLUDE "MODEDEFS.BAS"

#config
__CONFIG _CONFIG1H, _OSC_HS_1H
__CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L & _BORV_2_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_16384_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
__CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L
__CONFIG _CONFIG5H, _CPB_ON_5H
#endconfig

T2 var byte

LedG VAR PORTA.1 ' Green LED
LedR VAR PORTA.2 ' Red LED
BUZ VAR PORTA.3 ' Buzzer OP
KeyLine VAR PORTA.5 ' keyline
BPear1 var PORTB.4 ' Push 1 IP
BPear2 var PORTB.5 ' Push 2 IP
Bcall var PORTB.6 ' Call Button
Bcancel var PORTB.7 ' Cancel Button

LedR = 0 ' led off
LedG = 0 ' led off


Start:
BUZ = 1 ' Buzzer off
KeyLine = 1 ' transmitter off

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
Slp: ' Now prepare for sleep
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
'
INTCON=0 ' Disable all interrupt including tmr0
INTCON2.7 = 0 ' Enable weak pull-ups
PORTA=%00001000 '
PORTB=%11110000 '
PORTC=%00001000 '
TRISA = %00000000 '
TRISB = %11110000 '
TRISC = %00000000
T2=PORTB ' Read port to ensure no setting of flag
INTCON=%10001000 ' Enable the global interrupt and enable the change on port b

@sleep

PAUSE 100 ' Sound buzzer and Led as indicator of sleep exit
ledr=1
BUZ=0
pause 100
ledr=0
BUZ=1
pause 500
goto slp

end

richard
- 24th February 2018, 21:57
try this

DEFINE OSC 20
INCLUDE "MODEDEFS.BAS"

#config
__CONFIG _CONFIG1H, _OSC_HS_1H
__CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L & _BORV_2_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_16384_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
__CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L
__CONFIG _CONFIG5H, _CPB_ON_5H
#endconfig

T2 var byte

LedG VAR PORTA.1 ' Green LED
LedR VAR PORTA.2 ' Red LED
BUZ VAR PORTA.3 ' Buzzer OP
KeyLine VAR PORTA.5 ' keyline
BPear1 var PORTB.4 ' Push 1 IP
BPear2 var PORTB.5 ' Push 2 IP
Bcall var PORTB.6 ' Call Button
Bcancel var PORTB.7 ' Cancel Button

LedR = 0 ' led off
LedG = 0 ' led off


Start:
BUZ = 1 ' Buzzer off
KeyLine = 1 ' transmitter off

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
Slp: ' Now prepare for sleep
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''

INTCON2.7 = 0 ' Enable weak pull-ups
PORTA=%00001000 '
PORTB=%11110000 '
PORTC=%00001000 '
TRISA = %00000000 '
TRISB = %11110000 '
TRISC = %00000000
T2=PORTB ' Read port to ensure no setting of flag
INTCON=%00001000 ' Enable the global interrupt and enable the change on port b

@ sleep
@ nop


PAUSE 100 ' Sound buzzer and Led as indicator of sleep exit
ledr=1
BUZ=0
pause 100
ledr=0
BUZ=1
pause 500
goto slp

end

BobP
- 25th February 2018, 09:00
Hi,

Two small changes makes it work.

Many thanks Richard I was going round in circles getting nowhere.

Thanks
Bob