有空再学学PIC单片机,它的PICBASIC开发软件用起来很简单,其中有舵机的专用指令,学起来很简单!
我发一个PICBASIC的8通道编码程序,贼简单,但功能较少;你只要会数学计算:em06:要在编码程序里加入各种曲线混控功能或其他乱七八糟的功能那只是小儿科的是,俺试过加入直升机用四舵机90度CCPOM混控功能,还可以!
' 4 Channel radio control encoder, by G.Kuhn ZS1NZ
' Change nx value for more or less channels, compensate with Frame
Device 16F877 ' Using the 16F877
Declare XTAL 4 ' 4Mhz crystal
symbol pulse PortB.0 ' Pulse train out pin is PortB bit-0
Declare ADIN_TAD FRC ' Choose the RC osc for ADC samples
Declare ADIN_STIME 100 ' Allow 100us for charge time
Dim adcval as Word ' Variable to store ADC result
Dim nx as byte ' Variable for loop count
Dim trim as word ' Part of pulse length calculation
Dim out as word ' Part of pulse length calculation
Dim init as word ' Part of pulse length calculation
trisa = %11111111 ' Set port A all inputs
trisb = %11111110 ' Set port B.0 as output
ADCON1 = %10000000 ' Right justified result 10 bit value
trim = 1700 ' Fine tune pulse edge to edge length here
Again: for nx = 0 to 3 ' Loop to scan first 4 ADC's, can be 8
set pulse ' Make out pin high
adcval = adin nx ' Load AD value into variable
init = (((adcval+4)/2/2)*18)' Scale the result
'init = (((adcval+4)/4)*18) ' Les, why doesn't this work ?
out = init - trim ' Calculate output pulse
pauseus out ' Output pulse
low pulse ' Make out pin low
pauseus 400 ' Fixed off period for each stick
next nx ' Do this four times
set pulse ' Start of frame sync
Frame: pauseus 14000 ' Total frame length about 20 milliseconds
low pulse ' End of frame sync
goto again ' Repeat the scan
看到红色字体那一句没有?修改这一句就可以添加到8通道去!
:em15::em15::em15:
[ 本帖最后由 狐狸 于 2006-2-21 11:50 编辑 ] |