Has anyone got any simple code that I can 'borrow' to make a '84 wake up
from sleep mode when an input changes state? I also want some code to put
the device back into sleep mode.
The application? Well I want to build my daughter an electronic gadget for
christmas. Press a button and lights come on, the thing beeps and then
switches off !
Any help much appreciated!
Mike Barrett
=============================================
Mike Barrett E-mail: spam_OUTbarrettTakeThisOuTcambridge.scr.slb.com
Schlumberger Cambridge Research Phone: 01223 325200
PO Box 153, Cambridge, CB3 OHG. U.K Fax: 01223 327019
=============================================
(Sending again as the first attempt seemed to have been rejected by the
listserver)
Has anyone got any simple code that I can 'borrow' to make a '84 wake up
from sleep mode when an input changes state? I also want some code to put
the device back into sleep mode.
The application? Well I want to build my daughter an electronic gadget for
christmas. Press a button and lights come on, the thing beeps and then
switches off !
Any help much appreciated!
Mike Barrett
=============================================
Mike Barrett E-mail: .....barrettKILLspam@spam@cambridge.scr.slb.com
Schlumberger Cambridge Research Phone: 01223 325200
PO Box 153, Cambridge, CB3 OHG. U.K Fax: 01223 327019
=============================================
>Has anyone got any simple code that I can 'borrow' to make a '84 wake up
>from sleep mode when an input changes state? I also want some code to put
>the device back into sleep mode.
Check page 2-543 of the 94 databook for explanation of the TO and PD Status
bits., and the "SLEEP" instruction. PortB and INT interrupts will wakeup the
processor as well as a watch-dog timer time-out. Execution may start at the
ISR vector H'004' or elsewhere, depending on how the interrupts are configured.
>Has anyone got any simple code that I can 'borrow' to make a '84 wake up
>from sleep mode when an input changes state? I also want some code to put
>the device back into sleep mode.
This is sample code: " how to sleep and wake-up with portB"
Port B is able to wake up from sleep mode on a change state on its pin:
PB4, PB.5, PB.6 or PB.7,
There is to way to get out from sleep mode:
- by an interrupt routine (GIE=3D1)
- by an event (GIE=3D0)
1=B0/ Just configure PB4..PB7 as input for example:=20
PB4 and PB.7, PB.5 and PB.6 are output
2=B0/ Make a read of port B to latch value,
3=B0/ Set RBIF bit to enable interrupt on portB change
4=B0/ go in sleep mode
--------------------------------
*** A/ Wake-up with interrupt
; before, be sure RBIF is not active, RBIE is not set, bank 0 is activated
; don't forget RBPU bit to set pull-up on or off (depend your hardware)
start: bsf STATUS,RP0 ; STATUS address =3D 03h (or 83h), RP0 =3D STATUS.5
; SWITCH to bank 1 (register 80h to FFh)
movlw 090h ; PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
; in out out in out out out out
movwf TRISB ; TRISB address =3D 86h
bcf STATUS,RP0 ; STATUS address =3D 03h (or 83h), RP0 =3D STATUS.5
; SWITCH to bank 0 (register 00h to 7Fh)
movf PORTB,W ; Read PORTB (PortB address =3D 03h)
movlw 088h ; GIE =3D 1 and RBIE =3D 1
movwf INTCON ; INTCON address =3D 0Bh
sleep ; ENTER SLEEP MODE, low power, no oscillator =20
nop ; after sleep instruction, at the wake up the next
instruction is executed before jumping to the INT vector
; .... program will continue after wake-up and interrupt
goto start
--------------------------------
*** B/ Wake-up without interrupt
; Another way is to skeep interrupt routine and use only PORTB wakeup
org 0 ; RESET VECTOR
goto start
start: bsf STATUS,RP0 ; STATUS address =3D 03h (or 83h), RP0 =3D STATUS.5
; SWITCH to bank 1 (register 80h to FFh)
movlw 090h ; PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
; in out out in out out out out
movwf TRISB ; TRISB address =3D 86h
bcf STATUS,RP0 ; STATUS address =3D 03h (or 83h), RP0 =3D STATUS.5
; SWITCH to bank 0 (register 00h to 7Fh)
movf PORTB,W ; Read PORTB (PortB address =3D 03h)
movlw 008h ; GIE =3D 0 and RBIE =3D 1, NO INTERRUPT
movwf INTCON ; INTCON address =3D 0Bh
sleep ; ENTER SLEEP MODE, low power, no oscillator =20
nop ; after sleep instruction, at the wake up
; no interrupt is fetched due to GIE=3D0
bcf INTCON,RBIE ; clear no match condition
movf PORTB,W
bcf INTCON,RBIF
; .... program will continue after wake-up=20
goto start