;********************************************************************* ; * ; Tutorial 2 KEYPAD DECODER WITH WAKEUP FROM SLEEP * ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; The PIC16F877 supports several features making Keypad decoding ; easy. This example SLEEPs until a keypress is made, it then ; decodes the keypress and puts it onto PORTC and then falls ; back to sleep ;********************************************************************* ;* @version 0.1, 25 September 2001 ;* @author James Caska ;* @history 0.1, 25 September 2001 Created ;********************************************************************* list p=16F877 #include DELAY EQU .32 DEALYOUTER EQU .33 ORG .0 GOTO INIT ORG .4 INTERRUPTHANDLER CALL DEBOUNCE.Delay CALL KEYPAD.SCAN.4x4.ASCII IORLW .0 BTFSS STATUS,Z ;Update if KeyCode Found MOVWF PORTC CLRF PORTB BCF INTCON,RBIF RETFIE #include keyscan.asm DEBOUNCE.Delay MOVLW .10 MOVWF DEALYOUTER DEBOUNCE.Delay.Loop MOVLW .255 MOVWF DELAY DEBOUNCE.Delay.InnerLoop DECFSZ DELAY,F GOTO DEBOUNCE.Delay.InnerLoop DECFSZ DEALYOUTER,F GOTO DEBOUNCE.Delay.Loop RETURN INIT ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Begin PORT Configuration BSF STATUS, RP0 ;PORT TRIS Registers are on page 1 ;======PORT B MOVLW .240 ;PORTB Configuration Bits MOVWF TRISB ;======PORT C MOVLW .0 ;PORTC Configuration Bits MOVWF TRISC ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Enabled Port B Pullups BSF STATUS,RP0 ;Access Bank1 Configuration Bits BCF OPTION_REG,NOT_RBPU BCF STATUS,RP0 ;======Enabled Port B Interrupt BCF INTCON,RBIF ;Clear the PORTB interrupt flag BSF INTCON,RBIE ;Enabled the PORTB interrupt CLRF PORTB MOVLW ' ' ;Display Nothing to begin with MOVWF PORTC BSF INTCON,GIE ;Enable the Interrupts MAIN SLEEP ;Interrupt wakes up from sleep executes NOP then vectors to NOP ;interrupt handling routine GOTO MAIN END