ZLG_BIT_CNT EQU 31H
ZLG_SEND_BUF EQU 33H
ZLG_REC_BUF EQU 34H
;*******MOTOR PARAMETERS*******
MOTOR_D3_BIT EQU P2.7
MOTOR_D2_BIT EQU P2.6
MOTOR_D1_BIT EQU P2.5
MOTOR_D0_BIT EQU P2.4
MOTOR_IN_B2_BIT EQU P2.3
MOTOR_IN_A2_BIT EQU P2.2
MOTOR_IN_B1_BIT EQU P2.1
MOTOR_IN_A1_BIT EQU P2.0
;*******DELAY PARAMETERS*******
VAR_DELAY EQU 71H ;The variable for delay function
VAR_LOOP1 EQU 72H ;The loop variable for function
VAR_LOOP2 EQU 73H ;The loop variable for function
VAR_LOOP3 EQU 74H ;The loop variable for function
FLAG_1 EQU 75H ;The variable for delay function
GEWEI EQU 35H
SHIWEI EQU 36H
BAIWEI EQU 37H
QIANWEI EQU 38H
GAO1 EQU 40H
GAO2 EQU 41H
GAO3 EQU 42H
GAO4 EQU 43H
GAO6 EQU 46H
KONG_ZHI EQU 47H
XUNHUAN EQU 44H
KEY_0 EQU 00H
KEY_1 EQU 01H
KEY_2 EQU 02H
KEY_3 EQU 03H
KEY_4 EQU 04H
KEY_5 EQU 05H
KEY_6 EQU 06H
KEY_7 EQU 07H
KEY_8 EQU 08H
KEY_9 EQU 09H
KEY_10 EQU 0AH
KEY_11 EQU 0BH
KEY_12 EQU 0CH
KEY_13 EQU 0DH
KEY_14 EQU 0EH
KEY_15 EQU 0FH
FLAG EQU 45H
DELAY EQU 32H
;**************************************
;
;**************************************
CS EQU P3.0 ;TLC5615·?±e?ó51μ?P3.0-3.3
SCK EQU P3.1
DI EQU P3.2
ZLG_CS BIT P1.0
ZLG_CLK BIT P1.1
ZLG_DIO BIT P1.2
ZLG_KEY BIT P1.3
; ORG 000BH
; JMP INTERRUPT_T0
ORG 0000H
AJMP MAIN
ORG 0050H
MAIN:
MOV ZLG_SEND_BUF,#10100100B
CALL SEND
SETB ZLG_CS
MOV GEWEI,#00H
MOV SHIWEI,#00H
MOV BAIWEI,#00H
MOV QIANWEI,#00H
MOV GAO1,#00H
MOV GAO2,#00H
MOV GAO3,#00H
MOV GAO4,#00H
MOV FLAG_1,#00H
setb MOTOR_D3_BIT
clr MOTOR_D2_BIT
clr MOTOR_D1_BIT
clr MOTOR_D0_BIT
clr MOTOR_IN_B2_BIT
clr MOTOR_IN_B1_BIT
clr MOTOR_IN_A2_BIT
clr MOTOR_IN_A1_BIT
CALL DISPLAY
MAIN_1:
JB ZLG_KEY,MAIN_1
MOV ZLG_SEND_BUF,#00010101B
CALL SEND
CALL RECEIVE
SETB ZLG_CS ;ZLG_REC_BUF
MAIN_ANJ1:
JNB ZLG_KEY,MAIN_ANJ1
CALL GETZHI
AJMP MAIN_1
ret
;---------------------------------------
;display program 1
;---------------------------------------
DISPLAY:
PUSH ACC
MOV A,#80H
ADD A,GAO1
MOV GAO6,A
POP ACC
MOV ZLG_SEND_BUF,#80H
CALL SEND
MOV ZLG_SEND_BUF,GEWEI
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#81H
CALL SEND
MOV ZLG_SEND_BUF,SHIWEI
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#82H
CALL SEND
MOV ZLG_SEND_BUF,BAIWEI
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#83H
CALL SEND
MOV ZLG_SEND_BUF,QIANWEI
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#84H
CALL SEND
MOV ZLG_SEND_BUF,GAO6
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#85H
CALL SEND
MOV ZLG_SEND_BUF,GAO2
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#86H
CALL SEND
MOV ZLG_SEND_BUF,GAO3
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#87H
CALL SEND
MOV ZLG_SEND_BUF,GAO4
CALL SEND
SETB ZLG_CS
RET
DISPALY_1:
MOV ZLG_SEND_BUF,#80H
CALL SEND
MOV ZLG_SEND_BUF,GEWEI
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#81H
CALL SEND
MOV ZLG_SEND_BUF,SHIWEI
CALL SEND
SETB ZLG_CS
MOV ZLG_SEND_BUF,#82H
CALL SEND
MOV ZLG_SEND_BUF,BAIWEI
CALL SEND
SETB ZLG_CS
RET
;---------------------------------------------------
;°′?üé¨?è
;---------------------------------------------------
SONGZHI:
SONGMAIN:
JB ZLG_KEY,SONGMAIN
MOV ZLG_SEND_BUF, #00010101b
CALL SEND
CALL RECEIVE
SETB ZLG_CS
SONG_1:
JNB ZLG_KEY,SONG_1
;-----------------------------------------
;°′?ü0 1 2 3 4
CJNE R0,#5,ZHI_0
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_0
JMP ZHI_OVER
ZHI_0: CJNE A,#KEY_0,ZHI_1
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_1
MOV R5,#00H
JMP ZHI_OVER
ZHI_1: CJNE A,#KEY_1,ZHI_2
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_2
MOV R5,#01H
JMP ZHI_OVER
ZHI_2: CJNE A,#KEY_2,ZHI_3
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_3
MOV R5,#02H
JMP ZHI_OVER
ZHI_3: CJNE A,#KEY_3,ZHI_4
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_4
MOV R5,#03H
JMP ZHI_OVER
ZHI_4: CJNE A,#KEY_4,ZHI_5
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_5
MOV R5,#04H
JMP ZHI_OVER
;-----------------------------------
;×óóòò??ˉ°′?ü
ZHI_5: CJNE A,#KEY_5,ZHI_6
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_6
PUSH ACC
MOV A,XUNHUAN
CJNE A,#01111111B,HUAN_3
RL A
RL A
RL A
HUAN_3:
RL A
MOV XUNHUAN,A
POP ACC
CALL MOVE_LEFT
JMP XUN_EXIT
ZHI_6: CJNE A,#6,ZHI_7
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_7
PUSH ACC
MOV A,XUNHUAN
CJNE A,#11110111B,HUAN_1
RR A
RR A
RR A
HUAN_1: RR A
MOV XUNHUAN,A
POP ACC
CALL MOVE_LEFT
JMP XUN_EXIT
;-----------------------------------
;?′??°′?ü\
ZHI_7: CJNE A,#KEY_7,ZHI_8
MOV GEWEI,#00H
MOV SHIWEI,#00H
MOV BAIWEI,#00H
MOV QIANWEI,#00H
MOV GAO1,#00H
MOV GAO2,#00H
MOV GAO3,#00H
MOV GAO4,#00H
MOV R5,#00H
MOV KONG_ZHI,#00H
CALL SHE_ZHI_1
JMP XUN_EXIT
;--------------------------------
;°′?ü5 6 7 8 9
ZHI_8: CJNE A,#KEY_8,ZHI_9
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_9
MOV R5,#05H
JMP ZHI_OVER
ZHI_9: CJNE A,#KEY_9,ZHI_10
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_10
MOV R5,#06H
JMP ZHI_OVER
ZHI_10: CJNE A,#KEY_10,ZHI_11
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_11
MOV R5,#07H
JMP ZHI_OVER
ZHI_11: CJNE A,#KEY_11,ZHI_12
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_12
MOV R5,#08H
JMP ZHI_OVER
ZHI_12: CJNE A,#KEY_12,ZHI_13
MOV R3,FLAG_1
CJNE R3,#00H,ZHI_13
MOV R5,#09H
JMP ZHI_OVER
;-----------------------------------------------------------------------
;μ??úμ??y·′×a?ˉ
ZHI_13: CJNE A,#KEY_13,ZHI_14
MOV FLAG,#13
CALL SHE_ZHI_1
CALL MOTOR_SPROT
JMP XUN_EXIT
ZHI_14: CJNE A,#KEY_14,ZHI_15
MOV FLAG,#14
CALL SHE_ZHI_1
CALL MOTOR_SPROT
JMP XUN_EXIT
ZHI_15: CJNE A,#KEY_15,ZHI_OVER
JMP GETZHI
ZHI_OVER:
PUSH ACC
MOV A,XUNHUAN
CJNE A,#07FH,XUN_1
MOV GAO4,R5
JMP XUN_EXIT
XUN_1: CJNE A,#10111111B,XUN_2
MOV GAO3,R5
JMP XUN_EXIT
XUN_2: CJNE A,#11011111B,XUN_3
MOV GAO2,R5
JMP XUN_EXIT
XUN_3: CJNE A,#11101111B,XUN_4
MOV GAO1,R5
JMP XUN_EXIT
XUN_4: CJNE A,#11110111B,XUN_5
;------------------------------------------
;MOV R4,QIANWEI
CJNE R5,#00H,SAO_MIAO
MOV KONG_ZHI,#00H
JMP SAO_MIAO_1
SAO_MIAO:
PUSH ACC
MOV A,R5
MOV B,#02
DIV AB
ADD A,#1
MOV KONG_ZHI,A
POP ACC
SAO_MIAO_1:
MOV QIANWEI,R5
JMP XUN_EXIT
;-------------------------------------------
XUN_5: CJNE A,#11111011B,XUN_6
MOV BAIWEI,R5
JMP XUN_EXIT
XUN_6: CJNE A,#11111101B,XUN_7
MOV SHIWEI,R5
JMP XUN_EXIT
XUN_7: CJNE A,#11111110B,XUN_8
MOV GEWEI,R5
JMP XUN_EXIT
XUN_8: JMP XUN_EXIT
POP ACC
XUN_EXIT:
CALL DISPLAY
JMP SONGMAIN
RET
;------------------------------------------------
;???ˉμ??ú
SHE_ZHI_1:
MOV ZLG_SEND_BUF,#88H
CALL SEND
MOV ZLG_SEND_BUF,#11111111B
CALL SEND
SETB ZLG_CS
CALL DISPLAY
MOV FLAG_1,#01H
RET
;-------------------------------------------------
;???ˉéè??°′?ü
SHE_ZHI:
MOV ZLG_SEND_BUF,#88H
CALL SEND
MOV ZLG_SEND_BUF,#01111111B
CALL SEND
SETB ZLG_CS
CALL DISPLAY
RET
;------------------------------------------------
;????ò??ˉ
MOVE_LEFT:
MOV ZLG_SEND_BUF,#88H
CALL SEND
MOV ZLG_SEND_BUF,XUNHUAN
CALL SEND
SETB ZLG_CS
CALL DISPLAY
RET
;--------------------------------------------
;μ??ú???ˉ?÷êy
MOTOR_SPROT:
MOV R0,GAO1
MOV R1,GAO2
PUSH ACC
MOV A,R1
MOV B,#0AH
MUL AB
ADD A,R0
MOV R0,A
POP ACC
MOV R1,FLAG
CJNE R0,#00,MOTOR_MAIN
JMP MOTOR_EXIT
MOTOR_MAIN:
PUSH ACC
MOV A,R0
MOV B,#0AH
DIV AB
MOV SHIWEI,B
MOV BAIWEI,A
POP ACC
CALL DISPALY_1
mov VAR_LOOP1,#6
MOTOR_LOOP:
CJNE R1,#06,MOTOR_1
lcall motor_8_step_ZHENG
JMP MOTOR_2
MOTOR_1:
lcall motor_8_step_FAN
MOTOR_2:
djnz VAR_LOOP1,MOTOR_LOOP
DJNZ R0,MOTOR_MAIN
MOTOR_EXIT:
PUSH ACC
MOV A,R0
MOV B,#0AH
DIV AB
MOV SHIWEI,B
MOV BAIWEI,A
POP ACC
MOV R4,KONG_ZHI
CJNE R4,#00,MOTOR_Y
JMP MOTOR_T
MOTOR_Y:
MOV VAR_LOOP1,KONG_ZHI
MOTOR_MAIN_1:
CJNE R1,#06,MOTOR_3
lcall motor_8_step_ZHENG
JMP MOTOR_4
MOTOR_3:
lcall motor_8_step_FAN
MOTOR_4:
djnz VAR_LOOP1,MOTOR_MAIN_1
MOTOR_T:
;
RET
;-------------------------------------------------
GETZHI:
CJNE A,#KEY_15,NEXT_LOOP
MOV XUNHUAN,#07FH
CALL SHE_ZHI
MOV FLAG_1,#00H
CALL SONGZHI
NEXT_LOOP:
RET
;********************************************************
;??????ZLG7289A,????
;********************************************************
SEND:
MOV ZLG_BIT_CNT,#8 ;??????8 ?.
CLR ZLG_CS
CALL LONG_DELAY ;??50 ??.
SEND_LP:
MOV A, ZLG_SEND_BUF
RLC A
MOV ZLG_SEND_BUF, A
MOV ZLG_DIO, C
NOP
NOP
SETB ZLG_CLK
CALL SHORT_DELAY ;??10 ??.
CLR ZLG_CLK
CALL SHORT_DELAY ;??10 ??.
DJNZ ZLG_BIT_CNT,SEND_LP
CLR ZLG_DIO
RET
;********************************************************
;?ZLG7289A ???????,????
;********************************************************
RECEIVE:
MOV ZLG_BIT_CNT,#8 ;????8 ?.
SETB ZLG_DIO
CALL LONG_DELAY ;??50 ??.
RECEIVE_LP:
SETB ZLG_CLK
CALL SHORT_DELAY ;??10 ??.
MOV C,ZLG_DIO ;?????REC_BUF ??.
MOV A,ZLG_REC_BUF
RLC A
MOV ZLG_REC_BUF,A
CLR ZLG_CLK
CALL SHORT_DELAY ;??10 ??.
DJNZ ZLG_BIT_CNT,RECEIVE_LP
CLR ZLG_DIO
RET
;-------------------------------------------------------
motor_8_step_ZHENG: ;μ??úμ?×a?ˉ(?y×a)
;(1) 1+ 2+
clr MOTOR_IN_B1_BIT
setb MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
setb MOTOR_IN_A2_BIT
lcall delay_2500us
;(2) 1+ 2off
clr MOTOR_IN_B1_BIT
setb MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(3) 1+ 2-
clr MOTOR_IN_B1_BIT
setb MOTOR_IN_A1_BIT
setb MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(4) 1off 2-
clr MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
setb MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(5) 1- 2-
setb MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
setb MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(6) 1- 2off
setb MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(7) 1- 2+
setb MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
setb MOTOR_IN_A2_BIT
lcall delay_2500us
;(8) 1off 2+
clr MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
setb MOTOR_IN_A2_BIT
lcall delay_2500us
ret
;------------------------------------------
motor_8_step_FAN: ;μ??úμ?×a?ˉ(·′×a)
;(7) 1- 2+
setb MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
setb MOTOR_IN_A2_BIT
lcall delay_2500us
;(6) 1- 2off
setb MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(5) 1- 2-
setb MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
setb MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(4) 1off 2-
clr MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
setb MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(3) 1+ 2-
clr MOTOR_IN_B1_BIT
setb MOTOR_IN_A1_BIT
setb MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(2) 1+ 2off
clr MOTOR_IN_B1_BIT
setb MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
clr MOTOR_IN_A2_BIT
lcall delay_2500us
;(1) 1+ 2+
clr MOTOR_IN_B1_BIT
setb MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
setb MOTOR_IN_A2_BIT
lcall delay_2500us
;(8) 1off 2+
clr MOTOR_IN_B1_BIT
clr MOTOR_IN_A1_BIT
clr MOTOR_IN_B2_BIT
setb MOTOR_IN_A2_BIT
lcall delay_2500us
ret
;********************************************************
;?????
;********************************************************
LONG_DELAY:
MOV DELAY, #25
DJNZ DELAY, $
RET
SHORT_DELAY:
MOV DELAY, #4
DJNZ DELAY, $
RET
;------------------------------------------------------------
;12M,delay for 5us
delay_5us:
nop
nop
nop
nop
ret
;*****************************************************************
;12M,delay for 2.5MS
delay_2500us:
push VAR_DELAY
MOV R7,GAO4
MOV R6,GAO3
PUSH ACC
MOV A,R7
RL A
RL A
RL A
RL A
ADD A,R6
MOV R7,A
POP ACC
CJNE R7,#00,DELAY_X
JMP DELAY_EXIT
DELAy_X:
mov VAR_DELAY,#250 ;12M/2.5MS
DELAY2500_LOOP:
call delay_5us
call delay_5us
djnz VAR_DELAY,DELAY2500_LOOP
DJNZ R7,DELAY_X
DELAY_EXIT:
pop VAR_DELAY
ret
;*****************************************************************
END
[此贴子已经被作者于2007-6-5 14:19:24编辑过]