mikeReynolds
Member
Please forgive the rather long post. I am working on building an infrared remote controlled light switch/dimmer that will utilize zero crossing detection thru an interrupt. (60 Hz so 2 crossings per cycle) I am using Jason's (Atomsoft) SourceBoost C code for SIRC to receive the IR code and just want someone to check my math. I will be using a 12F629 at 4 MHz so figuring the max time for BTFSS's, DECFSZ's, BTFSC's of 2 instructions, plus 2 for all CALL's, GOTO's, and RETURN's I calculate the following code will take approx. 3137 uS to get 1 button press and set a pin high. Since the code in sections label 8 through label 13 will execute 7 times and the code in sections label 14 through label 19 will execute 5 times. I should have plenty of time between zero crossings to do this since 120 hz equates to 8333 uS if my math serves me right. But it is late and I might have miscounted so I am asking for opions on my thinking.
Code:
GetSIRC_00000
; { GetSIRC ; function begin
label6
CLRF GetSIRC_00000_1_ir_cmd
MOVLW 0x00
CLRF GetSIRC_00000_1_ir_add
label7
BTFSC gbl_gpio,5
GOTO label7
CLRF gbl_lTime
label8
BTFSC gbl_gpio,5
GOTO label9
INCF gbl_lTime, F
MOVLW 0x13
MOVWF delay_10us_00000_arg_del
CALL delay_10us_00000
GOTO label8
label9
MOVF gbl_lTime, W
SUBLW 0x0A
BTFSC STATUS,C
GOTO label6
MOVLW 0x0E
SUBWF gbl_lTime, W
BTFSC STATUS,C
GOTO label6
CLRF gbl_lTime
CLRF GetSIRC_00000_1_x
label10
MOVLW 0x07
SUBWF GetSIRC_00000_1_x, W
BTFSC STATUS,C
GOTO label14
BCF STATUS,C
RRF GetSIRC_00000_1_ir_cmd, F
label11
BTFSC gbl_gpio,5
GOTO label11
CLRF gbl_lTime
label12
BTFSC gbl_gpio,5
GOTO label13
INCF gbl_lTime, F
MOVLW 0x13
MOVWF delay_10us_00000_arg_del
CALL delay_10us_00000
GOTO label12
label13
MOVLW 0x06
SUBWF gbl_lTime, W
BTFSC STATUS,C
BSF GetSIRC_00000_1_ir_cmd,6
INCF GetSIRC_00000_1_x, F
GOTO label10
label14
CLRF GetSIRC_00000_1_x
label15
MOVLW 0x05
SUBWF GetSIRC_00000_1_x, W
BTFSC STATUS,C
GOTO label19
BCF STATUS,C
RRF GetSIRC_00000_1_ir_add, F
label16
BTFSC gbl_gpio,5
GOTO label16
CLRF gbl_lTime
label17
BTFSC gbl_gpio,5
GOTO label18
INCF gbl_lTime, F
MOVLW 0x13
MOVWF delay_10us_00000_arg_del
CALL delay_10us_00000
GOTO label17
label18
MOVLW 0x06
SUBWF gbl_lTime, W
BTFSC STATUS,C
BSF GetSIRC_00000_1_ir_add,4
INCF GetSIRC_00000_1_x, F
GOTO label15
label19
MOVF GetSIRC_00000_arg_address, W
MOVWF FSR
MOVF GetSIRC_00000_1_ir_add, W
MOVWF INDF
MOVF GetSIRC_00000_arg_command, W
MOVWF FSR
MOVF GetSIRC_00000_1_ir_cmd, W
MOVWF INDF
RETURN
; } GetSIRC function end
delay_10us_00000
; { delay_10us ; function begin
label1
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ delay_10us_00000_arg_del, F
GOTO label1
RETURN
; } delay_10us function end