📄 usbjoy32.asm
字号:
mov A, ffh ; bug fix by DEF
and A, [new_task] ; new_task is active if = 0
jnz TaskLoop ; wait for next time slice
inc [new_task]
mov A, [configuration]
cmp A, 01h
jnz no_event_task
mov A, [ep1_stall]
cmp A, FFh
jz no_event_task
mov A, [task_number] ; jump to current tasklet
asl ; x2 because jmp is 2 instructions
cmp A, (end_task_table - task_table) ; check to ensure not out of range
jc .DoTheJump
mov A, 00h
mov [task_number], A ; user may want to add own error recovery code here
.DoTheJump:
jacc task_table ; execute the selected task
XPAGEOFF
task_table:
jmp Task0
jmp Task1
jmp Task2
jmp Task3
jmp Task4
jmp Task5
jmp Task6
jmp Task7
jmp Task8
jmp Task9
jmp Task10
jmp Task11
jmp Task12
jmp Task13
jmp Task14
jmp Task15
end_task_table:
XPAGEON
no_event_task:
jmp TaskLoop
;=========================================================
; Task 0: Read Resistor Value for x_R1
;=========================================================
Task0:
mov a, 30h
iowr Global_Interrupt ;Enable only Capture interrupts
;**********************************************
;P0.0 = CMOS Hi-Z
;P0.1 = TTL Hi-Z
;P0.2 = High Sink
;P0.3/P0.4/P0.5/P0.6/P0.7 = CMOS Hi-Z
;Port0_Mode0 = 00000100
;Port0_Mode1 = 00000100
;Port0 = 00000010
;**********************************************
mov a, 04h ;Set port and port mode values to discharge capacitor
iowr Port0_Mode0 ;See table above
iowr Port0_Mode1
mov a, 02h
iowr Port0
mov a, 00h ;wait about 500usec (6000 cycles) for Capture_timer A & B ISRs, then recharge cap and do math below
mov [discharge_cnt], a
.discharge_loop:
inc [discharge_cnt]
mov a, CCh
cmp a, [discharge_cnt]
iowr Watchdog
jnz .discharge_loop
mov a, 00h
iowr Global_Interrupt ;Disable global interrupts
mov a, 00h
mov [rollover_bit], a ;rollover_bit set to 00h, but may need to change to 01h, if TTL value is < CMOS value
iord Capture_TimerA_Falling ;Read CaptureTimerA 8 bits, CMOS captured time value (always earlier and usually the smaller value)
mov [capture_a_temp], a
iord Capture_TimerB_Falling ;Read CaptureTimerB 8 bits, TTL captured time value (always earlier and usually the larger value)
mov [capture_b_temp], a
sub a, [capture_a_temp] ;Subtract CMOS time from TTL time to see if timer rolled over
jnc .no_timer_rollover ;If TTL value is > CMOS value, the timer did not roll over and we keep rollover_bit = 00h
mov a, 01h ;In the exception that TTL time value is < CMOS time value, we make rollover_bit = 01h
mov [rollover_bit], a
.no_timer_rollover:
mov a, FEh ;Recharges the capacitor, P0.0 is Hi-Z CMOS always, others set to Strong Drive CMOS
iowr Port0_Mode0
iowr Port0_Mode1
iowr Port0
SUB16x16 rollover_bit, capture_b_temp, 00h, capture_a_temp, always_zero, x_R1_diff1_new
mov a, 05h ;Re-Enable 1ms,USBReset interrupts
iowr Global_Interrupt
jmp TaskLoop
;=========================================================
; Task 1: Read Resistor Value for x_R2
;=========================================================
Task1:
mov a, 30h
iowr Global_Interrupt ;Enable only Capture interrupts
;**********************************************
;P0.0 = CMOS Hi-Z
;P0.1 = TTL Hi-Z
;P0.2 = CMOS Hi-Z
;P0.3 = High Sink
;P0.4/P0.5/P0.6/P0.7 = CMOS Hi-Z
;Port0_Mode0 = 00001000
;Port0_Mode1 = 00001000
;Port0 = 00000010
;**********************************************
mov a, 08h ;Set port and port mode values to discharge capacitor
iowr Port0_Mode0 ;See table above
iowr Port0_Mode1
mov a, 02h
iowr Port0
mov a, 00h ;wait about 500usec (6000 cycles) for Capture_timer A & B ISRs, then recharge cap and do math below
mov [discharge_cnt], a
.discharge_loop:
inc [discharge_cnt]
mov a, CCh
cmp a, [discharge_cnt]
iowr Watchdog
jnz .discharge_loop
mov a, 00h
iowr Global_Interrupt ;Disable global interrupts
mov a, 00h
mov [rollover_bit], a ;rollover_bit set to 00h, but may need to change to 01h, if TTL value is < CMOS value
iord Capture_TimerA_Falling ;Read CaptureTimerA 8 bits, CMOS captured time value (always earlier and usually the smaller value)
mov [capture_a_temp], a
iord Capture_TimerB_Falling ;Read CaptureTimerB 8 bits, TTL captured time value (always earlier and usually the larger value)
mov [capture_b_temp], a
sub a, [capture_a_temp] ;Subtract CMOS time from TTL time to see if timer rolled over
jnc .no_timer_rollover ;If TTL value is > CMOS value, the timer did not roll over and we keep rollover_bit = 00h
mov a, 01h ;In the exception that TTL time value is < CMOS time value, we make rollover_bit = 01h
mov [rollover_bit], a
.no_timer_rollover:
mov a, FEh ;Recharges the capacitor, P0.0 is Hi-Z CMOS always, others set to Strong Drive CMOS
iowr Port0_Mode0
iowr Port0_Mode1
iowr Port0
SUB16x16 rollover_bit, capture_b_temp, 00h, capture_a_temp, always_zero, x_R2_diff1_new
mov a, 05h ;Re-Enable 1ms,USBReset interrupts
iowr Global_Interrupt
jmp TaskLoop
;========================================================
; Task 2: read fire buttons
;========================================================
Task2:
iord Port1
and A, ffh
mov [button_debounce], A
jmp TaskLoop
;=========================================================
; Task 3: Read Resistor Value for y_R1
;=========================================================
Task3:
mov a, 30h
iowr Global_Interrupt ;Enable only Capture interrupts
;**********************************************
;P0.0 = CMOS Hi-Z
;P0.1 = TTL Hi-Z
;P0.4 = High Sink
;P0.2/P0.3/P0.5/P0.6/P0.7 = CMOS Hi-Z
;Port0_Mode0 = 00010000
;Port0_Mode1 = 00010000
;Port0 = 00000010
;**********************************************
mov a, 10h ;Set port and port mode values to discharge capacitor
iowr Port0_Mode0 ;See table above
iowr Port0_Mode1
mov a, 02h
iowr Port0
mov a, 00h ;wait about 500usec (6000 cycles) for Capture_timer A & B ISRs, then recharge cap and do math below
mov [discharge_cnt], a
.discharge_loop:
inc [discharge_cnt]
mov a, CCh
cmp a, [discharge_cnt]
iowr Watchdog
jnz .discharge_loop
mov a, 00h
iowr Global_Interrupt ;Disable global interrupts
mov a, 00h
mov [rollover_bit], a ;rollover_bit set to 00h, but may need to change to 01h, if TTL value is < CMOS value
iord Capture_TimerA_Falling ;Read CaptureTimerA 8 bits, CMOS captured time value (always earlier and usually the smaller value)
mov [capture_a_temp], a
iord Capture_TimerB_Falling ;Read CaptureTimerB 8 bits, TTL captured time value (always earlier and usually the larger value)
mov [capture_b_temp], a
sub a, [capture_a_temp] ;Subtract CMOS time from TTL time to see if timer rolled over
jnc .no_timer_rollover ;If TTL value is > CMOS value, the timer did not roll over and we keep rollover_bit = 00h
mov a, 01h ;In the exception that TTL time value is < CMOS time value, we make rollover_bit = 01h
mov [rollover_bit], a
.no_timer_rollover:
mov a, FEh ;Recharges the capacitor, P0.0 is Hi-Z CMOS always, others set to Strong Drive CMOS
iowr Port0_Mode0
iowr Port0_Mode1
iowr Port0
SUB16x16 rollover_bit, capture_b_temp, 00h, capture_a_temp, always_zero, y_R1_diff1_new
mov a, 05h ;Re-Enable 1ms,USBReset interrupts
iowr Global_Interrupt
jmp TaskLoop
;===========================================================
;
; Task 4: Read Resistor Value for y_R2
;============================================================
Task4:
mov a, 30h
iowr Global_Interrupt ;Enable only Capture interrupts
;**********************************************
;P0.0 = CMOS Hi-Z
;P0.1 = TTL Hi-Z
;P0.5 = High Sink
;P0.2/P0.3/P0.4/P0.6/P0.7 = CMOS Hi-Z
;Port0_Mode0 = 00100000
;Port0_Mode1 = 00100000
;Port0 = 00000010
;**********************************************
mov a, 20h ;Set port and port mode values to discharge capacitor
iowr Port0_Mode0 ;See table above
iowr Port0_Mode1
mov a, 02h
iowr Port0
mov a, 00h ;wait about 500usec (6000 cycles) for Capture_timer A & B ISRs, then recharge cap and do math below
mov [discharge_cnt], a
.discharge_loop:
inc [discharge_cnt]
mov a, CCh
cmp a, [discharge_cnt]
iowr Watchdog
jnz .discharge_loop
mov a, 00h
iowr Global_Interrupt ;Disable global interrupts
mov a, 00h
mov [rollover_bit], a ;rollover_bit set to 00h, but may need to change to 01h, if TTL value is < CMOS value
iord Capture_TimerA_Falling ;Read CaptureTimerA 8 bits, CMOS captured time value (always earlier and usually the smaller value)
mov [capture_a_temp], a
iord Capture_TimerB_Falling ;Read CaptureTimerB 8 bits, TTL captured time value (always earlier and usually the larger value)
mov [capture_b_temp], a
sub a, [capture_a_temp] ;Subtract CMOS time from TTL time to see if timer rolled over
jnc .no_timer_rollover ;If TTL value is > CMOS value, the timer did not roll over and we keep rollover_bit = 00h
mov a, 01h ;In the exception that TTL time value is < CMOS time value, we make rollover_bit = 01h
mov [rollover_bit], a
.no_timer_rollover:
mov a, FEh ;Recharges the capacitor, P0.0 is Hi-Z CMOS always, others set to Strong Drive CMOS
iowr Port0_Mode0
iowr Port0_Mode1
iowr Port0
SUB16x16 rollover_bit, capture_b_temp, 00h, capture_a_temp, always_zero, y_R2_diff1_new
mov a, 05h ;Re-Enable 1ms,USBReset interrupts
iowr Global_Interrupt
jmp TaskLoop
;========================================
; Task 5: Read Resistor Value for z_R1
;========================================
Task5:
mov a, 30h
iowr Global_Interrupt ;Enable only Capture interrupts
;**********************************************
;P0.0 = CMOS Hi-Z
;P0.1 = TTL Hi-Z
;P0.6 = High Sink
;P0.2/P0.3/P0.4/P0.5/P0.7 = CMOS Hi-Z
;Port0_Mode0 = 01000000
;Port0_Mode1 = 01000000
;Port0 = 00000010
;**********************************************
mov a, 40h ;Set port and port mode values to discharge capacitor
iowr Port0_Mode0 ;See table above
iowr Port0_Mode1
mov a, 02h
iowr Port0
mov a, 00h ;wait about 500usec (6000 cycles) for Capture_timer A & B ISRs, then recharge cap and do math below
mov [discharge_cnt], a
.discharge_loop:
inc [discharge_cnt]
mov a, CCh
cmp a, [discharge_cnt]
iowr Watchdog
jnz .discharge_loop
mov a, 00h
iowr Global_Interrupt ;Disable global interrupts
mov a, 00h
mov [rollover_bit], a ;rollover_bit set to 00h, but may need to change to 01h, if TTL value is < CMOS value
iord Capture_TimerA_Falling ;Read CaptureTimerA 8 bits, CMOS captured time value (always earlier and usually the smaller value)
mov [capture_a_temp], a
iord Capture_TimerB_Falling ;Read CaptureTimerB 8 bits, TTL captured time value (always earlier and usually the larger value)
mov [capture_b_temp], a
sub a, [capture_a_temp] ;Subtract CMOS time from TTL time to see if timer rolled over
jnc .no_timer_rollover ;If TTL value is > CMOS value, the timer did not roll over and we keep rollover_bit = 00h
mov a, 01h ;In the exception that TTL time value is < CMOS time value, we make rollover_bit = 01h
mov [rollover_bit], a
.no_timer_rollover:
mov a, FEh ;Recharges the capacitor, P0.0 is Hi-Z CMOS always, others set to Strong Drive CMOS
iowr Port0_Mode0
iowr Port0_Mode1
iowr Port0
SUB16x16 rollover_bit, capture_b_temp, 00h, capture_a_temp, always_zero, z_R1_diff1_new
mov a, 05h ;Re-Enable 1ms,USBReset interrupts
iowr Global_Interrupt
jmp TaskLoop
;========================================
; Task 6: Read Resistor Value for z_R2
;========================================
Task6:
mov a, 30h
iowr Global_Interrupt ;Enable only Capture interrupts
;**********************************************
;P0.0 = CMOS Hi-Z
;P0.1 = TTL Hi-Z
;P0.5 = High Sink
;P0.2/P0.3/P0.4/P0.6/P0.7 = CMOS Hi-Z
;Port0_Mode0 = 10000000
;Port0_Mode1 = 10000000
;Port0 = 00000010
;**********************************************
mov a, 80h ;Set port and port mode values to discharge capacitor
iowr Port0_Mode0 ;See table above
iowr Port0_Mode1
mov a, 02h
iowr Port0
mov a, 00h ;wait about 500usec (6000 cycles) for Capture_timer A & B ISRs, then recharge cap and do math below
mov [discharge_cnt], a
.discharge_loop:
inc [discharge_cnt]
mov a, CCh
cmp a, [discharge_cnt]
iowr Watchdog
jnz .discharge_loop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -