|
Org
00h
mov r0,#01h ; initileze key count
mov p1,#0ffh ; P1
as input port
lop: mov a,p1
cjne a,#0ffh,jmp
ajmp lop ;
loop until any key
; is pressed
jmp: clr p0.0 ;
indicates keypress
loop: rrc a
jnc num ;
get key no.
inc r0
sjmp loop
num: acall dely ; key debounce delay
setb p0.0
cjne r0,#01h,nxt ;
for 1st key
acall clkwise ;
rotate motor
sjmp over ;
clock wise
nxt: cjne r0,#02h,over ;
for 2nd key
acall aclkwise ;
rotate anticlock
over: mov p2,#00h ;
restore initial
mov p1,#0ffh ;
data and
mov r0,#01h
sjmp lop ;
jump to loop again
clkwise:
mov r1,#32h ; load
count 50d
go: clr p0.1
mov p2,#01h ;give 4
pulses in loop
acall delay ;
total 200 pulses
mov p2,#02h ; each
coil energized
acall delay ;
one by on in single
setb p0.1
mov p2,#04h ; coil
excitation
acall delay ; 30 ms
delay in betwn
mov p2,#08h ; means
speed is
acall delay ; 10
RPM
djnz r1,go
ret |
aclkwise:
mov r1,#32h
go1:clr p0.2
mov p2,#01h
acall delay
mov p2,#08h ; revert
the pulse
acall delay ;
sequence for
setb p0.2
mov p2,#04h ;
anticlockwise
acall delay
mov p2,#02h
acall delay
djnz r1,go1
ret
delay:
mov r5,#1Eh ; load
count 30
lop2: mov r6,#FAh ; give 1 ms
delay
lop1:nop ;
so it gives full
nop
; 30 ms delay
djnz r6,lop1
djnz r5,lop2
ret
dely:
mov r5,#0C8h ; load count 200
lop2: mov r6,#0FAh ; for 200ms
delay
lop1:nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end
|
|
Org 00h
mov r0,#01h ;
initileze key count
mov p1,#0ffh ; P1
as input port
lop: mov a,p1
cjne a,#0ffh,jmp
ajmp lop ;
loop until any key
; is pressed
jmp: clr p0.0 ;
indicates keypress
loop: rrc a
jnc num ;
get key no.
inc r0
sjmp loop
num: acall dely ; key
debounce delay
setb p0.0
cjne r0,#01h,nxt ;
for 1st key
acall clkwise ;
rotate motor
sjmp over ;
clock wise
nxt: cjne r0,#02h,over ;
for 2nd key
acall aclkwise ;
rotate anticlock
over: mov p2,#00h ;
restore initial
mov p1,#0ffh ;
data and
mov r0,#01h
sjmp lop ;
jump to loop again
clkwise:
clr p0.1
mov p2,#01h ;give 4
pulses in loop
acall delay ; as 1.8o
step resolution
mov p2,#02h ; total
7.2o rotation
acall delay ; in
single coil
setb p0.1
mov p2,#04h ;
excitation
acall delay ; 30 ms
delay in betwn
mov p2,#08h; means
speed is
acall delay ; 10
RPM
ret |
aclkwise:
clr p0.1
mov p2,#01h
acall delay
mov p2,#08h ; revert
the pulse
acall delay ;
sequence for
setb p0.1
mov p2,#04h ;
anticlockwise
acall delay
mov p2,#02h
acall delay
ret
delay:
mov r5,#1Eh ; load
count 30
lop2: mov r6,#FAh ; give 1 ms
delay
lop1:nop ;
so it gives full
nop
; 30 ms delay
djnz r6,lop1
djnz r5,lop2
ret
dely:
mov r5,#0C8h ; load count 200
lop2: mov r6,#0FAh ; for 200ms
delay
lop1:nop
nop
djnz r6,lop1
djnz r5,lop2
ret
end
|