"); //-->
代码
list p=16f877 #include<p16f877.inc> __CONFIG(_CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF& _CPD_OFF); CBLOCK 0X20 keyFIFO:8 keyPutPtr keyGetPtr endc cblock 0x70 w_temp status_temp pclath_temp fsr_temp endc org 0x0000 nop goto main org 0x004 movwf w_temp movf STATUS,W MOVWF status_temp movf PCLATH,W MOVWF pclath_temp movf FSR,W MOVWF fsr_temp pagesel $ banksel INTCON BTFSC INTCON,RBIF GOTO RBCHG_INT EndOfInt movf fsr_temp,w movwf FSR MOVF pclath_temp,w movwf PCLATH MOVF status_temp,w movwf STATUS SWAPF w_temp,f swapf w_temp,w retfie RBCHG_INT MOVF PORTB,W andlw b'11110000' xorlw b'11110000' skpnz goto _rbIntEnd movlw b'00001110' movwf PORTB _keyScan goto $+1 goto $+1 movf PORTB,W XORLW b'11111111' skpnz GOTO _rbIntEnd andlw b'11110000' skpz goto _keyFound setc rlf PORTB,f goto _keyScan _keyFound bankisel keyFIFO MOVLW keyFIFO&0xff addwf keyPutPtr,w movwf FSR MOVF PORTB,W MOVWF INDF incf keyPutPtr,f movlw 0x07 andwf keyPutPtr,f _rbIntEnd clrf PORTB MOVF PORTB,w bcf INTCON,RBIF GOTO EndOfInt main banksel TRISB MOVLW B'11110000' MOVWF TRISB MOVLW B'00000000' MOVWF TRISC BCF OPTION_REG,NOT_RBPU BANKSEL PORTB CLRF keyGetPtr CLRF keyPutPtr CLRF PORTB CLRF INTCON BSF INTCON,RBIE BSF INTCON,GIE mainLoop call KeyBoard goto mainLoop KeyBoard banksel keyGetPtr movf keyGetPtr,w xorwf keyPutPtr,w skpnz return bankisel keyFIFO MOVLW keyFIFO&0XFF addwf keyGetPtr,w movwf FSR incf keyGetPtr,f movlw 0x07 andwf keyGetPtr,f movf INDF,w BANKSEL PORTC MOVWF PORTC return end
运行效果图
按下7键,显示如下0xee
按下4键,显示如下0xed
按下1键,显示如下0xeb
按下0键,显示如下0xd7
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。