debug_trig MACRO
CPL P1_0
ENDM
//宏定义PID采样值,NZRI编码之后,LSB
PID_ACK EQU 02h
PID_SETUP EQU 08h
PID_OUT EQU 0Ah
PID_IN EQU 0Bh
PID_DATA1 EQU 0Ch
PID_DATA0 EQU 0Dh
SAMPLE_PIN BIT P0_0
// r0里面存正在接收的数据, r7为接收数据长度, r6为接收buffer指针, r5采样总线
CSEG AT 00003H
sjmp pid_sample
PID_TABLE: DB
PID_SETUP, LOW(setup_preprocess), HIGH(setup_preprocess),
PID_DATA0, LOW(data0_preprocess), HIGH(data0_preprocess),
PID_DATA1, LOW(data_process), HIGH(data_process),
PID_IN, LOW(in_process), HIGH(in_process),
PID_ACK, LOW(ack_process), HIGH(ack_process),
PID_OUT, LOW(out_procsee), HIGH(out_procsee)
ack_process:
ret
setup_preprocess:
ret
out_procsee:
ret
in_process:
ret
data_process:
ret
data0_preprocess:
mov r2, #08h //采集Byte数,采集8byte标准请求
mov r1, #07h //每个byte采样次数 setup采7次
nop
pid_sample:
mov a, r0 //数据暂存到A
debug_trig
mov c, SAMPLE_PIN //采样总线
rlc a //数据位右移
mov r0, a
djnz r1, pid_sample
get_pid_process_start:
mov DPTR, #PID_TABLE
check_pid:
clr a
MOVC A, @A+DPTR
xrl a, r0
jnz next_pid //如果PID不匹配,取下一个比较
inc DPTR
MOVC A, @A+DPTR
mov r0, a
inc DPTR
clr a
MOVC A, @A+DPTR
mov DPH, a
mov DPL, r0
CLR A
JMP @A+DPTR
next_pid: //此处有可能需要处理无法识别的PID
inc DPTR
inc DPTR
inc DPTR
sjmp check_pid
//不认识的PID类型
avlid_pid:
sjmp avlid_pid