bvan3
Newbie level 1
I want to control my PWM with my 8051 DIP switches and I need help
ORG 0000H
MAIN:
CLR P1.0
CLR P1.1
CLR P1.2
CLR P2.7
CLR P2.6
CHECKMOTOR:
JB P2.0, CONTROL
JNB P2.0, MOTOROFF
CONTROL:
SETB P1.0
JNB P2.7,CLOCKWISE
CLR P1.1
SETB P1.2
SJMP CHECKMOTOR
CLOCKWISE:
SETB P1.1
CLR P1.2
SJMP CHECKMOTOR
NORMAL:
JNB P2.6, FIFTYPERCENT
SETB P1.0
MOV R5,#25
ACALL DELAY
CLR P1.0
MOV R5,#75
ACALL DELAY
SJMP NORMAL
FIFTYPERCENT:
SETB P1.0
MOV R5,#50
ACALL DELAY
CLR P1.0
MOV R5,#50
ACALL DELAY
SJMP NORMAL
DELAY:
H1: MOV R2,#100
H2: MOV R3,#255
H3: DJNZ R3,H3
DJNZ R2,H2
DJNZ R5,H1
MOTOROFF:
SETB P1.0
RET
END
ORG 0000H
MAIN:
CLR P1.0
CLR P1.1
CLR P1.2
CLR P2.7
CLR P2.6
CHECKMOTOR:
JB P2.0, CONTROL
JNB P2.0, MOTOROFF
CONTROL:
SETB P1.0
JNB P2.7,CLOCKWISE
CLR P1.1
SETB P1.2
SJMP CHECKMOTOR
CLOCKWISE:
SETB P1.1
CLR P1.2
SJMP CHECKMOTOR
NORMAL:
JNB P2.6, FIFTYPERCENT
SETB P1.0
MOV R5,#25
ACALL DELAY
CLR P1.0
MOV R5,#75
ACALL DELAY
SJMP NORMAL
FIFTYPERCENT:
SETB P1.0
MOV R5,#50
ACALL DELAY
CLR P1.0
MOV R5,#50
ACALL DELAY
SJMP NORMAL
DELAY:
H1: MOV R2,#100
H2: MOV R3,#255
H3: DJNZ R3,H3
DJNZ R2,H2
DJNZ R5,H1
MOTOROFF:
SETB P1.0
RET
END