Вот готовый проект от MCS Electronics http://www.mcselec.com/index.php?option … ;Itemid=57 .а вот мой проект :
$regfile = "Attiny13.dat"
$crystal = 9600000
$hwstack = 16
$swstack = 8
$framesize = 16
Config Portb.3 = Input
Config Portb.4 = Input
Config Portb.2 = Output
Config Portb.1 = Output
Config Portb.0 = Output
'@genus(1)
Config Timer0 = Pwm , Prescale = 8 , Compare A Pwm = Clear Down
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Dim Pulse As Word
Dim Min_pulse As Word
Dim Max_pulse As Word
Dim Min_pulse_eram As Eram Word
Dim Max_pulse_eram As Eram Word
Dim D_pulse As Word
Dim Pulse_out As Word
Dim Bat As Word
Key Alias Pinb.4
Led_red Alias Portb.1
Led_green Alias Portb.2
If Max_pulse_eram = 65535 Or Min_pulse_eram = 65535 Or Key = 0 Then
Gosub Set_pulse
Else
Max_pulse = Max_pulse_eram
Min_pulse = Min_pulse_eram
End If
D_pulse = Max_pulse - Min_pulse
Setup_min:
Do
Gosub Getpulse
Gosub Flash_red
Loop Until Pulse =< Min_pulse
Do
Start Adc
Bat = Getadc(2)
If Bat < 827 Then
Reset Led_green
Goto Setup_min
Else
Set Led_green
End If
Gosub Getpulse 'measure rx input
Gosub Setpulse 'set motor speed
Loop
Set_pulse:
Set Led_red
Set Led_green
Gosub Key_wait
Max_pulse = Pulse - 15
Max_pulse_eram = Max_pulse
Reset Led_red
Gosub Key_wait
Min_pulse = Pulse + 15
Min_pulse_eram = Min_pulse
Reset Led_green
Wait 2
Return
Setpulse:
If Err = 1 Then
Gosub Flash_red
Goto Done
End If
If Pulse < Min_pulse Then
Pwm0a = 0
Goto Done
End If
If Pulse =< Max_pulse Then
Pulse_out = Pulse - Min_pulse
Pulse_out = Pulse_out * 100
Pulse_out = Pulse_out / D_pulse
Pulse_out = Pulse_out * 255
Pulse_out = Pulse_out / 100
Pwm0a = Pulse_out
Else
Pwm0a = 255
End If
Done:
Return
Getpulse:
Pulsein Pulse , Pinb , 3 , 1
Return
Key_wait:
Wait 3
Bitwait Key , Reset
Gosub Getpulse
Return
Flash_red:
Pwm0a = 0
Set Led_red
Waitms 150
Reset Led_red
Waitms 300
Return
Надо только отредактировать файл mcs.lib .В разделе [_PULSE_IN] @genus(9) исправить на @genus(1) и откампилировать его.
Программа без коментариев ткак что если будут вопросы спрашивайте
Отредактировано MDK_1 (2010-06-18 13:16:46)