Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

code-robot

$MOD51fx

;**************** KHAI BAO_NGO VAO **********************

CHAY_THANG BIT P0.5

CHAY_LUI BIT P2.6

XOAY_PHAI BIT P2.7

XOAY_TRAI BIT P2.0

NANG_TAY BIT P2.5

HA_TAY BIT P2.4

TANG_TOC BIT P0.7

CHAY BIT P0.4

HT_HA BIT P2.2

HT_NANG BIT P2.1

ACT_ENCODER BIT EX0

PHASE_B BIT P3.3

;******************* KHAI BAO BIEN **********************

VUNG EQU 40H

BANH_TRAI_TD1 EQU 45H

BANH_PHAI_TD1 EQU 46H

BANH_TRAI_TD2 EQU 47H

BANH_PHAI_TD2 EQU 48H

BANH_TRAI_TD1_DAO EQU 49H

BANH_PHAI_TD1_DAO EQU 4AH

BANH_TRAI_TD2_DAO EQU 4BH

BANH_PHAI_TD2_DAO EQU 4CH

BANH_TRAI_TD3 EQU 4DH

BANH_PHAI_TD3 EQU 4EH

BANH_TRAI_TD4 EQU 4FH

BANH_PHAI_TD4 EQU 70H

BANH_TRAI_TD5 EQU 71H

BANH_PHAI_TD5 EQU 72H

BANH_TRAI_TD6 EQU 73H

BANH_PHAI_TD6 EQU 74H

;***************** KHAI BAO DONG CO *********************

MOTOR_NANG EQU CCAP2H

MOTOR_NANG_DAO BIT P3.5

BANH_PHAI EQU CCAP0H

BANH_PHAI_DAO BIT P3.3

BANH_TRAI EQU CCAP1H

BANH_TRAI_DAO BIT P3.4

;***************** CHUONG TRINH CHINH *******************

ORG 0000H

LJMP MAIN

ORG 0003H

LJMP NGAT_EX0

MAIN: MOV R0,#05

MOV R1,#100

; MOV IE,#10000000B

; SETB IT0

MOV CMOD,#0

SETB CR

MOV CCAPM4,#01000010B

MOV CCAPM2,#01000010B

MOV CCAPM3,#01000010B

MOV CCAPM1,#01000010B

MOV CCAPM0,#01000010B

MOV BANH_TRAI_TD1,#255 ;TOC DO NHANH

MOV BANH_PHAI_TD1,#255

MOV BANH_TRAI_TD2,#145 ;TOC DO CHAM

MOV BANH_PHAI_TD2,#125

MOV BANH_TRAI_TD3,#80 ;TOC DO CHAM XOAY PHAI

MOV BANH_PHAI_TD3,#90

MOV BANH_TRAI_TD4,#65 ;TOC DO CHAM XOAY TRAI

MOV BANH_PHAI_TD4,#70

MOV BANH_TRAI_TD5,#160 ;TOC DO NHANH XOAY PHAI

MOV BANH_PHAI_TD5,#140

MOV BANH_TRAI_TD6,#160 ;TOC DO NHANH XOAY TRAI

MOV BANH_PHAI_TD6,#140

MOV BANH_TRAI_TD1_DAO,#130 ;TOC DO LUI NHANH

MOV BANH_PHAI_TD1_DAO,#130

MOV BANH_TRAI_TD2_DAO,#50 ;TOC DO LUI CHAM

MOV BANH_PHAI_TD2_DAO,#50

TD:

CALL KIEM_TRA_NUT_NHAN

CALL DIEU_KHIEN_ROBOT

SJMP TD

;************ CHUONG TRINH KIEM TRA NUT NHAN ************

KIEM_TRA_NUT_NHAN:

KIEM_TRA_TH1: ;CHAY CHAM KHONG XOAY

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,HA_TAY

ANL C,/CHAY

JNC KIEM_TRA_TH2

MOV VUNG,#30H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH2: ;CHAY NHANH KHONG XOAY

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/CHAY

ANL C,/TANG_TOC

JNC KIEM_TRA_TH3

MOV VUNG,#31H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH3: ;CHAY CHAM + NANG TAY

MOV C,TANG_TOC

ANL C,HA_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/NANG_TAY

ANL C,/CHAY

JNC KIEM_TRA_TH4

MOV VUNG,#02H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH4: ;CHAY NHANH + NANG TAY

MOV C,HA_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/CHAY

ANL C,/TANG_TOC

ANL C,/NANG_TAY

JNC KIEM_TRA_TH5

MOV VUNG,#15H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH5: ;CHAY CHAM + HA TAY

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/CHAY

ANL C,/HA_TAY

JNC KIEM_TRA_TH6

MOV VUNG,#04H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH6: ;CHAY NHANH + HA TAY

MOV C,NANG_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/CHAY

ANL C,/TANG_TOC

ANL C,/HA_TAY

JNC KIEM_TRA_TH7

MOV VUNG,#05H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH7: ;CHAY LUI CHAM

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,HA_TAY

ANL C,/CHAY_LUI

