📄 input_module.asm
字号:
movwf ScanCode2 goto ButtonPushedKeyWaitCol2A btfsc KEYPAD_COL2 goto KeyWaitCol3A movlw UP_ARROW_SCAN_CODE1 movwf ScanCode1 movlw UP_ARROW_SCAN_CODE2 movwf ScanCode2 goto ButtonPushedKeyWaitCol3A btfsc KEYPAD_COL3 goto KeyWaitDoneColsA movlw ENTER_SCAN_CODE1 movwf ScanCode1 movlw ENTER_SCAN_CODE2 movwf ScanCode2 goto ButtonPushedKeyWaitDoneColsA bcf STROBE2 bsf STATUS,RP0 bsf STROBE1_DIRECTION ; Strobe 1 Hi-Z bcf STROBE2_DIRECTION ; Energize Strobe 2 bcf STATUS,RP0 btfsc KEYPAD_COL1 goto KeyWaitCol2B movlw LEFT_ARROW_SCAN_CODE1 movwf ScanCode1 movlw LEFT_ARROW_SCAN_CODE2 movwf ScanCode2 goto ButtonPushedKeyWaitCol2B btfsc KEYPAD_COL2 goto KeyWaitCol3B movlw DOWN_ARROW_SCAN_CODE1 movwf ScanCode1 movlw DOWN_ARROW_SCAN_CODE2 movwf ScanCode2 goto ButtonPushedKeyWaitCol3B btfsc KEYPAD_COL3 goto KeyWaitDoneColsB movlw RIGHT_ARROW_SCAN_CODE1 movwf ScanCode1 movlw RIGHT_ARROW_SCAN_CODE2 movwf ScanCode2 goto ButtonPushedKeyWaitDoneColsB goto WaitForKeyDownLoopButtonPushed bsf STATUS,RP0 bsf STROBE1_DIRECTION ; Strobe 1 Hi-Z bsf STROBE2_DIRECTION ; Strobe 2 Hi-Z bcf STATUS,RP0 bcf INTCON,GIE call SendScanCode ; Transmit key down and key up scan codes in succession bsf INTCON,GIE movlw 125 movwf KeyUpWaitCountWaitForKeyUpLoop bsf STATUS,RP0 bsf STROBE1_DIRECTION ; Strobe 1 Hi-Z bsf STROBE2_DIRECTION ; Strobe 2 Hi-Z bcf STATUS,RP0 decfsz KeyUpWaitCount,f goto NotHeldDown goto HeldDownNotHeldDown call Delay10ms btfsc KEYBOARD_DATA ; Check if host wants to talk to us goto WaitUp1 bcf INTCON,GIE call ReceiveFromHost bsf INTCON,GIE addwf PCL, f ; Jump according to value in w; Next 3 instructions constitute a jump table goto WaitForKeyUpLoop ; w=0 goto WaitForKeyUpLoop ; w=1: Reset bcf INTCON,GIE ; w=2: Resend IF ((HIGH($)) != (HIGH($-3))) ERROR("Table crosses page boundary!") ENDIF call SendScanCode bsf INTCON,GIE goto WaitForKeyUpLoopWaitUp1 call Delay10ms btfsc KEYBOARD_DATA ; Check if host wants to talk to us goto WaitUp2 bcf INTCON,GIE call ReceiveFromHost bsf INTCON,GIE addwf PCL, f ; Jump according to value in w; Next 3 instructions constitute a jump table goto WaitForKeyUpLoop ; w=0 goto WaitForKeyUpLoop ; w=1: Reset bcf INTCON,GIE ; w=2: Resend IF ((HIGH($)) != (HIGH($-3))) ERROR("Table crosses page boundary!") ENDIF call SendScanCode bsf INTCON,GIE goto WaitForKeyUpLoopWaitUp2 bcf STROBE1 bsf STATUS,RP0 bcf STROBE1_DIRECTION ; Energize Strobe 1 bcf STATUS,RP0 btfss KEYPAD_COL1 goto WaitForKeyUpLoop btfss KEYPAD_COL2 goto WaitForKeyUpLoop btfss KEYPAD_COL3 goto WaitForKeyUpLoop bcf STROBE2 bsf STATUS,RP0 bsf STROBE1_DIRECTION ; Strobe 1 Hi-Z bcf STROBE2_DIRECTION ; Energize Strobe 2 bcf STATUS,RP0 btfss KEYPAD_COL1 goto WaitForKeyUpLoop btfss KEYPAD_COL2 goto WaitForKeyUpLoop btfss KEYPAD_COL3 goto WaitForKeyUpLoop goto WaitForKeyDownLoopHeldDown; Look for Robot ID Code set bcf STROBE1 bsf STATUS,RP0 bcf STROBE1_DIRECTION ; Energize Strobe 1 bcf STATUS,RP0 movf PORTB,w movwf KeyRowData movlw 0x00E andwf KeyRowData,f xorwf KeyRowData,f btfsc STATUS,Z goto CheckForIRControl; Set Robot ID rrf KeyRowData,w andlw 0x007 call KeyRobotIDTable bcf INTCON,GIE ; Global Interrupt Disable call StoreRobotCodeInEEPROM bsf INTCON,GIE ; Global Interrupt Enable goto WaitForKeyUpLoopCheckForIRControl bcf STROBE2 bsf STATUS,RP0 bsf STROBE1_DIRECTION ; Strobe 1 Hi-Z bcf STROBE2_DIRECTION ; Energize Strobe 2 bcf STATUS,RP0 movf PORTB,w movwf KeyRowData movlw 0x00E andwf KeyRowData,f xorwf KeyRowData,f movlw 0x00C subwf KeyRowData,w btfss STATUS,Z ; IR disable key combo held down? goto CheckIREnable; Disable IR bcf INTCON,RBIE movlw DISABLE_REMOTE_CODE bcf INTCON,GIE ; Global Interrupt Disable call StoreIREnableCodeinEEPROM bsf INTCON,GIE ; Global Interrupt Enable goto WaitForKeyUpLoopCheckIREnable movlw 0x006 subwf KeyRowData,w btfss STATUS,Z ; IR enable key combo held down? goto CheckRFDisable; Enable IR movlw ENABLE_REMOTE_CODE bcf INTCON,GIE ; Global Interrupt Disable call StoreIREnableCodeinEEPROM bsf INTCON,GIE ; Global Interrupt Enable bsf INTCON,RBIE goto WaitForKeyUpLoopCheckRFDisable movlw 0x008 subwf KeyRowData,w btfss STATUS,Z ; RF disable key held down? goto CheckRFEnable; Disable RF bcf INTCON,INTE movlw DISABLE_REMOTE_CODE bcf INTCON,GIE ; Global Interrupt Disable call StoreRFEnableCodeinEEPROM bsf INTCON,GIE ; Global Interrupt Enable goto WaitForKeyUpLoopCheckRFEnable movlw 0x002 subwf KeyRowData,w btfss STATUS,Z ; RF enable key held down? goto WaitForKeyUpLoop; Enable RF movlw ENABLE_REMOTE_CODE bcf INTCON,GIE ; Global Interrupt Disable call StoreRFEnableCodeinEEPROM bsf INTCON,GIE ; Global Interrupt Enable bsf INTCON,INTE goto WaitForKeyUpLoop; ----------------------------------------------------------------------; Subroutines; ----------------------------------------------------------------------; Global interrupts are assumed to be disabled before this subroutine is calledCheckEEPROMSettings call GetRFEnabledCodeFromEEPROM movwf RFEnabledSetting movlw ENABLE_REMOTE_CODE subwf RFEnabledSetting,w btfsc STATUS,Z ; RF Enabled? goto RfEEPROMSettingOK ; Yes movlw DISABLE_REMOTE_CODE subwf RFEnabledSetting,w btfss STATUS,Z ; RF Disabled? goto EEPROMCorruptRfEEPROMSettingOK call GetIREnabledCodeFromEEPROM movwf IREnabledSetting movlw ENABLE_REMOTE_CODE subwf IREnabledSetting,w btfsc STATUS,Z ; IR Enabled? goto IrEEPROMSettingOK ; Yes movlw DISABLE_REMOTE_CODE subwf IREnabledSetting,w btfss STATUS,Z ; IR Disabled? goto EEPROMCorruptIrEEPROMSettingOK call GetRobotCodeFromEEPROM andlw 0x01F btfss STATUS,Z ; Robot Code invalid? goto EEPROMCorrupt call GetRobotCodeFromEEPROM iorlw 0 btfss STATUS,Z goto CheckDoneEEPROMCorrupt movlw 0x020 ; Corresponds to Robot ID Code = 1 call StoreRobotCodeInEEPROM movlw ENABLE_REMOTE_CODE call StoreIREnableCodeinEEPROM ; Default to IR Enabled movlw ENABLE_REMOTE_CODE call StoreRFEnableCodeinEEPROM ; Default to RF EnabledCheckDone return; ----------------------------------------------------------------------; Global interrupts are assumed to be disabled before this subroutine is calledStoreRFEnableCodeinEEPROM movwf EEDATA movlw RF_ENABLE_CODE_EE_ADDR movwf EEADR call WriteEE return; ----------------------------------------------------------------------; Global interrupts are assumed to be disabled before this subroutine is calledStoreIREnableCodeinEEPROM movwf EEDATA movlw IR_ENABLE_CODE_EE_ADDR movwf EEADR call WriteEE return; ----------------------------------------------------------------------; Global interrupts are assumed to be disabled before this subroutine is calledStoreRobotCodeInEEPROM movwf EEDATA movlw ROBOT_CODE_EE_ADDR movwf EEADR call WriteEE return; ----------------------------------------------------------------------; Global interrupts are assumed to be disabled before this subroutine is calledWriteEE bsf STATUS,RP0 bsf EECON1^0x080,WREN movlw 0x055 movwf EECON2^0x080 movlw 0x0AA movwf EECON2^0x080 bsf EECON1^0x080,WR btfsc EECON1^0x080,WR goto $-1 bcf EECON1^0x080,WREN bcf STATUS,RP0 return; ----------------------------------------------------------------------IsIREnabled call GetIREnabledCodeFromEEPROM sublw ENABLE_REMOTE_CODE return; ----------------------------------------------------------------------IsRFEnabled call GetRFEnabledCodeFromEEPROM sublw ENABLE_REMOTE_CODE return; ----------------------------------------------------------------------GetIREnabledCodeFromEEPROM movlw IR_ENABLE_CODE_EE_ADDR movwf EEADR bsf STATUS,RP0 bsf EECON1^0x080,RD bcf STATUS,RP0 movf EEDATA,w return; ----------------------------------------------------------------------GetRFEnabledCodeFromEEPROM movlw RF_ENABLE_CODE_EE_ADDR movwf EEADR bsf STATUS,RP0 bsf EECON1^0x080,RD bcf STATUS,RP0 movf EEDATA,w return; ----------------------------------------------------------------------GetRobotCodeFromEEPROM movlw ROBOT_CODE_EE_ADDR movwf EEADR bsf STATUS,RP0 bsf EECON1^0x080,RD bcf STATUS,RP0 movf EEDATA,w return; ----------------------------------------------------------------------BAT movlw 60 movwf BATloopCountBATloop call Delay10ms decfsz BATloopCount,f ; Delay for 0.6 seconds goto BATloop movlw 0x0AA ; Send "BAT successful" scan code movwf ByteToSend call SendByte return; ----------------------------------------------------------------------SendScanCode movf ScanCode1,w btfsc STATUS,Z ; Don't send if 0x000 goto Send1 movwf ByteToSend call SendByte sublw 0 btfsc STATUS,Z ; Check return code to see of host comms initiated goto Send1; host wants to communicate call ReceiveFromHost addwf PCL, f ; Jump according to value in w; Next 3 instructions constitute a jump table goto Send1 ; w=0 return ; w=1: Reset goto SendScanCode ; w=2: Resend IF ((HIGH($)) != (HIGH($-3))) ERROR("Table crosses page boundary!")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -