$MOD51
;Main Program
;kelompok 2 kendali posisi motor servo DC
;*********************************************************
Org 0000Hmov P0,#0 ;Control ADC
setb P0.3 ;set pin
INTsetb P0.7 ;set pin WR
mov P2,#0 ;Control Motor
setb P2.0 ;set pin Enable
Main_Prog:
call Serial_Port_Init
Main_Prog_Loop:
call Serial_Receive
call read_adc
call Serial_Transmit
sjmp Main_Prog_Loop
Serial_Port_Init:
mov SCON, #50H
mov RCAP2H, #0FFH
mov RCAP2L, #0F7H ; 0F7H utk 38400 bps, 0FAH utk 56800 bps
mov T2CON, #34H ; utk set bit TCLK,RCLK dan TR2 pada reg TCON
ret
Serial_Receive:
jnb RI, $
mov A, SBUF ;data received simpan di A
cjne A,#’A’,putarkanan
setb P2.2
clr P2.3
sjmp oke
putarkanan:
cjne A,#’B’,oke
clr P2.2
setb P2.3
oke:
call delay ;lama putar motor
clr P2.2
clr P2.3
clr RI
retread_adc:
setb P0.6
mov R4,100
djnz R4,$
clr P0.6
mov A,P1
ret
Serial_Transmit:
mov B, A
swap A
anl A, #00FH
call NibleToASCII
call Transmit
xch A, B
anl A, #00Fh
call NibleToASCII
call Transmit
ret
NibleToASCII:
add A,#036h
jnb ACC.6, Skip
add A,#7
Skip:
subb A,#6
ret
Transmit:
clr TI
mov SBUF, A ;kirimkan ke Buffer
jnb TI, $
ret
delay:
mov R5,#100
D01:
mov R6,#200
djnz R6,$
djnz R5,D01
ret
end