JNC KIEM_TRA_TH8

MOV VUNG,#06H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH8: ;CHAY LUI NHANH

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,/CHAY_LUI

ANL C,/TANG_TOC

JNC KIEM_TRA_TH9

MOV VUNG,#07H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH9: ;CHAY LUI CHAM + NANG TAY

MOV C,HA_TAY

ANL C,TANG_TOC

ANL C,/NANG_TAY

ANL C,/CHAY_LUI

JNC KIEM_TRA_TH10

MOV VUNG,#08H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH10: ;CHAY LUI NHANH + NANG TAY

MOV C,HA_TAY

ANL C,/CHAY_LUI

ANL C,/TANG_TOC

ANL C,/NANG_TAY

JNC KIEM_TRA_TH11

MOV VUNG,#09H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH11: ;CHAY LUI CHAM + HA TAY

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,/HA_TAY

ANL C,/CHAY_LUI

JNC KIEM_TRA_TH12

MOV VUNG,#0AH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH12: ;CHAY LUI NHANH + HA TAY

MOV C,NANG_TAY

ANL C,/CHAY_LUI

ANL C,/TANG_TOC

ANL C,/HA_TAY

JNC KIEM_TRA_TH13

MOV VUNG,#0BH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH13: ;XOAY PHAI CHAM

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY

ANL C,XOAY_TRAI

ANL C,/XOAY_PHAI

JNC KIEM_TRA_TH14

MOV VUNG,#0CH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH14: ;XOAY PHAI NHANH

MOV C,XOAY_TRAI

ANL C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY

ANL C,XOAY_TRAI

ANL C,/XOAY_PHAI

ANL C,/TANG_TOC

JNC KIEM_TRA_TH15

MOV VUNG,#0DH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH15: ;XOAY TRAI CHAM

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY

ANL C,XOAY_PHAI

ANL C,/XOAY_TRAI

JNC KIEM_TRA_TH16

MOV VUNG,#0EH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH16: ;XOAY TRAI NHANH

MOV C,XOAY_PHAI

ANL C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY

ANL C,XOAY_PHAI

ANL C,/XOAY_TRAI

ANL C,/TANG_TOC

JNC KIEM_TRA_TH17

MOV VUNG,#0FH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH17: ;NANG TAY GAP

MOV C,HA_TAY

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/NANG_TAY

JNC KIEM_TRA_TH18

MOV VUNG,#10H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH18: ;HA TAY GAP

MOV C,NANG_TAY

ANL C,TANG_TOC

ANL C,XOAY_TRAI

ANL C,XOAY_PHAI

ANL C,/HA_TAY

JNC KIEM_TRA_TH21

MOV VUNG,#11H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH21:

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY_THANG

ANL C,CHAY_LUI

ANL C,XOAY_PHAI

ANL C,XOAY_TRAI

ANL C,/TANG_TOC

JNC KIEM_TRA_TH22

MOV VUNG,#14H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH22:

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY_THANG

ANL C,CHAY_LUI

ANL C,XOAY_PHAI

ANL C,XOAY_TRAI

ANL C,TANG_TOC

JNC KIEM_TRA_TH23

MOV VUNG,#14H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH23:

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY_THANG

ANL C,CHAY_LUI

ANL C,XOAY_PHAI

ANL C,XOAY_TRAI

ANL C,/TANG_TOC

JNC KIEM_TRA_TH24

MOV VUNG,#16H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH24:

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,CHAY_THANG

ANL C,CHAY_LUI

ANL C,XOAY_PHAI

ANL C,XOAY_TRAI

ANL C,TANG_TOC

JNC KIEM_TRA_TH25

MOV VUNG,#16H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH25: ;CHAY XOAY PHAI CHAM + NANG TAY

MOV C,XOAY_TRAI

ANL C,TANG_TOC

ANL C,HA_TAY

ANL C,/NANG_TAY

ANL C,/XOAY_PHAI

ANL C,/CHAY

JNC KIEM_TRA_TH26

MOV VUNG,#17H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH26: ;CHAY XOAY PHAI NHANH + NANG TAY

MOV C,XOAY_TRAI

ANL C,HA_TAY

ANL C,/TANG_TOC

ANL C,/NANG_TAY

ANL C,/XOAY_PHAI

ANL C,/CHAY

JNC KIEM_TRA_TH27

MOV VUNG,#18H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH27: ;CHAY XOAY TRAI CHAM + NANG TAY

MOV C,XOAY_PHAI

ANL C,HA_TAY

ANL C,TANG_TOC

ANL C,/NANG_TAY

ANL C,/XOAY_TRAI

ANL C,/CHAY

JNC KIEM_TRA_TH28

MOV VUNG,#19H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH28: ;CHAY XOAY TRAI NHANH + NANG TAY

MOV C,XOAY_PHAI

ANL C,HA_TAY

ANL C,/TANG_TOC

ANL C,/NANG_TAY

ANL C,/XOAY_TRAI

ANL C,/CHAY

JNC KIEM_TRA_TH29

MOV VUNG,#1AH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH29: ;CHAY XOAY PHAI CHAM + HA TAY

MOV C,XOAY_TRAI

ANL C,TANG_TOC

ANL C,NANG_TAY

ANL C,/HA_TAY

ANL C,/XOAY_PHAI

ANL C,/CHAY

JNC KIEM_TRA_TH30

MOV VUNG,#1BH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH30: ;CHAY XOAY PHAI NHANH + HA TAY

MOV C,XOAY_TRAI

ANL C,NANG_TAY

ANL C,/TANG_TOC

ANL C,/HA_TAY

ANL C,/XOAY_PHAI

ANL C,/CHAY

JNC KIEM_TRA_TH31

MOV VUNG,#1CH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH31: ;CHAY XOAY TRAI CHAM + HA TAY

MOV C,XOAY_PHAI

ANL C,NANG_TAY

ANL C,TANG_TOC

ANL C,/HA_TAY

ANL C,/XOAY_TRAI

ANL C,/CHAY

JNC KIEM_TRA_TH32

MOV VUNG,#1DH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH32: ;CHAY XOAY TRAI NHANH + HA TAY

MOV C,XOAY_PHAI

ANL C,NANG_TAY

ANL C,/TANG_TOC

ANL C,/HA_TAY

ANL C,/XOAY_TRAI

ANL C,/CHAY

JNC KIEM_TRA_TH33

MOV VUNG,#1EH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH33: ;NANG_TAY_GAP_QUA

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,/TANG_TOC

ANL C,/CHAY_THANG

JNC KIEM_TRA_TH34

MOV VUNG,#1FH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH34: ;NANG_TAY_GAP_QUA

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,TANG_TOC

ANL C,/CHAY_THANG

JNC KIEM_TRA_TH35

MOV VUNG,#1FH

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH35: ;GAP QUA

MOV C,NANG_TAY

ANL C,/TANG_TOC

ANL C,/HA_TAY

JNC KIEM_TRA_TH36

MOV VUNG,#20H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH36: ;CHAY CHAM XOAY PHAI

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,XOAY_TRAI

ANL C,HA_TAY

ANL C,/XOAY_PHAI

ANL C,/CHAY

JNC KIEM_TRA_TH37

MOV VUNG,#21H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH37: ;CHAY CHAM XOAY TRAI

MOV C,TANG_TOC

ANL C,NANG_TAY

ANL C,XOAY_PHAI

ANL C,HA_TAY

ANL C,/XOAY_TRAI

ANL C,/CHAY

JNC KIEM_TRA_TH38

MOV VUNG,#22H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH38: ;CHAY NHANH XOAY PHAI

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,XOAY_TRAI

ANL C,/CHAY

ANL C,/TANG_TOC

ANL C,/XOAY_PHAI

JNC KIEM_TRA_TH39

MOV VUNG,#24H

JMP THOAT_KIEM_TRA_NUT_NHAN

KIEM_TRA_TH39: ;CHAY NHANH XOAY TRAI

MOV C,NANG_TAY

ANL C,HA_TAY

ANL C,XOAY_PHAI

ANL C,/CHAY

ANL C,/TANG_TOC

ANL C,/XOAY_TRAI

JNC THOAT_KIEM_TRA_NUT_NHAN

MOV VUNG,#23H

JMP THOAT_KIEM_TRA_NUT_NHAN

THOAT_KIEM_TRA_NUT_NHAN:

RET

;***************** DIEU KHIEN ROBOT *****************

DIEU_KHIEN_ROBOT:

MOV A,VUNG

CJNE A,#30H,DK_TH1

CALL CHAY_TIEN

JMP THOAT_DK_ROBOT

DK_TH1:

MOV A,VUNG

CJNE A,#31H,DK_TH2

CALL CHAY_THANG_NHANH

JMP THOAT_DK_ROBOT

DK_TH2:

MOV A,VUNG

CJNE A,#02H,DK_TH3

CALL CHAY_CHAM_NANG

JMP THOAT_DK_ROBOT

DK_TH3:

MOV A,VUNG

CJNE A,#15H,DK_TH4

CALL CHAY_NHANH_NANG

JMP THOAT_DK_ROBOT

DK_TH4:

MOV A,VUNG

CJNE A,#04H,DK_TH5

CALL CHAY_CHAM_HA

JMP THOAT_DK_ROBOT

DK_TH5:

MOV A,VUNG

CJNE A,#05H,DK_TH6

CALL CHAY_NHANH_HA

JMP THOAT_DK_ROBOT

DK_TH6:

MOV A,VUNG

CJNE A,#06H,DK_TH7

CALL CHAY_LUI_CHAM

JMP THOAT_DK_ROBOT

DK_TH7:

MOV A,VUNG

CJNE A,#07H,DK_TH8

CALL CHAY_LUI_NHANH

JMP THOAT_DK_ROBOT

DK_TH8:

MOV A,VUNG

CJNE A,#08H,DK_TH9

CALL LUI_CHAM_NANG

JMP THOAT_DK_ROBOT

DK_TH9:

MOV A,VUNG

CJNE A,#09H,DK_TH10

CALL LUI_NHANH_NANG

JMP THOAT_DK_ROBOT

DK_TH10:

MOV A,VUNG

CJNE A,#0AH,DK_TH11

CALL LUI_CHAM_HA

JMP THOAT_DK_ROBOT

DK_TH11:

MOV A,VUNG

CJNE A,#0BH,DK_TH12

CALL LUI_NHANH_HA

JMP THOAT_DK_ROBOT

DK_TH12:

MOV A,VUNG

CJNE A,#0CH,DK_TH13

CALL XOAY_PHAI_CHAM

JMP THOAT_DK_ROBOT

DK_TH13:

MOV A,VUNG

CJNE A,#0DH,DK_TH14

CALL XOAY_PHAI_NHANH

JMP THOAT_DK_ROBOT

DK_TH14:

MOV A,VUNG

CJNE A,#0EH,DK_TH15

CALL XOAY_TRAI_CHAM

JMP THOAT_DK_ROBOT

DK_TH15:

MOV A,VUNG

CJNE A,#0FH,DK_TH16

CALL XOAY_TRAI_NHANH

JMP THOAT_DK_ROBOT

DK_TH16:

MOV A,VUNG

CJNE A,#10H,DK_TH17

CALL NANG_TAY_GAP

JMP THOAT_DK_ROBOT

DK_TH17:

MOV A,VUNG

CJNE A,#11H,DK_TH20

CALL HA_TAY_GAP

JMP THOAT_DK_ROBOT

DK_TH20:

MOV A,VUNG

CJNE A,#14H,DK_TH22

CALL DUNG_ROBOT

JMP THOAT_DK_ROBOT

DK_TH22:

MOV A,VUNG

CJNE A,#16H,DK_TH23

CALL DUNG_ROBOT2

JMP THOAT_DK_ROBOT

DK_TH23:

MOV A,VUNG

CJNE A,#17H,DK_TH24

CALL XOAY_PHAI_CHAM_NANG

JMP THOAT_DK_ROBOT

DK_TH24:

MOV A,VUNG

CJNE A,#18H,DK_TH25

CALL XOAY_PHAI_NHANH_NANG

JMP THOAT_DK_ROBOT

DK_TH25:

MOV A,VUNG

CJNE A,#19H,DK_TH26

CALL XOAY_TRAI_CHAM_NANG

JMP THOAT_DK_ROBOT

DK_TH26:

MOV A,VUNG

CJNE A,#1AH,DK_TH27

CALL XOAY_TRAI_NHANH_NANG

JMP THOAT_DK_ROBOT

DK_TH27:

MOV A,VUNG

CJNE A,#1BH,DK_TH28

CALL XOAY_PHAI_CHAM_HA

JMP THOAT_DK_ROBOT

DK_TH28:

MOV A,VUNG

CJNE A,#1CH,DK_TH29

CALL XOAY_PHAI_NHANH_HA

JMP THOAT_DK_ROBOT

DK_TH29:

MOV A,VUNG

CJNE A,#1DH,DK_TH30

CALL XOAY_TRAI_CHAM_HA

JMP THOAT_DK_ROBOT

DK_TH30:

MOV A,VUNG

CJNE A,#1EH,DK_TH32

CALL XOAY_TRAI_NHANH_HA

JMP THOAT_DK_ROBOT

DK_TH32:

MOV A,VUNG

CJNE A,#20H,DK_TH33

CALL HA_TAY_GAP_CHAM

JMP THOAT_DK_ROBOT

DK_TH33:

MOV A,VUNG

CJNE A,#21H,DK_TH34

CALL CHAY_CHAM_XOAY_PHAI

JMP THOAT_DK_ROBOT

DK_TH34:

MOV A,VUNG

CJNE A,#22H,DK_TH35

CALL CHAY_CHAM_XOAY_TRAI

JMP THOAT_DK_ROBOT

DK_TH35:

MOV A,VUNG

CJNE A,#24H,DK_TH36

CALL CHAY_NHANH_XOAY_PHAI

JMP THOAT_DK_ROBOT

DK_TH36:

MOV A,VUNG

CJNE A,#23H,THOAT_DK_ROBOT

CALL CHAY_NHANH_XOAY_TRAI

JMP THOAT_DK_ROBOT

THOAT_DK_ROBOT:

RET

;***************** CHAY TIEN CHAM *******************

CHAY_TIEN:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

CHAY_TIEN1:

MOV BANH_TRAI,#255

MOV BANH_PHAI,#210

CALL KIEM_TRA_NUT_NHAN

CALL KIEM_TRA_TOC_DO

MOV A,VUNG

CJNE A,#30H,THOAT_CHAY_TIEN

JMP CHAY_TIEN1

THOAT_CHAY_TIEN:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;*************** CHAY TIEN NHANH ******************

CHAY_THANG_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#255

MOV BANH_PHAI,#220

CHAY_THANG_NHANH1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#31H,THOAT_CHAY_THANG_NHANH

JMP CHAY_THANG_NHANH1

