📄 mdfan.asm
字号:
movmi time, #TIMER_COUNT_NONE ;no timer when turn on
movmi speed, #SPEED_LO ;speed low when turn on
call Start_Up_Fan ;run at speed middle when power on
bclr F_10S_ARRIVED
;clr counter_l
clr counter_m
clr counter_h
call Init_T0 ;reintilize T0,time 10s
jmp Command_Handle_End ;valide command from user,handle it and return
Power_On2Off: ;we are now in 'POWER_ON' state
movmi power, #POWER_OFF ;a press in this state change the state to 'POWER_OFF'
call Run_Speed_None ;stop running
call Lit_LED_None ;off all led
movmi timer_count, #TIMER_COUNT_NONE ;no timer,don't check auto-sleep
bset F_10S_ARRIVED ;don't check 10s when power-off.
jmp Command_Handle_End ;valide command from user,handle it and return
Handle_Speed:
;------------------------
mov A, power
cmprs A, #POWER_ON
jmp Command_Handle_End ;do not handle it when power-off
;------------------------
bset F_10S_ARRIVED ;key pressed within the first 10s after reset,don't check 10s.
call BeepShort
mov A, speed
cmprs A, #SPEED_LO ;we are now in 'SPEED_LO' state?
jz Speed_Lo2Mid
cmprs A, #SPEED_MID ;we are now in 'SPEED_MID' state?
jz Speed_Mid2Hi
Speed_Hi2Lo: ;we are now in 'SPEED_HI' state
movmi speed, #SPEED_LO ;a press in this state change the state to 'SPEED_LO'
call Run_Speed_Lo
jmp Command_Handle_End ;valide command from user,handle it and return
Speed_Lo2Mid: ;we are now in 'SPEED_LO' state
movmi speed, #SPEED_MID ;a press in this state change the state to 'SPEED_MID'
call Run_Speed_Mid
jmp Command_Handle_End ;valide command from user,handle it and return
Speed_Mid2Hi: ;we are now in 'SPEED_MID' state
movmi speed, #SPEED_HI ;a press in this state change the state to 'SPEED_HI'
call Run_Speed_Hi
jmp Command_Handle_End ;valide command from user,handle it and return
Handle_Time:
;------------------------
mov A, power
cmprs A, #POWER_ON
jmp Command_Handle_End ;do not handle it when power-off
;------------------------
call BeepShort
;clr counter_l ;reset timer
clr counter_m
clr counter_h
call Init_T0 ;reinitilize T0
mov A, time
cmprs A, #TIME_NONE ;we are now in 'TIME_NONE' state?
jz Time_None22H
cmprs A, #TIME_2H ;we are now in 'TIME_2H' state?
jz Time_2H24H
cmprs A, #TIME_4H ;we are now in 'TIME_4H' state?
jz Time_4H28H
Time_8H2None: ;we are now in 'TIME_8H' state
movmi time, #TIME_NONE ;a press in this state change the state to 'TIME_NONE'
call Lit_LED_None
movmi timer_count, #TIMER_COUNT_NONE ;clear timer_counter
jmp Command_Handle_End ;valide command from user,handle it and return
Time_None22H: ;we are now in 'TIME_NONE' state
movmi time, #TIME_2H ;a press in this state change the state to 'TIME_2H'
call Lit_LED_2H
movmi timer_count, #TIMER_COUNT_2H
jmp Command_Handle_End ;valide command from user,handle it and return
Time_2H24H: ;we are now in 'TIME_2H' state?
movmi time, #TIME_4H ;a press in this state change the state to 'TIME_4H
call Lit_LED_4H
movmi timer_count, #TIMER_COUNT_4H
jmp Command_Handle_End ;valide command from user,handle it and return
Time_4H28H: ;we are now in 'TIME_4H' state?
movmi time, #TIME_8H ;a press in this state change the state to 'TIME_8H'
call Lit_LED_8H
movmi timer_count, #TIMER_COUNT_8H
jmp Command_Handle_End ;valide command from user,handle it and return
;------------------------------------------------------------------------
Access_Code_Read:
;------------------------
;mov A, #0xff ;access code should be 0xff when pairing the device
;cmprs A, access_code0
;jmp Command_Handle_End
;cmprs A, access_code1
;jmp Command_Handle_End
;cmprs A, access_code2
;jmp Command_Handle_End
;------------------------
;mov A, #0 ;pairing event should only occour druing the first 1 minute since power-on reset
;cja counter_h, A, Command_Handle_End ;coounter_h>0,Access Code denied.
;mov A, #ACC_CODE_TIME_ALLOWED
;cja counter_m, A, Command_Handle_End ;coounter_m>allowed time,Access Code denied
;---------------------------
;call Delay_10ms ;Delay for remote to change to Rx mode
movmi command, #COMM_MODE_ACCESS_CODE_RETURN ;fill command with 'Access Code Reply'
call Write_Tx_Pload
call Tx_Mode ;change to Tx mode
call CE_Puls ;generate CE puls to Tx data
call Delay_100ms ;wait for data to sent out
call Rx_Mode ;go back to Rx mode
jmp Command_Handle_End ;valide command from user,handle it and return
;--------------------------------------------------------------------------
Access_Code_Wri: ;worker send access code via RF,save it
movmm local_access_code0, access_code0 ;load access code0 received to local
movmm local_access_code1, access_code1 ;load access code1 received to local
movmm local_access_code2, access_code2 ;load access code2 received to local
call Save_AccessCode ;save to EEPROM for future use
call Set_New_RX_Addr ;set new Rx address
;............indicate worker........................
call Init_TC0
;call Start_TC0
call Lit_LED_All
call Delay_250ms
call Stop_TC0
call Lit_LED_None
call Delay_250ms
call Start_TC0
call Lit_LED_All
call Delay_250ms
call Stop_TC0
call Lit_LED_None
call Delay_250ms
call Start_TC0
call Lit_LED_All
call Delay_250ms
call Stop_TC0
call Lit_LED_None
;call Delay_250ms
;....................................................
jmp Command_Handle_End ;valide command from user,handle it and return
;----------------------Board Test-------------------
Test_Board:
bset F_10S_ARRIVED ;test board,don't check 10s.
Test_EEPROM:
movmi test_data0, #0x55
movmi test_data1, #0xaa
call Save_TestCode
call Delay_100ms
clr test_data0
clr test_data1
call Load_TestCode
mov A, test_data0
cmprs A, #0x55
jmp EEPROM_Error
mov A, test_data1
cmprs A, #0xaa
jmp EEPROM_Error
Test_Function:
call Run_Speed_Mid
call Lit_LED_4H
call Delay_10S
call Run_Speed_Hi
call Lit_LED_8H
call Delay_10S
call Run_Speed_Lo
call Lit_LED_2H
call Delay_10S
call Run_Speed_None
call Lit_LED_None
jmp Command_Handle_End
EEPROM_Error:
call Lit_LED_All
call BeepShort
call Lit_LED_None
call Delay_250ms
call Delay_250ms
call Lit_LED_All
call BeepLong
call Lit_LED_None
jmp Test_Function
;-----------------------------------------------
;=======================================================================
Tx_Data_Sent: ;'Access Code Reply' success
;call Rx_Mode ;go back to Rx mode
jmp Command_Handle_End
;========================================================================
Max_Retries: ;'Access Code Reply' failed
;call Rx_Mode ;go back to Rx mode
jmp Command_Handle_End
;*******************************************************************
;----------------------Interrup Service Routine----------------------
ISR:
xch A,AccBuf ;store Acc into buffer
movmm PFlagBuf, PFLAG ;store Pflag into buffer
T0_Check:
jb0 FT0IEN, INT1_Check ;FT0IEN=0,T0 interrup is disable,goto check INT1
jb1 FT0IRQ, T0_ISR ;FTC1IRQ=1,TC1 interrup occour,goto T0 ISR
INT1_Check:
jb0 FP01IEN, ISR_Exit ;FP01IEN=0,INT1 interrup is disable,get out of ISR
jb1 FP01IRQ, INT1_ISR ;FP01IRQ=1,INT1 interrup occour,goto INT0 ISR
ISR_Exit:
movmm PFLAG, PFlagBuf ;restore Pflag
xch A,AccBuf ;restore Acc
reti
;---------------------------Timer Overflow Interrup Service Routine----------------
;T0 interrup triggers every 10s
T0_ISR:
B0BCLR FT0IRQ ;clear FTC1IRQ to accept next interrup
MOV A, #T0C_VALUE
B0MOV T0C, A ;reload T0C value manuly.
;------------------------------
bset F_CHECK_CD ;check CD every 10s
;------------------------------
inc counter_m ;counter_m++ every 10s
;mov a, #180 ;10s*180=1800s=30min=0.5hour
mov a, #225 ;8s*225=1800s=30min=0.5hour
cjb counter_m, a, ISR_Exit ;counter_m<180,exit
clr counter_m ;counter_m>=1800,counter_m=0
inc counter_h ;counter_h++ every 0.5hour
jmp ISR_Exit ;exit
;-------------------------INT1 Interrup Service Routine--------------
INT1_ISR:
B0BCLR FP01IRQ ;clear FP01IRQ to accept the next interrup
bclr PIN_SPI_CSN ;SPI enable
movmi spi_data, #WRITE_REG+STATUS
call SPI_RW ;write register adrress
movmm spi_status, spi_data ;store register "Status" value
movmi spi_data, #MASK_IRQ_FLAGS
call SPI_RW ;write register value
bset PIN_SPI_CSN
mov A, spi_status
mov status_temp, A ;store the value for future use
and A, #MASK_IRQ_FLAGS
mov irq_source, A
jmp ISR_Exit
;-------------------------ClrRAM subroutine-------------------------
ClrRAM:
; RAM Bank 0
clr Y ;Select bank 0
movmi Z, #3fh ;Set @YZ address from bottom of RAM
ClrLoop:
clr @YZ ;Clear @YZ content
decms Z ;z = z – 1 , skip next if z=0
jmp ClrLoop
clr @YZ ;Clear address 0x00
ret
;--------------------------SysInit subroutine-----------------------
SysInit:
;initialize ports
mov A, #0ffh ;enable all pull-up register
mov P5UR, A
mov P1UR, A
mov P0UR, A
mov P5M, A ;configure all pin as output
mov P1M, A
bset P0M.0
bclr P5M.@BIT(PIN_SPI_MISO) ;MISO input
bclr P0M.@BIT(PIN_IRQ_nRF24L01) ;INT input
clr P1OC ;disable open-drain
movmi P5, #10001011b ;MISO=Hiz,CE=L,SCK=L,BUZZ=L,CSN=H,MOSI=L,LED_8H=H,LED_4H=H
movmi P1, #11111111b ;Ctrl=H,SDA=H,SCL=H,LED_Lo=H,LED_Mid=H
movmi P0, #00000011b ;INT=Hiz,LED_2H=H
;initialize interrupt
clr INTEN
clr INTRQ
dint ;disable global interrup
ret
Enable_RF_INT:
B0BSET FP01IEN ;enable INT from nRF24L01
clr INTRQ
eint ;enable global interrup
ret
;----------------------------------------------
Init_T0:
;initialize timer
B0BCLR FT0ENB ; T0 timer.
B0BCLR FT0IEN ; T0 interrupt function is disabled.
B0BCLR FT0IRQ ; T0 interrupt request flag is cleared.
;Set T0 timer rate.
MOV A, #T0_RATE
B0MOV T0M, A ; T0 timer is disabled.
;Set T0 interrupt interval time.
MOV A, #T0C_VALUE
B0MOV T0C, A ; Set T0C value.
B0BSET FT0IEN ; Enable T0 interrupt function.
B0BSET FT0ENB ; Enable T0 timer.
ret
;---------------------------------------------------
Init_TC0:
B0BCLR FTC0ENB ; TC0 timer, TC0OUT and PWM stop.
B0BCLR FTC0IEN ; TC0 interrupt function is disabled.
B0BCLR FTC0IRQ ; TC0 interrupt request flag is cleared.
;Set TC0 timer rate. (Besides event counter mode.)
MOV A, #TC0_RATE ;The TC0 rate control bits exist in bit4~bit6 of TC0M. The
B0MOV TC0M, A ; TC0 interrupt function is disabled.
;Set TC0 interrupt interval time, TC0OUT (Buzzer) frequency or PWM duty cycle.
MOV A, #TC0C_VALUE ; TC0C and TC0R value is decided by TC0 mode.
B0MOV TC0C, A ; Set TC0C value.
B0MOV TC0R, A ; Set TC0R value under auto reload mode or PWM mode.
B0BSET FALOAD0 ; Enable TC0 auto reload function.
;B0BSET FTC0IEN ; Enable TC0 interrupt function.
B0BSET FTC0OUT ; Enable TC0OUT (Buzzer) function.
B0BSET FTC0ENB ; Enable TC0 timer.
ret
;---------------------------------------------------
;for indicating that wokers have programmed Access Codes to a Fan
Init_TC0_1k:
B0BCLR FTC0ENB ; TC0 timer, TC0OUT and PWM stop.
B0BCLR FTC0IEN ; TC0 interrupt function is disabled.
B0BCLR FTC0IRQ ; TC0 interrupt request flag is cleared.
;Set TC0 timer rate. (Besides event counter mode.)
MOV A, #TC0_RATE_1k ;The TC0 rate control bits exist in bit4~bit6 of TC0M. The
B0MOV TC0M, A ; TC0 interrupt function is disabled.
;Set TC0 interrupt interval time, TC0OUT (Buzzer) frequency or PWM duty cycle.
MOV A, #TC0C_VALUE_1k; TC0C and TC0R value is decided by TC0 mode.
B0MOV TC0C, A ; Set TC0C value.
B0MOV TC0R, A ; Set TC0R value under auto reload mode or PWM mode.
B0BSET FALOAD0 ; Enable TC0 auto reload function.
;B0BSET FTC0IEN ; Enable TC0 interrupt function.
B0BSET FTC0OUT ; Enable TC0OUT (Buzzer) function.
B0BSET FTC0ENB ; Enable TC0 timer.
ret
;---------------------------------------------------
Check_Auto_ShutDown:
mov A, timer_count
cmprs A, #TIMER_COUNT_NONE
jz Check_Auto_ShutDown_Out ;no timer,don't auto shut down
cjb counter_h, A, Check_Auto_ShutDown_Out ;time not arrived yet
movmi power, #POWER_OFF ;a press in this state change the state to 'POWER_OFF'
call Run_Speed_None ;stop running
call Lit_LED_None ;off all led
movmi timer_count, #TIMER_COUNT_NONE ;no timer,don't check auto-sleep
bset F_10S_ARRIVED ;don't Check_10S when power-off
Check_Auto_ShutDown_Out:
ret
;----------------------------------------------------
Check_10s:
jb1 F_10S_ARRIVED, Time_Out_10s ;key pressed or 10s time out?
mov A, #1
cjb counter_m, A, Time_Out_10s
movmi speed, #SPEED_LO
call Run_Speed_Lo ;10s time out,no key pressed
bset F_10S_ARRIVED
Time_Out_10s:
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -