Mini-Programme für den Tiny13      


Elektronik-Labor  Projekte  AVR 

 

In Elektor gab es 2012 eine Serie "Zurück zu den Wurzeln", die man jetzt noch in dem Buch Elektronik-Grundlagen und Einsteiger-Projekte findet. Es ging um Elektronik-Grundlagen, also einfache analoge Transistorschaltungen. Nur so zum Kontrast hatte jede Folge aber auch ein kleines Mikrocontroller-Projekt mit dem Tiny13. Oft wurde die zuvor analog gelöste Aufgabe noch einem zum Kontrast mit dem Controller gelöst. In anderen Fällen ging es um nützliche Messtechnik mit dem Controller.

Alle diese kleinen Programme habe ich mit der Tiny13-Platine aus dem Franzis Lernpaket Mikrocontroller entwickelt. Einfach weil sie gerade da war und wenig Aufwand bedeutete. Fast immer konnte die nötige Schaltung einfach aufgesteckt werden. Achtung, wenn man den Bootloader des Lernpakets benutzt und dann die Anwendung autonom ohne Verbindung mit der Schnittstelle betreiben möchte, muss die TXD-Leitung vom PC an Masse liegen, damit der Controller nicht beim Start versehentlich in den Boot-Modus rutschen kann.

Im Laufe des Kurses kamen immer mal wieder Fragen auf. Teilweise lag es daran, dass ich die Programme mit einer ältern Bascom-Version geschrieben hatte. Teilweise hatte ich die Stack-Einstellungen noch nicht im Quelltext stehen, was leicht zu Fehlern führen kann, wenn man mit verschiedenen Controllern arbeitet. Erst in den späteren Folgen wurden die Programme auf der Elektor-Seite zum Download abgelegt. Damit alle angefallenen Verbesserungen leicht zugänglich sind, möchte ich hier alle zehn Programme mit Quelltext und Hexfile zum Download anbieten. und zu schnellen Übersicht auch den Quelltexte zeigen. Die Programme wurden mit Bascom in der Version 1.11.9.8 übersetzt.


Download: BascomEL2012.zip

 

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, siehe auch Transistor-Testgerät

'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,  siehe auch Millivoltmeter

'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, siehe auch AM-Prüfoszillator mit Mega8

'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



Elektronik-Labor  Projekte  AVR