THOAT_CHAY_THANG_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;************* CHAY TIEN CHAM & NANG **************

;************* CHAY TIEN CHAM & NANG **************

CHAY_CHAM_NANG:

JNB HT_NANG,THOAT_CHAY_CHAM_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,#200

MOV BANH_PHAI,#175

MOV MOTOR_NANG,#255

CHAY_CHAM_NANG1:

JNB HT_NANG,THOAT_CHAY_CHAM_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#02H,THOAT_CHAY_CHAM_NANG_DUNG

JMP CHAY_CHAM_NANG1

THOAT_CHAY_CHAM_NANG:

MOV BANH_TRAI,BANH_TRAI_TD2

MOV BANH_PHAI,BANH_PHAI_TD2

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#02H,THOAT_CHAY_CHAM_NANG_DUNG

JMP THOAT_CHAY_CHAM_NANG

THOAT_CHAY_CHAM_NANG_DUNG:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;************* CHAY TIEN NHANH & NANG ***************

CHAY_NHANH_NANG:

JNB HT_NANG,THOAT_CHAY_NHANH_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD1

MOV BANH_PHAI,BANH_PHAI_TD1

MOV MOTOR_NANG,#255

CHAY_NHANH_NANG1:

JNB HT_NANG,THOAT_CHAY_NHANH_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#15H,THOAT_CHAY_NHANH_NANG_DUNG

JMP CHAY_NHANH_NANG1

THOAT_CHAY_NHANH_NANG:

MOV BANH_TRAI,BANH_TRAI_TD1

MOV BANH_PHAI,BANH_PHAI_TD1

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#15H,THOAT_CHAY_CHAM_NANG_DUNG

JMP THOAT_CHAY_NHANH_NANG

THOAT_CHAY_NHANH_NANG_DUNG:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;************* CHAY TIEN CHAM & HA *************

CHAY_CHAM_HA:

JNB HT_HA,THOAT_CHAY_CHAM_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CLR MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,#200

MOV BANH_PHAI,#175

MOV MOTOR_NANG,#255

CHAY_CHAM_HA1:

JNB HT_HA,THOAT_CHAY_CHAM_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#04H,THOAT_CHAY_CHAM_HA_DUNG

JMP CHAY_CHAM_HA1

THOAT_CHAY_CHAM_HA:

MOV BANH_TRAI,BANH_TRAI_TD2

MOV BANH_PHAI,BANH_PHAI_TD2

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#04H,THOAT_CHAY_CHAM_HA_DUNG

JMP THOAT_CHAY_CHAM_HA

THOAT_CHAY_CHAM_HA_DUNG:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;************** CHAY TIEN NHANH & HA ***************

CHAY_NHANH_HA:

JNB HT_HA,THOAT_CHAY_NHANH_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CLR MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD1

MOV BANH_PHAI,BANH_PHAI_TD1

MOV MOTOR_NANG,#255

CHAY_NHANH_HA1:

JNB HT_HA,THOAT_CHAY_NHANH_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#05H,THOAT_CHAY_NHANH_HA_DUNG

JMP CHAY_NHANH_HA1

THOAT_CHAY_NHANH_HA:

MOV BANH_TRAI,BANH_TRAI_TD1

MOV BANH_PHAI,BANH_PHAI_TD1

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#05H,THOAT_CHAY_NHANH_HA_DUNG

JMP THOAT_CHAY_NHANH_HA

THOAT_CHAY_NHANH_HA_DUNG:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;***************** CHAY LUI CHAM *****************

CHAY_LUI_CHAM:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

CLR BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#200

MOV BANH_PHAI,#175

CHAY_LUI_CHAM1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#06H,THOAT_CHAY_LUI_CHAM

JMP CHAY_LUI_CHAM1

THOAT_CHAY_LUI_CHAM:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;*************** CHAY LUI NHANH ****************

CHAY_LUI_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

CLR BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD1_DAO

MOV BANH_PHAI,BANH_PHAI_TD1_DAO

CHAY_LUI_NHANH1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#07H,THOAT_CHAY_LUI_NHANH

JMP CHAY_LUI_NHANH1

THOAT_CHAY_LUI_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;************* CHAY LUI CHAM & NANG **************

LUI_CHAM_NANG:

JNB HT_NANG,THOAT_LUI_CHAM_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

CLR BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD2_DAO

MOV BANH_PHAI,BANH_PHAI_TD2_DAO

MOV MOTOR_NANG,#255

LUI_CHAM_NANG1:

JNB HT_NANG,THOAT_LUI_CHAM_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#08H,THOAT_LUI_CHAM_NANG

JMP LUI_CHAM_NANG1

THOAT_LUI_CHAM_NANG:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;*************** CHAY LUI NHANH & NANG ***************

LUI_NHANH_NANG:

JNB HT_NANG,THOAT_LUI_NHANH_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

CLR BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD1_DAO

MOV BANH_PHAI,BANH_PHAI_TD1_DAO

MOV MOTOR_NANG,#255

LUI_NHANH_NANG1:

JNB HT_NANG,THOAT_LUI_NHANH_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#09H,THOAT_LUI_NHANH_NANG

JMP LUI_NHANH_NANG1

THOAT_LUI_NHANH_NANG:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;************** CHAY LUI CHAM & HA ***************

LUI_CHAM_HA:

JNB HT_HA,THOAT_LUI_CHAM_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

CLR BANH_PHAI_DAO

CLR MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD2_DAO

MOV BANH_PHAI,BANH_PHAI_TD2_DAO

MOV MOTOR_NANG,#255

LUI_CHAM_HA1:

JNB HT_HA,THOAT_LUI_CHAM_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#0AH,THOAT_LUI_CHAM_HA

JMP LUI_CHAM_HA1

THOAT_LUI_CHAM_HA:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;************** CHAY LUI NHANH & HA ***************

LUI_NHANH_HA:

JNB HT_HA,THOAT_LUI_NHANH_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

CLR BANH_PHAI_DAO

CLR MOTOR_NANG_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD1_DAO

MOV BANH_PHAI,BANH_PHAI_TD1_DAO

MOV MOTOR_NANG,#255

LUI_NHANH_HA1:

JNB HT_HA,THOAT_LUI_NHANH_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#0BH,THOAT_LUI_NHANH_HA

JMP LUI_NHANH_HA1

THOAT_LUI_NHANH_HA:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;**************** XOAY PHAI **********************

XOAY_PHAI_CHAM:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

CLR BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#200

MOV BANH_PHAI,#70

XOAY_PHAI_CHAM1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#0CH,THOAT_XOAY_PHAI_CHAM

JMP XOAY_PHAI_CHAM1

THOAT_XOAY_PHAI_CHAM:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

XOAY_PHAI_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

CLR BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#255

MOV BANH_PHAI,#100

XOAY_PHAI_NHANH1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#0DH,THOAT_XOAY_PHAI_NHANH

JMP XOAY_PHAI_NHANH1

THOAT_XOAY_PHAI_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;**************** XOAY TRAI **********************

XOAY_TRAI_CHAM:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#90

MOV BANH_PHAI,#170

XOAY_TRAI_CHAM1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#0EH,THOAT_XOAY_TRAI_CHAM

JMP XOAY_TRAI_CHAM1

THOAT_XOAY_TRAI_CHAM:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

XOAY_TRAI_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

CLR BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#100

MOV BANH_PHAI,#255

XOAY_TRAI_NHANH1:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#0FH,THOAT_XOAY_TRAI_NHANH

JMP XOAY_TRAI_NHANH1

THOAT_XOAY_TRAI_NHANH:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;***************** NANG TAY GAP ******************

NANG_TAY_GAP:

JNB HT_NANG,TNTG

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV MOTOR_NANG,#255

NANG_TAY_GAP1:

JNB HT_NANG,THOAT_NANG_TAY_GAP

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#10H,THOAT_NANG_TAY_GAP

JMP NANG_TAY_GAP1

THOAT_NANG_TAY_GAP:

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV MOTOR_NANG,#00

TNTG:

RET

;********************** HA TAY GAP ***********************

HA_TAY_GAP:

JNB HT_HA,THTG

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR MOTOR_NANG_DAO

CALL DELAY_FET

MOV MOTOR_NANG,#255

HA_TAY_GAP1:

JNB HT_HA,THOAT_HA_TAY_GAP

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#11H,THOAT_HA_TAY_GAP

JMP HA_TAY_GAP1

THOAT_HA_TAY_GAP:

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV MOTOR_NANG,#00

THTG:

RET

;********************** HA TAY GAP ***********************

HA_TAY_GAP_CHAM:

JNB HT_HA,THTG_CHAM

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR MOTOR_NANG_DAO

CALL DELAY_FET

MOV MOTOR_NANG,#70

HA_TAY_GAP1_CHAM:

JNB HT_HA,THOAT_HA_TAY_GAP_CHAM

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#20H,THOAT_HA_TAY_GAP_CHAM

JMP HA_TAY_GAP1_CHAM

THOAT_HA_TAY_GAP_CHAM:

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

CALL DELAY_FET

MOV MOTOR_NANG,#00

THTG_CHAM:

RET

DUNG_ROBOT:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

DUNG_ROBOT11:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#14H,THOAT_DUNG_ROBOT

JMP DUNG_ROBOT11

THOAT_DUNG_ROBOT:

RET

DUNG_ROBOT2:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#10

DUNG_ROBOT111:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#16H,THOAT_DUNG_ROBOT11

JMP DUNG_ROBOT111

THOAT_DUNG_ROBOT11:

RET

;***************** XOAY PHAI CHAM + NANG TAY ***********************

XOAY_PHAI_CHAM_NANG:

JNB HT_NANG,THOAT_XOAY_PHAI_CHAM_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD3

MOV BANH_PHAI,BANH_PHAI_TD3

MOV MOTOR_NANG,#255-

XOAY_PHAI_CHAM_NANG1:

JNB HT_NANG,THOAT_XOAY_PHAI_CHAM_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#17H,THOAT_XOAY_PHAI_CHAM_NANG

