Hi, Marcus
this one should work as desired ...
may be you'll have to modify a bit the " @ __config ......" line if you use PM as an assembler.Code:'**************************************************************** '* Name : GrassBurner.BAS * '* Author : Acetronics * '* Notice : Copyright (c) 2010 * '* : All Rights Reserved * '* Date : 23/12/2010 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** ' @ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF ' DEFINES Define OSC 8 Define BUTTON_PAUSE 0 ' Internal Osc 8Mhz OSCCON = %01110010 ' Turn off A/D conversion - Digital Inputs ADCON0 = 0 ANSEL = 0 ' Comparators Off CMCON = 7 'Define variables and pins I VAR BYTE Position var WORD Delay var Byte OldButton var bit PORTA = 0 TRISA = %11111101 BUTTON_ VAR PORTA.0 SERVO VAR PORTA.1 buttonloop: ' Button check loop OldButton = 0 LOW Servo Pulsout SERVO, 300 ' pulse to place servo to neutral Pause 19 BUTTON BUTTON_,1,255,0,Delay,0,Buttonloop OldButton = 1 ' Launched ... We've pressed it !!! '****************************************************************************** positionloop: 'Servo position control loop I = 0 ' Reset time counter While ( OldButton AND ( I < 75 )) ' if button has been pushed and time < 1.5s IF I >= 50 THEN ' 1 second is ... 50 x 20 ms ! position = 300 ELSE POSITION = 200 ENDIF LOW Servo Pulsout SERVO, Position ' pulse to servo PAUSEUs 19813 - ( Position * 5 ) ' time between pulses I = I+1 'Increase Time counter Wend ' go for seeking a new button push ... goto buttonloop End 'end of program supposed never reached
Also correct " IF I >= 50 ..." to i.e. " IF I >= 55 " to take servo positionning time into account ... knowing 1 unit is 20 ms.
Alain




Bookmarks