Hi, Atom
Those lines Have Passed the MPSIM Test ...
Try those lines ... should work !!!Code:@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; Using Internal Clock, no clock out @ DEVICE pic12F629, WDT_ON ; Enable Watch dog timer @ DEVICE pic12F629, PWRT_ON ; Enable Power-up timer @ DEVICE pic12F629, MCLR_OFF ; Disable MCLR pin @ DEVICE pic12F629, BOD_ON ; Enable Brown-out detect @ DEVICE pic12F629, CPD_OFF ; EEPROM Protect @ DEVICE pic12F629, PROTECT_OFF ; Code Protect off '@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF DEFINE OSCCAL_1K 1 DEFINE BUTTON_PAUSE 20 GPIO = %00000000 TRISIO = %11111110 INTCON.6=0 ' Disable all unmasked Interrupts INTCON.7=0 ' Disable Global Interrupts CMCON = 7 ' Disable analog comparator ServoOut var GPIO.0 SetLimitSw var GPIO.1 PotIn var GPIO.2 MinSw var GPIO.4 MaxSw var GPIO.5 Delay var Byte Posit var Byte MinPosit var Byte MaxPosit var Byte 'load starting min and max positions at program time data @ 0,100 data @ 2,250 '************************************************* *************** low Servoout 'read in stored min and max limits read 0, MinPosit read 2, MaxPosit Start: gosub GetServoPosition Low servoout pulsout servoout, posit Delay = 0 BUTTON setlimitsw, 0, 255, 0, Delay, 1, Start Delay = 0 BUTTON minsw, 1, 255, 0, Delay, 1, MinL '20 ms Delay = 0 BUTTON maxsw, 1, 255, 0, Delay, 1, MaxL ' 20 ms pause 20 ' no button pushed Goto Start MinL: IF maxsw = 1 THEN Start '1 Button pushed at a Time !!! IF Posit <> MinPosit THEN MinPosit = Posit write 0, MinPosit '10 ms ENDIF goto start MaxL: IF minsw = 1 THEN Start '1 Button pushed at a Time !!! IF Posit <> Maxposit THEN MaxPosit = Posit write 2, MaxPosit ' 10 ms ENDIF goto start '************************************************* *************** GetServoPosition: high potin pause 1 rctime potin, 1, Posit 'at 4 mhz, returns 3 - 123 :: 1.23 ms max 'adjust posit to get values between 75 and 250 posit = posit + 75 + (posit / 2) 'now limit posit to 100 - 250 (1 ms - 2.5 ms) if posit < 100 then posit = 100 if posit > 250 then posit = 250 if setlimitsw = 0 then 'apply limits if Posit < MinPosit then Posit = MinPosit if Posit > MaxPosit then Posit = MaxPosit endif return '************************************************* *************** End
Alain




Bookmarks