JMP XOAY_PHAI_CHAM_NANG1

THOAT_XOAY_PHAI_CHAM_NANG:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;***************** XOAY PHAI NHANH + NANG TAY ***********************

XOAY_PHAI_NHANH_NANG:

JNB HT_NANG,THOAT_XOAY_PHAI_NHANH_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD6

MOV BANH_PHAI,BANH_PHAI_TD6

MOV MOTOR_NANG,#255

XOAY_PHAI_NHANH_NANG1:

JNB HT_NANG,THOAT_XOAY_PHAI_NHANH_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#18H,THOAT_XOAY_PHAI_NHANH_NANG

JMP XOAY_PHAI_NHANH_NANG1

THOAT_XOAY_PHAI_NHANH_NANG:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;***************** XOAY TRAI CHAM + NANG TAY ***********************

XOAY_TRAI_CHAM_NANG:

JNB HT_NANG,THOAT_XOAY_TRAI_CHAM_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD4

MOV BANH_PHAI,BANH_PHAI_TD4

MOV MOTOR_NANG,#255

XOAY_TRAI_CHAM_NANG1:

JNB HT_NANG,THOAT_XOAY_TRAI_CHAM_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#19H,THOAT_XOAY_TRAI_CHAM_NANG

JMP XOAY_TRAI_CHAM_NANG1

THOAT_XOAY_TRAI_CHAM_NANG:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;***************** XOAY TRAI NHANH + NANG TAY ***********************

XOAY_TRAI_NHANH_NANG:

JNB HT_NANG,THOAT_XOAY_TRAI_NHANH_NANG

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

SETB MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD5

MOV BANH_PHAI,BANH_PHAI_TD5

MOV MOTOR_NANG,#255

XOAY_TRAI_NHANH_NANG1:

JNB HT_NANG,THOAT_XOAY_TRAI_NHANH_NANG

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#1AH,THOAT_XOAY_TRAI_NHANH_NANG

JMP XOAY_TRAI_NHANH_NANG1

THOAT_XOAY_TRAI_NHANH_NANG:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;***************** XOAY PHAI CHAM + HA TAY ***********************

XOAY_PHAI_CHAM_HA:

JNB HT_HA,THOAT_XOAY_PHAI_CHAM_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD3

MOV BANH_PHAI,BANH_PHAI_TD3

MOV MOTOR_NANG,#255

XOAY_PHAI_CHAM_HA1:

JNB HT_HA,THOAT_XOAY_PHAI_CHAM_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#1BH,THOAT_XOAY_PHAI_CHAM_HA

JMP XOAY_PHAI_CHAM_HA1

THOAT_XOAY_PHAI_CHAM_HA:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;***************** XOAY PHAI NHANH + NANG TAY ***********************

XOAY_PHAI_NHANH_HA:

JNB HT_HA,THOAT_XOAY_PHAI_NHANH_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD6

MOV BANH_PHAI,BANH_PHAI_TD6

MOV MOTOR_NANG,#255

XOAY_PHAI_NHANH_HA1:

JNB HT_HA,THOAT_XOAY_PHAI_NHANH_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#1CH,THOAT_XOAY_PHAI_NHANH_HA

JMP XOAY_PHAI_NHANH_HA1

THOAT_XOAY_PHAI_NHANH_HA:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;***************** XOAY TRAI CHAM + NANG TAY ***********************

XOAY_TRAI_CHAM_HA:

JNB HT_HA,THOAT_XOAY_TRAI_CHAM_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD4

MOV BANH_PHAI,BANH_PHAI_TD4

MOV MOTOR_NANG,#255

XOAY_TRAI_CHAM_HA1:

JNB HT_HA,THOAT_XOAY_TRAI_CHAM_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#1DH,THOAT_XOAY_TRAI_CHAM_HA

JMP XOAY_TRAI_CHAM_HA1

THOAT_XOAY_TRAI_CHAM_HA:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;***************** XOAY TRAI NHANH + NANG TAY ***********************

XOAY_TRAI_NHANH_HA:

JNB HT_HA,THOAT_XOAY_TRAI_NHANH_HA

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

MOV MOTOR_NANG,#00

CALL DELAY_FET

CLR MOTOR_NANG_DAO

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,BANH_TRAI_TD5

MOV BANH_PHAI,BANH_PHAI_TD5

MOV MOTOR_NANG,#255

XOAY_TRAI_NHANH_HA1:

JNB HT_HA,THOAT_XOAY_TRAI_NHANH_HA

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#1EH,THOAT_XOAY_TRAI_NHANH_HA

JMP XOAY_TRAI_NHANH_HA1

THOAT_XOAY_TRAI_NHANH_HA:

MOV MOTOR_NANG,#00

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

SETB MOTOR_NANG_DAO

RET

;**************** CHAY CHAM VA XOAY PHAI *****************

CHAY_CHAM_XOAY_PHAI:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#200

MOV BANH_PHAI,#50

CHAY_TIEN1S:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#21H,THOAT_CHAY_TIENS

JMP CHAY_TIEN1S

