; ; utility routine to drive an RC servo ; - asumptions - P1.7 ; wired to the white wire on the servo, the red wire (power) ; is wired to 6V and the black wire is connected to ground. ; ; calling conventions: ; always clear carry on return ; r1:r0 width of pulse in (11/12)uS ; ; the servo signal is a 1-2mS (depending on the stick positioon) ; pulse every 20mS or so - we measure the pulse by waiting for it ; to start then turning on the timer, and using the signal to gate ; the result. ; ; low values return ~0x3c0 high ones ~0x630 ; ; uses timer #0 as a side effect, leaves it idle ; ; for the record with a 11MHz rock there are 916.66666 timer clocks/mS ; put_rcout: clr p1.7 ; make it an input clr tr0 ; turn off timer #0 clr ie0 clr it0 mov a, r0 xrl a, #0xff mov tl0, a mov a, r1 xrl a, #0xff mov th0, a mov a, tmod ; set tmod anl a, #0xf0 orl a, #0x01 mov tmod, a clr tf0 setb p1.7 setb tr0 rco1: jnb tf0, rco1 clr p1.7 clr tr0 clr c ret