ATtiny13

1/12: LED-Blinker: Ttiny13_LED.bas

'ATtiny13 driving LEDs
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Portb = Output

Do
Portb.3 = 1
Toggle Portb.4
Waitms 500
Loop

End

2/12: Zeitschalter Ttiny13_Timer.bas

'Timer 60 s
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4

Config Portb.4 = Output
Portb.3 = 1 'Pullup

Do
Do
Loop Until Pinb.3 = 0
Portb.4 = 1
Waitms 60000
Portb.4 = 0
Loop

End

3/12: Transistor-Prüfer Ttiny13_Transistor.bas

'Transistor tester
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4


Dim U1 As Word
Dim U2 As Word
Dim I1 As Word
Dim I2 As Word
Dim V As Word

Config Adc = Single , Prescaler = Auto
Start Adc

Open "comb.1:9600,8,n,1,INVERTED" For Output As #1

Do
U1 = Getadc(3)
U1 = U1 * 50 'max 5115 mV
U2 = U1 - 6000 'Ube 600 mV
U1 = 51150 - U1
I1 = U1 '1 k
I2 = U2 / 100 '100 k
V = I1 / I2
Print #1 , V
Waitms 1000
Loop
End

4/12: Weicher LED-Blinker Ttiny13_Soft.bas

'LED soft flasher
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4
Dim I As Byte
Dim D As Integer

Config Portb = Output
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down

Do
For I = 40 To 215
If I < 128 Then
D = I
D = D * D
End If
If I > 127 Then
D = 255 - I
D = D * D
End If
D = D / 64
Pwm0a = D
Waitms 60
Next I
Waitms 800
Loop
End

5/12: Spannungs-Monitor Ttiny13_V_monitor.bas

'Voltage Monitor
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4

Dim U As Word

Config Adc = Single , Prescaler = Auto , Reference = Internal
Start Adc
Ddrb = &H07 'B0/1/2 outputs

Do
U = Getadc(3) '0...6.1V
If U < 797 Then '4.75 V
Portb = &H04 'red
Else
If U > 880 Then '5.25 V
Portb = &H01 'yellow
Else
Portb = &H02 'green
End If
End If
Waitms 1000
Loop
End

6/12: Dämmerungsschalter Ttiny13_LDR.bas

'Dämmerungsschalter
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4

Dim U As Word
Config Adc = Single , Prescaler = Auto
Start Adc
Config Portb = 1 'Output B.0

Do
U = Getadc(3)
If U < 400 Then Portb.0 = 0
If U > 600 Then Portb.0 = 1
Waitms 1000
Loop
End

9/12: U/F-Wandler Ttiny13_U2f.bas

'U/f Converter  0...5 V 0...600 Hz
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4

Dim U As Word
Dim A As Word

Config Adc = Single , Prescaler = Auto
Start Adc
Ddrb.4 = 1

Do
U = Getadc(3)
A = A + U
A = A And &H0FFF
If A >= &H0800 Then
Portb.4 = 1
Else
Portb.4 = 0
End If
Loop
End

10/12: NF-Millivoltmeter Ttiny13_ACmV.bas

'Millivoltmeter  1 mVeff ... 2000 mVeff
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4


Dim U1 As Integer
Dim U2 As Integer
Dim U3 As Long
Dim N As Integer

Config Adc = Single , Prescaler = Auto
Start Adc
Open "comb.1:9600,8,n,1,INVERTED" For Output As #1

Do
U2 = 0
For N = 1 To 64
U1 = Getadc(3)
U2 = U2 + U1
Next N
Shift U2 , Right , 3 ' /8
U3 = 0 ' Nullpunkt
For N = 1 To 2780
U1 = Getadc(3)
Shift U1 , Left , 3 ' *8
U1 = U1 - U2
U1 = Abs(u1)
U3 = U3 + U1
Next N ' / 64
Shift U3 , Right , 12 'Mittelwert
Print #1 , U3
Loop
End

11/12: Dreiphasen-Blinklicht Tiny13_3Phase.bas

'Dreiphasen-Blinker 1500ms, 0,67 Hz
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4
Config Portb = Output

Do
Portb.0 = 1
Waitms 250
Portb.3 = 0
Waitms 250
Portb.4 = 1
Waitms 250
Portb.0 = 0
Waitms 250
Portb.3 = 1
Waitms 250
Portb.4 = 0
Waitms 250
Loop
End

12/12: AM-Generator Ttiny13_AM.bas

'ATtiny13 AM Generator
$regfile = "attiny13.dat"
$crystal = 1200000
$hwstack = 8
$swstack = 4
$framesize = 4

Config Portb = Output
Dim N As Byte

Do
For N = 1 To 50 '70 kHz
Portb = 255
Portb = 0
Next N
For N = 1 To 50 'AM 750 Hz
nop
nop
Next N
Loop
End