' Demonstrate the SERVO command ' PortA.0 servo left.PortA.1 servo center.PortA.2 servo right Device 16F84 Declare XTAL 4 REMARKS ON Dim Pos as Word ' Servo Position Symbol Max_Right = 560 ' Maximum clockwise position Symbol Max_Left = 2480 ' Maximum Anti-clockwise position Pos = 1500 ' Center servo PORTA = 0 ' PORTA lines low TRISA = %00000111 ' Enable the button pins as inputs ' Check if any button pressed to move the servo Main: If PORTA.0=0 Then If Pos < Max_Left Then Pos=Pos+20 ' Move servo left If PORTA.1=0 Then Pos=1500 ' Center servo If PORTA.2=0 Then If Pos > Max_Right Then Pos=Pos-20' Move servo right Servo PORTB.1,Pos Delayms 10 ' Servo update rate Goto Main ' Do it forever