本帖最后由 Kxuan163 于 2020-12-24 20:31 编辑
【控制系统的硬件】:
51单片机系统板,EPROM27128(贮存程序机器码),键盘扫描及显示芯片8279,
扩展I/O口芯片8155, EEPROM2864(贮存注射时间数据),
4N25芯片(作+5v电源与+12V电源隔离),
反相驱动芯片MCT1413(驱动继电器),MY2N继电器(控制流接触器线包通/断电),
流接触器(控制电磁阀、泵、搅拌器,风机...启/停)。
【51汇编语言源程序】原创 Kxuan163
;; RAM地址分配及用途:
;;(40~41)byte: LED DPH, LED DPL
;;(42~43)byte: HI No, low No
;;(44~47)byte: 注射持续时间
;;(48~4b)byte: 注射后的停留时间
;;(4c~4f)byte: 注射后的清洗时间
;;(50~53)byte: 注射后的吹风时间
;;(5b)byte: 循环时间c
;;(5c)byte: 输出控制值
;;(5d)byte: 手动控制键入值
;;(2f)byte (7f)bit: JT0~JT40触键标志
ORG 0000H
FIRST: AJMP MAIN
NOP
NOP
NOP
INT0: AJMP MAIN
NOP
NOP
NOP
Time0: AJMP MAIN
NOP
NOP
NOP
INT1: AJMP MAIN
NOP
NOP
NOP
DW 0FFFFH
DW 0FFFFH
ORG 0030H
MAIN: CLR EA
ACALL DLY40MS
MOV SP,#60H ;Stack Point
CLRAM: MOV R0,#40H ;CLear RAM byte 40~60
CLRAM1: MOV @R0,#00H
INC R0
CJNE R0,#61H,CLRAM1
ACALL READACB ;READ After.Clear.Blow time
CLEARN0:MOV DPTR,#4100H ;CLear Time no 00
CLR A
MOVX @DPTR,A
ACALL DLY10MS
INC DPL
MOVX @DPTR,A
ACALL DLY10MS
START: ACALL SET
MOV 5CH,#00H
ACALL OUT ;ject.clear.blow off
MOV 42H,#00H ;first H No
MOV 43H,#00H ;first W No
ACALL LED1 ;display H
ACALL LED2 ;display W
ACALL XST ;display Time
HEADKEY:NOP ;scan head key
ACALL FEEDDOG
MOV DPTR,#7000H
MOV R4,#01 ;T0 TO T24
ACALL SCU9U10 ;SCan U9
JB 7FH ,GOTNO ;hav hit T0~T24 key
MOV DPTR,#6000H
MOV R4,#25 ;T25 TO T40
ACALL SCU9U10 ;SCan U10
JB 7FH,GOTNO ;hav hit T25~T40 key
AJMP SCCLBL ;SCan Clear.Blow key
GOTNO: AJMP TIMENO ;goto time No
SCU9U10:CLR 7FH ;clear hit T0~T40 key flag
PORTA: MOVX A,@DPTR
JZ PORTB
ACALL DESHAKE ;anti key shake & disturbed
CJNE A,5DH,PORTB
SETB 7FH
RET
PORTB: MOV A,#08
ADD A,R4
MOV R4,A
INC DPL
MOVX A,@DPTR
JZ PORTC
ACALL DESHAKE ;anti key shake & disturbed
CJNE A,5DH,PORTC
SETB 7FH
RET
PORTC: MOV R3,DPH
CJNE R3,#60H,U9C
U10C: RET ;no scan unit 10 port C
U9C: MOV A,#08 ;scan unit 9 port C
ADD A,R4
MOV R4,A
INC DPL
MOVX A,@DPTR
JZ U910RET
ACALL DESHAKE ;anti key shake & disturbed
CJNE A,5DH,U910RET
SETB 7FH
U910RET:RET ;scan U9U10 RET
SCCLBL: MOV DPTR,#6002H ;SCan CLear.BLow key
MOVX A,@DPTR
ACALL DESHAKE
CJNE A,5DH,NOHEADK
SCCLEAR:JB ACC.7,GOCLEAR
SCBLOW: JB ACC.6,GOBLOW
NOHEADK:AJMP KEYBOAD ;NO hit HEAD Key
GOCLEAR:AJMP QX
GOBLOW: AJMP CF
DW 0000H
TIMENO: NOP ;time NO
ACALL CHNUM ;check NUM
FLHW: MOV DPTR,#TNOB ;devide NO-Hi & NO-loW
MOVC A,@A+DPTR
PUSH ACC
ANL A,#0F0H
SWAP A
MOV 42H,A
POP ACC
ANL A,#0FH
MOV 43H,A
ACALL LED1
ACALL LED2
ACALL XST ;read & display time
AJMP ZS ;goto ject
CHNUM: MOV R2,#00 ;check NUM
CHBIT: JB ACC.0,NUM ;check bit
CJNE R2,#07,NEXTBIT
SJMP NUM
NEXTBIT:INC R2
RR A
SJMP CHBIT
NUM: MOV A,R4
ADD A,R2
RET ;CHNUM RET
KEYBOAD:NOP ;scan keyboard - unit11 portA.portB
CLR 7EH ;clear editing flag
MOV R3,#00H ;time display begin from LED3
U11A: NOP ;unit11 port A
ACALL CIRCLE ;circle rebrush
ACALL FEEDDOG
JNB 7EH,SCU11A ;check editing flag
CHR31: CJNE R3,#01H,CHR32 ;check R3=#01
CL456: ACALL CLLED4 ;R3=#01, wait edit LED4~LED6
ACALL CLLED5
ACALL CLLED6
SJMP SCU11A
CHR32: CJNE R3,#02H,CHR33 ;check R3=#02
CL56: ACALL CLLED5 ;R3=#02, wait edit LED5~LED6
ACALL CLLED6
SJMP SCU11A
CHR33: CJNE R3,#03H,SCU11A ;chech R3=#03
CL6: ACALL CLLED6 ;R3=#03, wait edit LED6
SCU11A: MOV DPTR,#2000H ;scan unit11 portA
MOVX A,@DPTR
JZ U11B
ACALL DESHAKE
CJNE A,5DH,U11B
SJMP NUM0TO7 ;NUM 0 TO 7 key of keyboard
U11B: MOV DPTR,#2001H ;scan unit11 portB
MOVX A,@DPTR
ANL A,#0F8H
JZ NOTHITK ;not hit keyboard & headkey
ACALL DESHAKE
ANL A,#0F8H
CJNE A,5DH,NOTHITK
JB ACC.6,NUM9 ;NUM 9 key of keyboard
JB ACC.7,NUM8 ;NUM 8 key of keyboard
JB ACC.3,GOLASTW ;go DEC LOW
JB ACC.4,GONEXTW ;go ADD LOW
JB ACC.5,GONEXTH ;go ADD HI
NOTHITK:NOP ;not hit keyboard & headkey
JB 7EH,U11A ;editing
ACALL CIRCLE ;circle rebrush
AJMP HEADKEY
GOLASTW:AJMP WLAST
GONEXTW:AJMP WNEXT
GONEXTH:AJMP HNEXT
NUM0TO7:MOV R4,#00H ;NUM 0 TO 7 key of keyboard
ACALL CHNUM
SJMP EDIT
NUM8: MOV A,#08H ;NUM 8 key of keyboard
SJMP EDIT
NUM9: MOV A,#09H ;NUM 9 key of keyboard
SJMP EDIT
EDIT: PUSH ACC ;edit time data
CLR A ;T00 no edit
CJNE A,42H,CHFLAG
CJNE A,43H,CHFLAG
POP ACC
ACALL CIRCLE ;circle rebrush
CLR 7EH ;clear editing flag
AJMP HEADKEY
CHFLAG: JB 7EH,EDITING ;check editing flag
SETB 7EH ;set editing flag
EDITING:MOV A,R3
MOV B,#0BH
MUL AB
MOV DPTR,#EDLED3
JMP @A+DPTR
EDLED3: POP ACC ;edit LED3-X10sec
MOV 44H,A
ACALL LED3 ;display LED3
ACALL WAITKF1 ;wait MUM Key Free
INC R3 ;next LED
AJMP U11A
EDLED4: POP ACC ;edit LED4-X1sec
MOV 45H,A
ACALL LED4 ;display LED4
ACALL WAITKF1 ;wait MUM Key Free
INC R3 ;next LED
AJMP U11A
EDLED5: POP ACC ;edit LED5-X0.1sec
MOV 46H,A
ACALL LED5 ;display LED5
ACALL WAITKF1 ;wait MUM Key Free
INC R3 ;next LED
AJMP U11A
EDLED6: POP ACC ;edit LED6-X0.01sec
MOV 47H,A
ACALL LED6 ;display LED6
ACALL WAITKF1 ;wait MUM Key Free
CLR 7EH ;clear editing flag
AJMP W2864 ;edit end, go wrire 2864
CLLED4: CLR A
MOV DPTR,#6801H ;clear LED4
MOVX @DPTR,A
RET
CLLED5: CLR A
MOV DPTR,#6802H ;clear LED5
MOVX @DPTR,A
RET
CLLED6: CLR A
MOV DPTR,#6800H ;clear LED6
MOVX @DPTR,A
RET
WAITKF1:MOV DPTR,#2000H ;wait NUM key free
WU11A: ACALL FEEDDOG
MOVX A,@DPTR
JNZ WU11A ;wait 0~7 key free
INC DPL
WU11B: ACALL FEEDDOG
MOVX A,@DPTR
ANL A,#0C0H
JNZ WU11B ;wait 8~9 key free
RET ;WAITKF1 RET
WAITKF2:ACALL FEEDDOG ;wait H+ W+ W- key free
MOV DPTR,#2001H ;unit 11 port B
MOVX A,@DPTR
ANL A,#38H ;retain U11 PB5 PB4 PB3
JNZ WAITKF2
RET ;WAITKF2 RET
DESHAKE:MOV 5DH,A ;anti key shake & disturbed
ACALL DLY10MS
MOVX A,@DPTR
RET ;DESHAKE RET
HNEXT: MOV A,42H ;H NEXT
CJNE A,#04H,HADD
MOV 42H,#00H
SJMP HNEXT1
HADD: INC 42H ;H ADD
HNEXT1: ACALL LED1 ;display H
ACALL XST ;read & display time
ACALL WAITKF2 ;wait H+ W+ W- key free
AJMP HEADKEY ;H NEXT END
WNEXT: MOV A,43H ;W NEXT
CJNE A,#09H,WADD
MOV 43H,#00H
ACALL LED2 ;display W
SJMP HNEXT ;go H next
WADD: INC 43H ;W ADD
WNEXT1: ACALL LED2 ;display W
ACALL XST ;read & display time
ACALL WAITKF2 ;wait H+ W+ W- key free
AJMP HEADKEY ;W NEXT END
HLAST: MOV A,42H ;H LAST
CJNE A,#00H,HDEC
MOV 42H,#04H
SJMP HLAST1
HDEC: DEC 42H ;H DEC
HLAST1: ACALL LED1 ;display H
ACALL XST ;read & display time
ACALL WAITKF2 ;wait H+ W+ W- key free
AJMP HEADKEY ;H LAST END
WLAST: MOV A,43H ;W LAST
CJNE A,#00H,WDEC
MOV 43H,#09H
ACALL LED2 ;display W
SJMP HLAST
WDEC: DEC 43H ;W DEC
WLAST1: ACALL LED2 ;display W
ACALL XST ;read & display time
ACALL WAITKF2 ;wait H+ W+ W- key free
GOSCAN: AJMP HEADKEY ;( W LAST END ) or ( condition not satisfy )
ZS: MOV DPTR,#6002H ;U10 port C 注射
CHCOND: MOVX A,@DPTR ;CHeck CONDitions
ACALL DESHAKE
CJNE A,5DH,CHCOND
JNB ACC.5,GOSCAN ;pump ERR
PUMPOK: JNB ACC.2,JECT ;料泵正常
JOB: JNB ACC.4,GOSCAN ;搅拌器异未工作
JECT: ;注射
ACALL DLY40MS
ACALL DLY40MS ;DLY 80ms for display ject time
MOV 5CH,#10H ;set bit U11 PC.4
ACALL OUT ;ject output
MOV R0,#44H
ACALL DLY ;DLY ject time
AFTER: MOV 5CH,#00H ;after ject
ACALL OUT ;ject.clear.blow off
ACALL XSTIMEA ;display After ject TIME
MOV R0,#48H
ACALL DLY ;DLY after ject time
MOV DPTR,#6002H ;U10 port C
CHAUTO: MOVX A,@DPTR ;CHeck AUTO clear & blow condition
ANL A,#0F8H
ACALL DESHAKE
ANL A,#0F8H
CJNE A,5DH,NOTAUTO
JB ACC.3,QX ;auto clear & blow
NOTAUTO:ACALL REBRUSH
AJMP START ;not autu clear & blow
QX: ;清洗注射枪头残余物料
MOV 5CH,#20H ;set bit U11 PC.5
ACALL OUT ;output clear
ACALL XSTIMEC ;display TIME Clear
MOV R0,#4CH
ACALL DLY ;DLY clear time
CF: ;吹风(吹干注射枪头)
MOV 5CH,#40H ;set bit U11 PC.6
ACALL OUT ;output blow
ACALL XSTIMEB ;display TIME Blow
MOV R0,#50H
ACALL DLY ;DLY blow time
ACALL REBRUSH
AJMP START ;吹风完毕
XST: ACALL R2864 ;读取预存于EEPROM2864的注射持续时间值
XSTIME: ;显示注射持续时间值
ACALL LED3
ACALL LED4
ACALL LED5
ACALL LED6
RET
XSTIMEA: ;显示注射后的停留时间
MOV 42H,#04H ;
MOV 43H,#01H
ACALL LED1 ;display H
ACALL LED2 ;display W
ACALL RETRSA ;retrans After ject time
ACALL XSTIME ;display time
RET
XSTIMEC: ;显示清洗时间值
MOV 42H,#04H
MOV 43H,#02H
ACALL LED1 ;display H
ACALL LED2 ;display W
ACALL RETRSC ;retrans Clear time
ACALL XSTIME
RET
XSTIMEB: ;显示吹风时间值
MOV 42H,#04H
MOV 43H,#03H
ACALL LED1
ACALL LED2
ACALL RETRSB ;retrans Blow time
ACALL XSTIME
RET
XS: ;显示工作状态及注射持续时间
PUSH ACC
MOV DPTR,#DMB
MOVC A,@A+DPTR
MOV DPH,40H
MOV DPL,41H
MOVX @DPTR,A
POP ACC
RET
LED1: MOV A,42H ;display Hi
MOV 40H,#78H
MOV 41H,#01H ;DPTR=7801H
ACALL XS
RET
LED2: MOV A,43H ;display Low
MOV 40H,#78H
MOV 41H,#02H ;DPTR=7802H
ACALL XS
RET
LED3: MOV A,44H ;display X10 SEC
MOV 40H,#78H
MOV 41H,#00H ;DPTR=7800H
ACALL XS
RET
LED4: MOV A,45H ;display X1 SEC
MOV 40H,#68H
MOV 41H,#01H ;DPTR=6801H
ACALL XS
RET
LED5: MOV A,46H ;display X0.1 SEC
MOV 40H,#68H
MOV 41H,#02H ;DPTR=6802H
ACALL XS
RET
LED6: MOV A,47H ;display X0.01 SEC
MOV 40H,#68H
MOV 41H,#00H ;DPTR=6800H
ACALL XS
RET
JSDZ: MOV DPH,#41H ;calculate time data address in 2864
MOV B,#14H ;DPH=41h
MOV A,42H ;DPL=Hx14h+Wx2h
MUL AB
MOV R4,A
MOV A,43H
NOP
RL A
ADD A,R4
MOV DPL,A
RET
R2864: ACALL JSDZ ;read 2864
MOV R0,#44H
MOVX A,@DPTR
ACALL DLY10MS
ACALL FLBCD
INC R0
INC DPL
MOVX A,@DPTR
ACALL DLY10MS
ACALL FLBCD
RET
FLBCD: PUSH ACC ;devide BCD code
ANL A,#0F0H
SWAP A
MOV @R0,A
INC R0
POP ACC
ANL A,#0FH
MOV @R0,A
RET
READACB:MOV DPH,#41H ;read A.C.B. time
READA: MOV DPL,#52H ;read After ject time
MOV R0,#48H
ACALL READT
READC: INC DPL ;read Clear time
MOV R0,#4CH
ACALL READT
READB: INC DPL ;read Blow time
MOV R0,#50H
ACALL READT
RET
READT: MOVX A,@DPTR ;read Time from 2864
ACALL DLY10MS
ACALL FLBCD
INC R0
INC DPL
MOVX A,@DPTR
ACALL DLY10MS
ACALL FLBCD
RET
W2864: ACALL JSDZ ;write 2864
MOV R0,#44H
ACALL YSBCD ;compress BCD code
INC DPL
INC R0
ACALL YSBCD
MOV A,42H
CJNE A,#04H,WEND ;W864 END
MOV A,43H
JB ACC.0,GOTRANS ;after inject time or blow time
JB ACC.1,GOTRANS ;clear time or blow time
SJMP WEND
GOTRANS:ACALL TRANS ;TRANSlate time data
WEND: ACALL FEEDDOG
ACALL DLY40MS
AJMP WNEXT ;W2864 END, goto edit next time
YSBCD: MOV A,@R0 ;compress BCD code
SWAP A
INC R0
ORL A,@R0
MOVX @DPTR,A
ACALL DLY40MS
RET
NOP
NOP
AJMP FIRST
TRANS: MOV R0,#44H ;TRANSlate time date
DEC A
MOV B,#05H
MUL AB
MOV DPTR,#TRANSA
JMP @A+DPTR
TRANSA: MOV R1,#48H ;TRANS After ject time (48~4b) < (44~47)
ACALL SENDT
RET
TRANSC: MOV R1,#4CH ;TRANS Clear time (4c~4f) < (44~47)
ACALL SENDT
RET
TRANSB: MOV R1,#50H ;TRANS Blow time (50~53) < (44~47)
ACALL SENDT
RET
SENDT: MOV A,@R0 ;SEND Time
MOV @R1,A ;(R1) < (R0)
CJNE R0,#47H,NEXTS
RET
NEXTS: INC R0 ;NEXT Send
INC R1
SJMP SENDT
RETRSA: MOV R1,#48H ;RETRANS After ject time
MOV R0,#44H ;(48~4b) > (44~47)
ACALL RESENDT
RET
RETRSC: MOV R1,#4CH ;RETRANS Clear time
MOV R0,#44H ;(4c~4f) > (44~47)
ACALL RESENDT
RET
RETRSB: MOV R1,#50H ;RETRANS Blow time
MOV R0,#44H ;(50~53) > (44~47)
ACALL RESENDT
RET
RESENDT:MOV A,@R1 ;RESEND Time
MOV @R0,A ;(R1) > (R0)
CJNE R0,#47H,NEXTRES
RET
NEXTRES:INC R0 ;NEXT RESend
INC R1
SJMP RESENDT
DLY40MS:MOV R7,#28H
DELY0: MOV R6,#0FFH
DELY1: DJNZ R6,DELY1
DJNZ R7,DELY0
RET ;DLY40MS END
DLY10MS:MOV R7,#0AH
D10MS0: MOV R6,#0EBH
D10MS1: DJNZ R6,D10MS1
DJNZ R7,D10MS0
RET ;DLY10MS END
DLY: NOP ;Delay ( decalculate time)
NOP
D47: MOV R1,#47H ;Delay X0.01 SEC
CJNE @R1,#00H,DEC47
SJMP D46
DEC47: ACALL REBRUSH
ACALL FEEDDOG
ACALL DLY10MS
DEC 47H
ACALL LED6
MOV R0,#47H
CJNE @R0,#00H,DEC47
D46: MOV R1,#46H ;Delay X0.1 SEC
CJNE @R1,#00H,DEC46
SJMP D45
DEC46: DEC 46H
ACALL LED5
MOV 47H,#0AH
SJMP DEC47
D45: MOV R1,#45H ;Delay X1 SEC
CJNE @R1,#00H,DEC45
SJMP D44
DEC45: DEC 45H
ACALL LED4
MOV 46H,#0AH
SJMP DEC46
D44: MOV R1,#44H ;Delay X10 SEC
CJNE @R1,#00H,DEC44
SJMP DLYEND
DEC44: DEC 44H
ACALL LED3
MOV 45H,#0AH
SJMP DEC45
DLYEND: RET ;DLY END
DW 0000H
AJMP MAIN
DMB: ;数码管段码表
DB 7EH ;00H-'0'
DB 0CH ;01H-'1'
DB 0B6H ;02H-'2'
DB 9EH ;03H-'3'
DB 0CCH ;04H-'4'
DB 0DAH ;05H-'5'
DB 0FAH ;06H-'6'
DB 0EH ;07H-'7'
DB 0FEH ;08H-'8'
DB 0DEH ;09H-'9'
DB 0DDH ;0AH-'A'
DB 0F8H ;0BH-'b'
DB 72H ;0CH-'C'
DB 0BCH ;0DH-'d'
DB 0F2H ;0EH-'E'
DB 0E2H ;0FH-'F'
DB 00H ;10H-OFF
DB 0ECH ;12H-'H'
DB 70H ;11H-'L'
TNOB: DB 00H
DW 0102H ;JT01~JT40 注射时间值
DW 0304H
DW 0506H
DW 0708H
DW 0910H
DW 1112H
DW 1314H
DW 1516H
DW 1718H
DW 1920H
DW 2122H
DW 2324H
DW 2526H
DW 2728H
DW 2930H
DW 3132H
DW 3334H
DW 3536H
DW 3738H
DW 3940H
DW 4142H ;JT41-after ject time, JT42-clear time
DW 4344H ;JT43-blow time
DW 4546H
DW 4748H
DB 49H ;JT44~T49 not use
DW 0000H
AJMP MAIN
SET: CLR EA
SETT0M1:MOV TMOD,#01H ;Time MOD1
SETB PT0 ;Time0
SETU7: MOV A,#80H ;8255 MOD0 ALL OUTPUT
MOV DPTR,#7803H ;Unit7 LED1-LED3
MOVX @DPTR,A
SETU8: MOV DPTR,#6803H ;Unit8 LED4-LED6
MOVX @DPTR,A
SETU9: MOV A,#9BH ;8255 MOD0 ALL INPUT
MOV DPTR,#7003H ;Unit9 PA.PB.PC(T01-T24)
MOVX @DPTR,A
SETU10: MOV DPTR,#6003H ;Unit10
MOVX @DPTR,A ;PA.PB(T25-T40) PC(OK.BL.CL.AUTO.input)
SETU11: MOV A,#92H ;8255 MOD0 (PA.PB INPUT) (PC OUTPUT)
MOV DPTR,#2003H ;Unit11 (PA.PB KEYBOARD ) (PC JECT.CLEAR.BLOW)
MOVX @DPTR,A
RET ;end of SET
OUT: MOV A,5CH
MOV DPTR,#2002H
MOVX @DPTR,A
RET
FEEDDOG:CLR EA ;feed dog
MOV TL0,#00H
MOV TH0,#00H ;largest time=(FFFF+1)T0=65536(12/6M)=131.072ms
MOV IE,#82H ;set bit EA & ET0
SETB TR0 ;start T0
RET
REBRUSH:ACALL SET ;for anti OUT & LED disturbed 8279雨刮
ACALL OUT ;output
ACALL LED1 ;display H
ACALL LED2 ;display W
ACALL XSTIME ;display time
RET
DW 0000H
CIRCLE: MOV A,5BH ;circle times
CJNE A,#0FFH,NEXTCL
ACALL REBRUSH ;circle rebrush
MOV 5BH,#00H
SJMP CIREND
NEXTCL: INC 5BH ;next circle
CIREND: RET ;circle end
END
|