stan cartwright - 2017-03-10
A 50Hz timer interrupt to refresh a servo and the ubiquitous scan left/right code on an arduino uno.
; A uno servo controller that refreshes the servo every 20ms
; servopos is the servo position
#chip mega328p,16
#config osc = int
#option Explicit
;
dim count as word
dim servopos as word
dim servodir as byte
#define servopin portb.0 ;uno pin 8
servopos=1500 ;us
servodir=1
dir servopin out
;
TCCR1A = 0x80;
TCCR1B = 0x0A;
OCR1AH = 0x9c;
OCR1AL = 0x3f;
On Interrupt Timer1Match1 call ISR
;main program
do
;
if servodir = 1 then
  servopos = servopos + 80 ;us
  if servopos = 2220 then ;end of servo turn
    servodir = 0
  end if
else
  servopos = servopos - 80 ;us
  if servopos = 780 then ;end of servo turn
    servodir = 1
  end if
end if
;
wait 1 s
  loop
;end main program
sub ISR
pulseout servopin,servopos us
end sub