#include "iodefine.inc" #include "iodefine_ext.inc" .extern process .extern process2 .extern process3 .global _cnt_int_lo .global _cnt_int_hi .global _cnt_deint_lo .global _cnt_deint_hi .global _cnt_sign #define stAZ 0x00 #define stINT 0x04 #define stDEINT 0x08 #define stIOZ 0x0C #define P20 0xFFF02.0 #define P137 0xFFF0D.7 #define TRIGGER P20 .section .data, "a" .align 2 state: .byte 0, 0 ticks: .byte 0xFF _cnt_int_lo: .byte 0, 0 _cnt_int_hi: .byte 0, 0 _cnt_deint_lo: .byte 0, 0 _cnt_deint_hi: .byte 0, 0 _cnt_sign: .byte 0 .align 2 cnt_tmr01: .byte 0, 0 ;;; =============================================================================================== ;;; TMR00 interrupt service routine ;; ================================================================================================ isr_tmr00: push AX movw AX, #st_table addw AX, !state br AX st_table: br !!st_az br !!st_int br !!st_deint ;;; ---------------------------------------------------------------------- ;;; AutoZero ;;; ---------------------------------------------------------------------- st_az: cmp !ticks, #120 ; sknh ; if(tick > 40) mov !ticks, #0xFF ; tick = -1; ; inc !ticks ; tick++ ; ------------------------------------ st_az_0: cmp0 !ticks ; if ticks = 0 then bnz $st_az_1 ; begin ; set1 TRIGGER ; TRIGGER := 1; mov P4, #4 ; TC500A := AutoZero ; pop ax ; reti ; RETI; ; end; ; ------------------------------------ st_az_1: cmp !ticks, #1 ; if ticks = 1 then bnz $st_az_2 ; begin ; clr1 TRIGGER ; TRIGGER := 0; pop ax ; RETI; reti ; end; ; ------------------------------------ st_az_2: cmp !ticks, #2 ; if ticks = 2 then bnz $st_az_3 ; begin ; call !!_process ; process(); pop ax ; RETI; reti ; end; ; ------------------------------------ st_az_3: cmp !ticks, #3 ; if ticks = 3 then bnz $st_az_4 ; begin ; call !!_process2 ; process2(); pop ax ; RETI; reti ; end; ; ------------------------------------ st_az_4: cmp !ticks, #4 ; if ticks = 4 then bnz $st_az_38 ; begin ; call !!_process3 ; process3(); pop ax ; RETI; reti ; end; ; ------------------------------------ st_az_38: cmp !ticks, #120 ; if ticks = 120 then (40 !!) bnz $st_az_99 ; begin ; mov !ticks, #0xFF ; ticks := -1; mov !state, #stINT ; state := Integrate; ;br $st_int_00 ; end; st_az_99: pop ax ; RETI; reti ; ;;; ---------------------------------------------------------------------- ;;; Integrate/Deintegrate phase ;;; ---------------------------------------------------------------------- st_int: cmp !ticks, #40 ; sknh ; if(tick > 40) mov !ticks, #0xFF ; tick = -1; ; inc !ticks ; tick++ ; End of Integrate phase ; - save TMR01 counters ; - stop TMR00 st_int_39: cmp !ticks, #40 bnz $st_int_0 ei ; stop TMR00 ; ---------------------------- set1 !TT0L.0 ; trigger to stop ; clr1 TMIF00 ; clear TMR01 interrupt flag set1 TMMK00 ; disable TMR01 interrupt ; start Deintegrate phase ; ---------------------------- mov P4, #6 ; TC500A <= stDEINT sel RB1 ; di ; movw AX, !TCR01 ; integration time movw !_cnt_int_lo, AX ; movw AX, !cnt_tmr01 ; movw !_cnt_int_hi, AX ; ei ; sel RB0 ; (TCA reacts on CMP in 2 us) st_int_391: bt P137, $st_int_391 ; wait for CMP falling edge mov P4, #0 ; TCA500A <= stIOZ ; set1 !TT0L.1 ; stop TMR01 ; st_int_392: bf P137, $st_int_392 ; wait for CMP rising edge mov P4, #4 ; TCA500A <= stAZ sel RB1 ; movw AX, !TCR01 ; integration time movw !_cnt_deint_lo, AX ; movw AX, !cnt_tmr01 ; movw !_cnt_deint_hi, AX ; sel RB0 ; ; restart TMR00 ; ---------------------------- clr1 TMIF00 ; clear TMR01 interrupt flag clr1 TMMK00 ; enable TMR01 interrupt ; set1 !TS0L.0 ; trigger to start ; move state to stAZ ; ---------------------------- mov !ticks, #0xFF ; clear ticks mov !state, #stAZ ; set state pop ax reti ; ------------------ ; start tmr01 ; ------------------ st_int_0: cmp0 !ticks bnz $st_int_35 st_int_00: clr1 TMIF01 ; clear TMR01 interrupt flag clr1 TMMK01 ; enable TMR01 interrupt set1 !TS0L.1 ; enable TMR01 mov P4,#2 ; TC500A <= integrate clrw ax movw !cnt_tmr01, ax ; clear TMR01 overflow counter pop ax reti st_int_35: cmp !ticks,#35 bnz $st_int_99 bf P137, $st_int_351 mov !_cnt_sign, #0 reti st_int_351: mov !_cnt_sign, #1 pop ax reti st_int_99: pop ax reti st_deint: pop ax reti .end