版主,我附上用汇编做的程序,根据实际需要,我要把该程序用verilog hdl给描述出来。请您过目,谢谢。
;//======================================
VOC_DETECT:
MOV R3,#00H ;//READ COUNTER
VOC_DETECT_20:
CLR TF0
CLR P2.5 ;//ENABLE ADC0804
MOV R0,#0FFH ;//START ADC0804
MOV A,#0FFH
MOVX @R0,A
MOV R4,#00H
DJNZ R4,$
MOVX A,@R0
SETB P2.5 ;//DISABLE ADC0804
MOV TEMP_MEAS,A
CLR C
SUBB A,#32H ;//50℃
JC VOC_DETECT_10
INC R3
MOV A,R3
CLR C
SUBB A,#200 ;//200 COUNTER
JC VOC_DETECT_20
RET
VOC_DETECT_10:
CLR C
MOV A,#0D4H ;//#D4H-->A,IF(28H)>2BH=43℃
ADD A,TEMP_MEAS ;//(28H)
MOV R1,#0BH ;//#14H-->R0
JC VOC_DETECT_30
MOV R1,#00H
MOV A,TEMP_MEAS
CPL A ;//FFH-(28H)+04H+04H
ADD A,#04H ;//GAP=4℃
MOV TEMP_MEAS,A
JC VOC_DETECT_30
VOC_DETECT_40:
MOV A,#04H ;//GAP=4℃
ADD A,TEMP_MEAS
MOV TEMP_MEAS,A
JC VOC_DETECT_30 ;//C=1,JUMP,IF(28H)<08H
INC R1 ;//R0++,TAB POINTER
AJMP VOC_DETECT_40
VOC_DETECT_30:
MOV A,R1
MOV B,A ;//SAVE VOC TABLE POINTER
CALL INK_TABLE_VOC ;//FROM TEMP FIND VISO
CALL MEAS_SOLV_ON ;//测量电磁阀开/关循环(2次)
MOV R6,#00H ;//COUNT:256*256
MOV R7,#00H
MOV TMOD,#11H ;//T1 16BIT,T0 16 BIT
VOC_DETECT_B0:
MOV TL0,#60H ;//T0:3.9MS
MOV TH0,#0F8H
SETB TR0
CLR TF0
JB FAULT_PORT,VOC_DETECT_B1
CALL SEND_FAULT_DATA ;//CHK P24,IF=0,SEND FAULT MESSGE,IF P24=1,CLOSE JETSTART,OPEN RED
VOC_DETECT_B1:
MOV R5,#10
VOC_DETECT_60:
CLR C
JB TF0,VOC_DETECT_50 ;//TF0=1?
VOC_DETECT_90:
JNB BALL_DET,VOC_DETECT_60 ;//BALL_DET=0?
DJNZ R5,VOC_DETECT_70 ;//REPEAT 10 TIMES
AJMP VOC_DETECT_80
VOC_DETECT_70:
MOV R4,#09H ;//DELAY 40us
DJNZ R4,$
AJMP VOC_DETECT_90
;//======================================
;//VISC TIME COUNT(JUDGE IF 3 MEASUREMENT
;//CYCLES END---13S+107S+13S+107S+13S=253S)
;//======================================
VOC_DETECT_50:
INC R6 ;//COUNTER
MOV A,R6
JZ VOC_DETECT_A0
AJMP VOC_DETECT_B0
VOC_DETECT_A0:
INC R7 ;//COUNTER
MOV A,R7
JZ VOC_DETECT_C0
AJMP VOC_DETECT_B0
VOC_DETECT_C0:
MOV TMOD,#12H ;//T1 16BIT,T0 8 BIT
SETB VISCO_HI
SETB VISCO_LOW
CLR P2.2 ;//VOR LED ON
RET
;//======================================
;//DEFINE IF ALARM AND OPEN SOLV SOLEN
;//======================================
VOC_DETECT_80:
MOV TMOD,#12H ;//T1 16BIT,T0 8 BIT
CLR TR0 ;//STOP TIMER/COUNTER
MOV A,R6
ORL A,R7
JNZ VOC_DETECT_81
CLR P2.2 ;//VOR LED ON
SETB VISCO_HI
SETB VISCO_LOW
AJMP VOC_DETECT_M0
VOC_DETECT_81:
SETB P2.2 ;//VOR LED OFF
MOV A,B ;//TEMP INDEX
CALL INK_TABLE_VOC ;//SEARCH TABLE
ADD A,#1
CLR C
RLC A
MOV R4,A ;//THOERY VALUE->R4
ADD A,#32
MOV THOERY32,A ;//THOERY VALUE+25
MOV A,R4 ;//THOERY VALUE
ADD A,#2
MOV THOERY2,A ;//THOERY VALUE+10
CLR C
MOV A,R4 ;//THOERY VALUE
SUBB A,#10
JC VOC_DETECT_D0 ;//FAULT ON
MOV THOERY10,A ;//THOERY VALUE-10
CLR C
MOV A,R4 ;//THOERY VALUE
SUBB A,#32
JC VOC_DETECT_D0 ;//FAULT ON
MOV R5,A ;//THOERY VALUE-25
MOV A,R7 ;//TEST VALUE
SUBB A,#10
JC VOC_DETECT_D0 ;//FAULT ON
MOV A,R7 ;//TEST VALUE
SUBB A,R4 ;//THOERY VALUE
JNC VOC_DETECT_E0 ;//TEST VALUE>THOERY VALUE
CLR C
MOV A,R7 ;//TEST VALUE
SUBB A,R5 ;//THORY VALUE-20
JC VOC_DETECT_D0 ;//FAULT ON,TEST VALUE
AJMP VOC_DETECT_F0 ;//NO FAULT,TEST VALUE>THORY VALUE-32
VOC_DETECT_E0:
MOV A,R7 ;//TEST VALUE
SUBB A,THOERY2 ;//THOERY VALUE+5
JC VOC_DETECT_F0 ;//NO FAULT,TEST VALUE
MOV A,R7 ;//TEST VALUE
SUBB A,THOERY32 ;//THOERY VALUE+20
JC VOC_DETECT_G0 ;//NO FALUT,SOLV ON,TEST VALUE
CLR P2.2 ;//VOR LED ON
CLR VISCO_HI ;//墨水太浓
SETB VISCO_LOW
AJMP VOC_DETECT_H0
VOC_DETECT_G0:
SETB P2.2 ;//VOR LED OFF
SETB VISCO_HI
SETB VISCO_LOW
VOC_DETECT_H0:
MOV R5,#30
ORL P1,#80H ;//P17,SOLV SOLEN ON
VOC_DETECT_L0:
MOV R6,#00H
VOC_DETECT_K0:
MOV TH0,#00H ;//TIMER START:0.512MS
MOV TL0,#00H
SETB TR0 ;//START COUNTER
VOC_DETECT_J0:
JBC TF0,VOC_DETECT_I0 ;//T0 OVER
AJMP VOC_DETECT_J0
VOC_DETECT_I0:
DJNZ R6,VOC_DETECT_K0 ;//DELAY:30*256*0.512=3.9S
DJNZ R5,VOC_DETECT_L0
AJMP VOC_DETECT_M0
;//======================================
VOC_DETECT_D0: ;//墨水太淡
CLR P2.2 ;//VISC LED ON
CLR VISCO_LOW
SETB VISCO_HI
AJMP VOC_DETECT_M0
VOC_DETECT_F0:
SETB P2.2 ;//VOR LED OFF
SETB VISCO_HI
SETB VISCO_LOW
VOC_DETECT_M0: ;//SOLS OPERATE:ON OR OFF
ANL P1,#3FH ;//P1.7,P1.6=0,SOLV SOL AND MEAS SOL OFF
VOC_DETECT_S0:
CLR C
MOV A,R7
SUBB A,#78H ;//120S
JNC VOC_DETECT_N0
VOC_DETECT_R0:
MOV TMOD,#11H ;//T1 16BIT,T0 16 BIT
MOV TL0,#12H ;//T0:7.1MS
MOV TH0,#0F2H
SETB TR0 ;//START COUNTER
JB FAULT_PORT,VOC_DETECT_Q0 ;//SEND FAULT MESSAGE
CALL SEND_FAULT_DATA ;//CHK P24,IF=0,SEND FAULT MESSGE,IF P24=1,CLOSE JETSTART,OPEN RED
VOC_DETECT_Q0:
JBC TF0,VOC_DETECT_P0 ;//T0 OVER
AJMP VOC_DETECT_Q0
VOC_DETECT_P0:
INC R6 ;//COUNTER L.
MOV A,R6
JNZ VOC_DETECT_R0
INC R7 ;//COUNTER H.
AJMP VOC_DETECT_S0
VOC_DETECT_N0:
MOV TMOD,#12H ;//T1 16BIT,T0 8 BIT
RET
;//======================================
;//SEARCH INK VISC TABLE.
;//======================================
INK_TABLE_VOC:
ORL P1,#03H
MOV A,P1
ANL A,#03H
XRL A,#03H
CJNE A,#00H,INK_TABLE_VOC_10 ;//OFF/OFF:WT5206
MOV DPTR,#INK_WT5206
AJMP INK_TABLE_VOC_20
INK_TABLE_VOC_10:
CJNE A,#01H,INK_TABLE_VOC_30 ;//ON/OFF:BK2501
MOV DPTR,#INK_BK2501
AJMP INK_TABLE_VOC_20
INK_TABLE_VOC_30:
CJNE A,#02H,INK_TABLE_VOC_40 ;//OFF/ON:BK6901
MOV DPTR,#INK_BK6901
AJMP INK_TABLE_VOC_20
INK_TABLE_VOC_40:
MOV DPTR,#INK_BK0701 ;//ON/ON:BK0701
INK_TABLE_VOC_20:
MOV A,R1
MOV B,A
ANL A,#0FH
MOVC A,@A+DPTR
MOV TEMP_MEAS,A ;//SAVE TO RAM:(28H)=VISC TIME
RET
;//======================================
;//ON/OFF MEASURE SOLV 2 TIMES
;//======================================
MEAS_SOLV_ONOFF:
MOV R3,#02H ;//LOOP COUNTER
MEAS_SOLV_ONOFF_10:
CALL MEAS_SOLV_ON ;//MEASURE SOL PULSE,CHK P24
CALL DELAY_107s ;//SAVE TO 1EH,1FH,1FH,20H,20H,21H
DJNZ R3,MEAS_SOLV_ONOFF_10
RET
;//======================================
;//NAME:MEAS_SOL_ON
;//FUNCTION:OPEN MEASURE SOLV 9S
;//RESOURCE:R5,R6,A
;//======================================
MEAS_SOLV_ON:
MOV R5,#00H
MEAS_SOLV_ON_40:
ORL P1,#40H ;//P16=1,MEASURE SOLEN ON
MOV R6,#105
SETB TR0 ;//START COUNTER
MEAS_SOLV_ON_30:
MOV TL0,#00H ;//START VALUE.
MOV TH0,#00H
CLR TF0
JB FAULT_PORT,MEAS_SOLV_ON_10
CALL SEND_FAULT_DATA ;//CHK P24,IF=0,SEND FAULT MESSGE,IF P24=1,CLOSE JETSTART,OPEN RED
MEAS_SOLV_ON_10:
JBC TF0,MEAS_SOLV_ON_20 ;//T0 OVER
AJMP MEAS_SOLV_ON_10
MEAS_SOLV_ON_20:
DJNZ R6,MEAS_SOLV_ON_30
DJNZ R5,MEAS_SOLV_ON_40
ANL P1,#3FH ;//0011B,P17=0(SOL SOLEN),P16=0(MEASURE SOLEN),OFF.
RET