THOAT_CHAY_TIENS:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;**************** CHAY CHAM VA XOAY TRAI *****************

CHAY_CHAM_XOAY_TRAI:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#50

MOV BANH_PHAI,#200

CHAY_TIEN1T:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#22H,THOAT_CHAY_TIENT

JMP CHAY_TIEN1T

THOAT_CHAY_TIENT:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;**************** CHAY NHANH VA XOAY TRAI *****************

CHAY_NHANH_XOAY_TRAI:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#40

MOV BANH_PHAI,#255

CHAY_TIEN1TN:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#23H,THOAT_CHAY_TIENTN

JMP CHAY_TIEN1TN

THOAT_CHAY_TIENTN:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;**************** CHAY NHANH VA XOAY TRAI *****************

CHAY_NHANH_XOAY_PHAI:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

CALL DELAY_FET

MOV BANH_TRAI,#255

MOV BANH_PHAI,#80

CHAY_TIEN1PN:

CALL KIEM_TRA_NUT_NHAN

MOV A,VUNG

CJNE A,#24H,THOAT_CHAY_TIENPN

JMP CHAY_TIEN1PN

THOAT_CHAY_TIENPN:

MOV BANH_TRAI,#00

MOV BANH_PHAI,#00

CALL DELAY_FET

SETB BANH_TRAI_DAO

SETB BANH_PHAI_DAO

RET

;****************** CHUONG TRINH NGAT INT0 **********

NGAT_EX0:

JB PHASE_B,QUAY_NGHICH

JMP QUAY_THUAN

QUAY_THUAN:

INC R0

CJNE R0,#100,THOAT_NGAT

MOV R0,#00

INC R1

CJNE R1,#255,THOAT_NGAT

MOV R1,#00

MOV R0,#00

JMP THOAT_NGAT

QUAY_NGHICH:

DEC R0

CJNE R0,#255,THOAT_NGAT

MOV R0,#99

DEC R1

CJNE R1,#255,THOAT_NGAT

MOV R1,#100

MOV R0,#99

THOAT_NGAT:

RETI

;**************** KIEM TRA TOC DO **************

KIEM_TRA_TOC_DO:

CJNE R1,#100,TD2 ;TOC DO CHAM

MOV BANH_TRAI_TD2,#80

MOV BANH_PHAI_TD2,#80

JMP THOAT_INT0

TD2:

CJNE R1,#110,TD3 ;TOC DO CHAM

MOV BANH_TRAI_TD2,#120

MOV BANH_PHAI_TD2,#120

JMP THOAT_INT0

TD3:

CJNE R1,#120,TD4 ;TOC DO CHAM

MOV BANH_TRAI_TD2,#170

MOV BANH_PHAI_TD2,#170

JMP THOAT_INT0

TD4:

CJNE R1,#130,TD5 ;TOC DO CHAM

MOV BANH_TRAI_TD2,#210

MOV BANH_PHAI_TD2,#210

JMP THOAT_INT0

TD5:

CJNE R1,#140,TD1N ;TOC DO CHAM

MOV BANH_TRAI_TD2,#250

MOV BANH_PHAI_TD2,#250

JMP THOAT_INT0

TD1N:

CJNE R1,#90,TD2N ;TOC DO CHAM

MOV BANH_TRAI_TD2,#60

MOV BANH_PHAI_TD2,#60

JMP THOAT_INT0

TD2N:

CJNE R1,#80,TD3N ;TOC DO CHAM

MOV BANH_TRAI_TD2,#40

MOV BANH_PHAI_TD2,#40

JMP THOAT_INT0

TD3N:

CJNE R1,#70,TD4N ;TOC DO CHAM

MOV BANH_TRAI_TD2,#30

MOV BANH_PHAI_TD2,#30

JMP THOAT_INT0

TD4N:

CJNE R1,#60,TD5N ;TOC DO CHAM

MOV BANH_TRAI_TD2,#10

MOV BANH_PHAI_TD2,#10

JMP THOAT_INT0

TD5N:

CJNE R1,#50,THOAT_INT0 ;TOC DO CHAM

MOV BANH_TRAI_TD2,#00

MOV BANH_PHAI_TD2,#00

JMP THOAT_INT0

THOAT_INT0:

RET

;******************** DELAY FET ******************

DELAY_FET:

MOV TMOD,#01

MOV TH0,#HIGH(-500)

MOV TL0,#LOW(-500)

SETB TR0

JNB TF0,$

CLR TR0

CLR TF0

RET

DELAY05S: MOV R2,#10

L6: MOV TMOD,#01H

MOV TH0,#HIGH(-50000)

MOV TL0,#LOW(-50000)

SETB TR0

JNB TF0,$

CLR TR0

CLR TF0

DJNZ R2,L6

RET

DELAY02S: MOV R2,#4

L63: MOV TMOD,#01H

MOV TH0,#HIGH(-50000)

MOV TL0,#LOW(-50000)

SETB TR0

JNB TF0,$

CLR TR0

CLR TF0

DJNZ R2,L63

RET

END

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: