📄 docking_station.asm
字号:
movf State,w addwf PCL,f goto State0 goto State1 goto State2 goto State3 IF ((HIGH($)) != (HIGH(MainLoop))) ERROR("Table crosses page boundary!") ENDIF; --- Both relays offState0 movf RemoteReceiveState,w sublw 4 btfss STATUS,Z goto MainLoop ; No new command received from PMM by IR; Have new command from PMM movf RemoteReceiveByte,w sublw TURN_ON_EXT_COMMAND btfss STATUS,Z goto State0NotExtPower; Turn on external power command bsf EXT_SUPPLY_RELAY ; External supply relay On bcf EXT_SUPPLY_LED ; Turn on Green LED movlw TMR2_ONE_SEC * 60 movwf Timer2 movlw 1 movwf State ; Next state = 1 clrf RemoteReceiveState goto MainLoopState0NotExtPower clrf RemoteReceiveState goto MainLoop; --- Ext supply only onState1 movf Timer2,w btfss STATUS,Z goto State1Timer2NotZero; Ping timeout bsf EXT_SUPPLY_LED ; Green LED off bcf EXT_SUPPLY_RELAY ; External supply relay off clrf State goto MainLoopState1Timer2NotZero movf RemoteReceiveState,w sublw 4 btfss STATUS,Z goto MainLoop ; No new command received from PMM by IR; Have new command from PMM movf RemoteReceiveByte,w sublw TURN_OFF_EXT_COMMAND btfss STATUS,Z goto State1NotTurnOffExt; Turn off external supply bcf EXT_SUPPLY_RELAY ; External supply relay Off bsf EXT_SUPPLY_LED ; Turn off Green LED clrf State ; Next state = 0 clrf RemoteReceiveState goto MainLoopState1NotTurnOffExt movf RemoteReceiveByte,w sublw TURN_ON_CHARGER_COMMAND btfss STATUS,Z goto State1NotTurnOnCharger; Turn on charger movf Timer1,w btfss STATUS,Z goto Timer1NotZero; Go straight to state 3 bcf CHARGER_LED ; Yellow LED on bsf EXT_SUPPLY_LED ; Green LED off bsf CHARGER_RELAY ; Charger relay on movlw TMR2_ONE_SEC * 60 movwf Timer2 movlw 3 movwf State clrf RemoteReceiveState goto MainLoopTimer1NotZero; Go to state 2 (pending charger) bsf EXT_SUPPLY_LED ; Green LED off movlw TMR2_ONE_SEC * 60 movwf Timer2 movlw 2 movwf State clrf RemoteReceiveState goto MainLoopState1NotTurnOnCharger movf RemoteReceiveByte,w sublw PING_COMMAND btfss STATUS,Z goto State1NotPing; Ping movlw TMR2_ONE_SEC * 60 movwf Timer2 clrf RemoteReceiveState goto MainLoopState1NotPing clrf RemoteReceiveState goto MainLoop; --- Charging pendingState2 movf Timer2,w btfss STATUS,Z goto State2Timer2NotZero; Ping timeout bsf CHARGER_LED ; Yellow LED off bcf EXT_SUPPLY_RELAY ; External supply relay off clrf State goto MainLoopState2Timer2NotZero movf Timer1,w btfss STATUS,Z goto State2Timer1NotZero; Go to state 3 bcf CHARGER_LED ; Yellow LED on bsf CHARGER_RELAY ; Charger relay on movlw 3 movwf State goto MainLoopState2Timer1NotZero btfss Timer1,1 goto State2YellowOff; Yellow LED on bcf CHARGER_LED ; Yellow LED on goto State2YellowDoneState2YellowOff bsf CHARGER_LED ; Yellow LED offState2YellowDone movf RemoteReceiveState,w sublw 4 btfss STATUS,Z goto MainLoop ; No new command received from PMM by IR; Have new command from PMM movf RemoteReceiveByte,w sublw TURN_OFF_CHARGER_COMMAND btfss STATUS,Z goto State2NotTurnOffCharger; Turn off charger (it was never on) bsf CHARGER_LED ; Yellow LED off bcf EXT_SUPPLY_LED ; Green LED on movlw TMR2_ONE_SEC * 60 movwf Timer2 movlw 1 movwf State clrf RemoteReceiveState goto MainLoopState2NotTurnOffCharger movf RemoteReceiveByte,w sublw TURN_OFF_EXT_COMMAND btfss STATUS,Z goto State2NotTurnOffExt; Turn off external supply (and charger) bsf CHARGER_LED ; Yellow LED off bcf EXT_SUPPLY_RELAY ; External supply relay off clrf State clrf RemoteReceiveState goto MainLoopState2NotTurnOffExt movf RemoteReceiveByte,w sublw PING_COMMAND btfss STATUS,Z goto State2NotPing; Ping movlw TMR2_ONE_SEC * 60 movwf Timer2 clrf RemoteReceiveState goto MainLoopState2NotPing clrf RemoteReceiveState goto MainLoop; --- ChargingState3 movf Timer2,w btfss STATUS,Z goto State3Timer2NotZero; Ping timeout bsf CHARGER_LED ; Yellow LED off bcf EXT_SUPPLY_RELAY ; External supply relay off bcf CHARGER_RELAY ; Charger relay off movlw TMR1_ONE_SEC * 30 movwf Timer1 clrf State goto MainLoopState3Timer2NotZero movf RemoteReceiveState,w sublw 4 btfss STATUS,Z goto MainLoop ; No new command received from PMM by IR; Have new command from PMM movf RemoteReceiveByte,w sublw TURN_OFF_CHARGER_COMMAND btfss STATUS,Z goto State3NotTurnOffCharger; Turn off charger bsf CHARGER_LED ; Yellow LED off bcf EXT_SUPPLY_LED ; Green LED on bcf CHARGER_RELAY ; Charger relay off movlw TMR1_ONE_SEC * 30 movwf Timer1 movlw TMR2_ONE_SEC * 60 movwf Timer2 movlw 1 movwf State clrf RemoteReceiveState goto MainLoopState3NotTurnOffCharger movf RemoteReceiveByte,w sublw TURN_OFF_EXT_COMMAND btfss STATUS,Z goto State3NotTurnOffExt; Turn off external supply (and charger) bsf CHARGER_LED ; Yellow LED off bcf EXT_SUPPLY_RELAY ; External supply relay off bcf CHARGER_RELAY ; Charger relay off movlw TMR1_ONE_SEC * 30 movwf Timer1 clrf State clrf RemoteReceiveState goto MainLoopState3NotTurnOffExt movf RemoteReceiveByte,w sublw PING_COMMAND btfss STATUS,Z goto State3NotPing; Ping movlw TMR2_ONE_SEC * 60 movwf Timer2 clrf RemoteReceiveState goto MainLoopState3NotPing clrf RemoteReceiveState goto MainLoop; ----------------------------------------------------------------------; Subroutines; ----------------------------------------------------------------------InitClock bsf STATUS,RP0 bcf STATUS,RP1 movlw 0x060 ; Select 4MHz internal clock. movwf OSCCON^0x080 bcf STATUS,RP0 return; ----------------------------------------------------------------------InitInterrupts; Enable interrupts. bsf STATUS,RP0 bcf STATUS,RP1 bsf PIE1^0x080,TMR1IE ; Enable timer 1 interrupt bsf PIE1^0x080,TMR2IE ; Enable timer 2 interrupt bcf OPTION_REG^0x080,INTEDG ; Interrupt when RB0 goes High to Low bcf STATUS,RP0 clrf INTCON bsf INTCON,INTE ; Enable RB0/INT Pin interrupt bsf INTCON,PEIE ; Enable unmasked peripheral interrupts bsf INTCON,GIE ; Global Interrupt Enable return; ----------------------------------------------------------------------InitTimer bsf STATUS,RP0 bcf STATUS,RP1 bcf OPTION_REG^0x080,T0CS ; Select Timer Mode bcf OPTION_REG^0x080,PSA ; Assign prescaler to Timer0 bcf OPTION_REG^0x080,PS0 bcf OPTION_REG^0x080,PS1 bsf OPTION_REG^0x080,PS2 ; Set timer prescaler bcf STATUS,RP0; Set timer 1 to 1/4s period bcf T1CON,T1CKPS0 bsf T1CON,T1CKPS1 ; Set timer prescaler bcf T1CON,T1OSCEN ; Disable built-in oscillator bcf T1CON,TMR1CS ; Use Fosc/4 bsf T1CON,TMR1ON ; Turn on timer 1; Timer 2 to generate interrupts for ping timing bsf STATUS,RP0 bcf STATUS,RP1 movlw 255 movwf PR2^0x080 bcf STATUS,RP0 movlw 15 movwf Timer2tmp ; Set to 15 to get a 1 second period movlw b'01111110' movwf T2CON return; ----------------------------------------------------------------------InitIO; Set port A and B data directions movlw b'00010100' ; Initialize data bits movwf PORTA movlw b'00000000' movwf PORTB bsf STATUS,RP0 bcf STATUS,RP1 movlw b'00000110' movwf ADCON1^0x80 ; Not using ADC - set to I/O movlw b'00100000' ; Set Port A data direction bits. movwf TRISA^0x080 movlw b'00000001' ; Set Port B data direction bits. movwf TRISB^0x080 bcf STATUS,RP0 return; ----------------------------------------------------------------------; End end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -