TITLE"KeyStrokeWakeUp"
LISTP=16C54
;******************************************************
;Programdemonstratingkeystrokewakeupfor
;thePIC16CXX.Programhasbeenimplementedfor
;twokeys,butCANbeextendedformorekeys.
;WhenSW1ispressedagreenLEDlightsup.
;WhenSW2ispressedaredLEDlightsup.
;******************************************************
;
;Defineequates
;
PCEQU2
PORT_BEQU6
SCAN1EQU2
SCAN2EQU3
SW1EQU0
SW2EQU1
GRN_LEDEQU4
RED_LEDEQU5
MSEC_20EQUD’20’
DB1EQU8
GPEQU8
DB2EQU9
;
;PORT_BASSIGNMENTS:
;0-->SW1INPUT
;1-->SW2INPUT
;2-->SCAN1OUTPUT
;3-->SCAN2OUTPUT
;4-->GRN_LEDOUTPUT
;5-->RED_LEDOUTPUT
;6&7-->ASSIGNEDASDUMMYOUTPUTS
PAGE
;
;
ORG0
;
START
CALLINIT_PORT_B;INITIALIZEPORTB
CALLDELAY;DELAY20MSECS
CALLSCAN_KEYS;GETKEYVALUES
MOV WFGP;SAVEINRAM
BTFSCGP,SW1;SKIPIFSW1NOTPRESSED
CALLTURN_GREEN_ON;ELSEDOROUTINE
BTFSCGP,SW2;SKIPIFSW2NOTPRESSED
CALLTURN_RED_ON;ELSEDOROUTINE
CHK_FOR_KEY
CALLDELAY;DELAYFOR20MSEC
CALLSCAN_KEYS;GETKEYHIT
XORLW0;EXCL.ORWITH0
BNZCHK_FOR_KEY;KEYSTILLPRESSED
;THENLOOP
NO_KEY_PRESSED
BCFPORT_B,SCAN1;SETSCANLINESLOW
BCFPORT_B,SCAN2;/
SLEEP;SLEEP
;
PAGE
;
INIT_PORT_B
MOV LWB’00000011’;configRB0,1asi/p’s
TRISPORT_B;andRB2-7aso/p’s
MOV LW0FFh
MOV WFPORT_B;DEFAULTVALUESFORPORT_B
RETLW0;RETURNWITHNOERROR
;
;Thisroutine,scanstwokeysandreturnsthefollowing:
;0ifnokeyispressed
;1ifSW1ispressd
;2ifSW2ispressed
;3ifSW1andSW2arepressed
;
SCAN_KEYS
BCFPORT_B,SCAN1;ENABLESCANFORSW1
BCFPORT_B,SCAN2;EANBLESCANFORSW2
MOV LWB’00000011’;LOADMASKINW
ANDWFPORT_B,0;ANDWITHPORT
BSFPORT_B,SCAN1;DISABLESCAN
BSFPORT_B,SCAN2;/
ADDWFPC,1;GETOFFSETTOTABLE
RETLW3;SW1ANDSW2PRESSED
RETLW2;SW2PRESSED
RETLW1;SW1PRESSED
RETLW0;NOKEYPRESSED
;
;DELAY,ISAAPPROX.WAITFOR20.4mSECS,FORASYSTEM
;USINGA2MHzCRYSTALCLOCK.
DELAY
MOV LWMSEC_20
MOV WFDB1
DLY1
CLRFDB2
DECFSZDB1
GOTODLY2
RETLW0
DLY2
DECFSZDB2;INNERLOOP=1.02MSEC.
GOTODLY2;/
GOTODLY1
;
;
TURN_GREEN_ON
BCFPORT_B,GRN_LED
RETLW0
;
TURN_RED_ON
BCFPORT_B,RED_LED
RETLW0
;
END