Исходный текст, написанный в среде Bascom:
$regfile = "attiny13.dat" $crystal = 9600000 $hwstack = 0 ' default use 32 for the hardware stack $swstack = 0 ' default use 10 for the SW stack $framesize = 0 Config Portb.3 = Output 'выход для подключения ноги Trigger Trigger Alias Portb.3 Trigger = 0 Config Portb.4 = Input 'вход для импульса Echo Config Portb.0 = Output 'конфигурация для подключения светодиода Led Alias Portb.0 Led = 0 Config Portb.1 = Output 'output control pin Control Alias Portb.1 Control = 0 Config Portb.2 = Input 'вход для button Dim A As Word , A2 As Word 'сюда копируется значение длины сигнала Dim M As Word , Em As Eram Word Dim I As Byte , T As Word , Tled As Byte Const Toff = 750 '250=1min '500 'TIME to OFF Const Tmax = 50000 Enable Interrupts 'enable global ints Enable Pcint0 'we enable pcint0 as this has pcint0-pcint7 On Pcint0 Btn 'we jump to this label when one of the pins is changed Pcmsk = &B00000100 'enable pcint2 (portb.2) Config Watchdog = 1024 '8192 '2048 M = Em : T = Tmax : Tled = 0 : Control = 0 : Led = 0 Start Watchdog Do Reset Watchdog Gosub Test A2 = A Waitms 100 Reset Watchdog Gosub Test Waitms 100 If A < M And A2 < M And A > 0 And A2 > 0 Then T = 0 ': Led = 1 Else Incr T ' : Led = 0 If T > Tmax Then T = Tmax End If If T < Toff Then Control = 1 Else Control = 0 End If If T = 0 Then If Tled < 9 Then : Led = 1 : Else : Led = 0 : End If ' on Else If T < Toff Then If Tled < 5 Then : Led = 1 : Else : Led = 0 : End If ' last minute Else If Tled < 1 Then : Led = 1 : Else : Led = 0 : End If ' off End If End If Incr Tled : If Tled > 10 Then Tled = 0 Loop End '------------------------------------------------------------------------------------ Btn: For I = 1 To 50 Toggle Led : Waitms 200 : Reset Watchdog Next Gosub Test 'Gifr = 0 M = A : Shift M , Right , 3 : M = A -m : Em = M : T = Tmax 'Tled = 0 : Control = 0 Set Led ': Waitms 2000 : Reset Led : Waitms 1000 Do : Loop Return '----------------------------------------------------------------------------------- Test: Trigger = 1 'даем импульс на ногу Portd.4 длительностью 15 мкс Waitus 15 Trigger = 0 Waitus 10 Pulsein A , Pinb , 4 , 1 'ловим импульс высокого уровня Return '-----------------------------------------------------------------------------------
Для изменения времени горения лампы редактировать строку
Const Toff = 750
исходя из того, что число 250 соответствует 1 минуте.