Em chào các cao thủ, e xin các cao thủ dịch giúp e đoạn code này từ AMS( Assembleur) sang C với, mỗi lệnh các đại ca chú thích giúp e nữa thì tốt cho em quá. Em là lính mới mong các đại ca chỉ giáo, ngàn lần cám ơn các pro !
C_A BIT P0.5
D_A BIT P0.6
EN_A BIT P0.7
FW BIT P3.5
STOP BIT P3.4
REV BIT P3.3
START BIT P3.2
DATA1 EQU P1
DEM EQU R1
CHIEUQUAY EQU R5
PWM EQU 30H
TRANGTHAI EQU R6
ORG 0000H
LJMP SETUP
ORG 000BH
LJMP NGATT0
ORG 001BH
LJMP NGATT1
ORG 0030H
SETUP:
SETB EA
SETB ET0
SETB ET1
MOV DATA1,#255
SETB START
MOV TMOD,#11H
MOV TH0,#HIGH(-1000)
MOV TL0,#LOW(-1000)
MOV TH1,#HIGH(-5000)
MOV TL1,#LOW(-5000)
SETB TR0
SETB TR1
MOV PWM,#1
MOV DEM,#0
MAIN:
JB FW,KTREV
JNB FW,$
MOV TRANGTHAI,#1
JMP MAIN
KTREV:
JB REV,KTSTOP
JNB REV,$
MOV TRANGTHAI,#2
JMP MAIN
KTSTOP:
JB STOP,MAIN
JNB STOP,$
LCALL DUNGCHAY
MOV TRANGTHAI,#3
JMP MAIN
NGATT1:
CLR TR1
MOV TH1,#HIGH(-5000)
MOV TL1,#LOW(-5000)
SETB TR1
LCALL READ_AD
RETI
NGATT0:
CLR TR0
MOV TH0,#HIGH(-1000)
MOV TL0,#LOW(-1000)
SETB TR0
PUSH ACC
MOV A,PWM
CJNE A,#0,DIEUXUNG
JMP THOAT_T0
DIEUXUNG:
CJNE TRANGTHAI,#1,NGUOC
INC DEM
MOV A,DEM
CJNE A,PWM,KTTIEP
LCALL DUNGCHAY
KTTIEP:
CJNE DEM,#100,THOAT_T0
LCALL CHAYTHUAN
MOV DEM,#0
LJMP THOAT_T0
NGUOC:
CJNE TRANGTHAI,#2,THOAT_T0
INC DEM
MOV A,DEM
CJNE A,PWM,KTTIEP1
LCALL DUNGCHAY
KTTIEP1:
CJNE DEM,#100,THOAT_T0
MOV DEM,#0
LCALL CHAYNGUOC
THOAT_T0:
POP ACC
RETI
READ_AD:
CLR START
LCALL DELAY100US
SETB START
MOV PWM,DATA1
RET
CHAYTHUAN:
SETB EN_A
CLR C_A
SETB D_A
RET
CHAYNGUOC:
SETB EN_A
SETB C_A
CLR D_A
RET
DUNGCHAY:
SETB EN_A
CLR C_A
CLR D_A
RET
DELAY100US:
MOV R7,#60
DJNZ R7,$
RET
END
C_A BIT P0.5
D_A BIT P0.6
EN_A BIT P0.7
FW BIT P3.5
STOP BIT P3.4
REV BIT P3.3
START BIT P3.2
DATA1 EQU P1
DEM EQU R1
CHIEUQUAY EQU R5
PWM EQU 30H
TRANGTHAI EQU R6
ORG 0000H
LJMP SETUP
ORG 000BH
LJMP NGATT0
ORG 001BH
LJMP NGATT1
ORG 0030H
SETUP:
SETB EA
SETB ET0
SETB ET1
MOV DATA1,#255
SETB START
MOV TMOD,#11H
MOV TH0,#HIGH(-1000)
MOV TL0,#LOW(-1000)
MOV TH1,#HIGH(-5000)
MOV TL1,#LOW(-5000)
SETB TR0
SETB TR1
MOV PWM,#1
MOV DEM,#0
MAIN:
JB FW,KTREV
JNB FW,$
MOV TRANGTHAI,#1
JMP MAIN
KTREV:
JB REV,KTSTOP
JNB REV,$
MOV TRANGTHAI,#2
JMP MAIN
KTSTOP:
JB STOP,MAIN
JNB STOP,$
LCALL DUNGCHAY
MOV TRANGTHAI,#3
JMP MAIN
NGATT1:
CLR TR1
MOV TH1,#HIGH(-5000)
MOV TL1,#LOW(-5000)
SETB TR1
LCALL READ_AD
RETI
NGATT0:
CLR TR0
MOV TH0,#HIGH(-1000)
MOV TL0,#LOW(-1000)
SETB TR0
PUSH ACC
MOV A,PWM
CJNE A,#0,DIEUXUNG
JMP THOAT_T0
DIEUXUNG:
CJNE TRANGTHAI,#1,NGUOC
INC DEM
MOV A,DEM
CJNE A,PWM,KTTIEP
LCALL DUNGCHAY
KTTIEP:
CJNE DEM,#100,THOAT_T0
LCALL CHAYTHUAN
MOV DEM,#0
LJMP THOAT_T0
NGUOC:
CJNE TRANGTHAI,#2,THOAT_T0
INC DEM
MOV A,DEM
CJNE A,PWM,KTTIEP1
LCALL DUNGCHAY
KTTIEP1:
CJNE DEM,#100,THOAT_T0
MOV DEM,#0
LCALL CHAYNGUOC
THOAT_T0:
POP ACC
RETI
READ_AD:
CLR START
LCALL DELAY100US
SETB START
MOV PWM,DATA1
RET
CHAYTHUAN:
SETB EN_A
CLR C_A
SETB D_A
RET
CHAYNGUOC:
SETB EN_A
SETB C_A
CLR D_A
RET
DUNGCHAY:
SETB EN_A
CLR C_A
CLR D_A
RET
DELAY100US:
MOV R7,#60
DJNZ R7,$
RET
END
Comment