$regfile = "ATtiny13.DAT"
$crystal = 128000 'Frequenz des internen 128kHz-Oszillators
$hwstack = 10 ' default use 32 for the hardware stack
$swstack = 10 'default use 10 for the SW stack
$framesize = 10 'default use 40 for the frame
Config Portb = &B11011101 'Portb.1.5auf 'Eingang' schalten
Portb = &B00100010 'Pullups Portb.1.5 zuschalten
Config Adc = Single , Prescaler = Auto , Reference = Internal 'Referenzspannung Des Adc Auf "Internal" = 1,1 V
Config Int0 = Rising
On Int0 Auswahl 'INT0 konfiguriren, wird nur benutzt um Powerdown zu beenden
Enable Int0
Dim Zaehler As Byte
Dim Impuls As Byte
Dim Wert1 As Word
Dim Wert2 As Word
Dim Schwelle As Word
Dim Anzahl As Byte
Wert1 = 1023
Stop Adc
Stop Ac
Anfang:
Gosub Ehufums
Enable Interrupts
Portb = &B00100010
Powerdown
Disable Interrupts
Zaehler = 1
Eineled:
For Impuls = 1 To 25
Portb = &B00100011
Gosub Funfms
Portb = &B00100010
Gosub Funfms
Next Impuls
Goto Pruefen
Blinkeineled:
For Impuls = 1 To 25
Portb = &B00100011
Gosub Funfms
Portb = &B00100010
Gosub Funfms
Next Impuls
Gosub Zhufums
Goto Pruefen
Dreiled:
For Impuls = 1 To 25
Portb = &B00110111
Gosub Zweims
Portb = &B00100010
Gosub Achtms
Next Impuls
Goto Pruefen
Blinkdreiled:
For Impuls = 1 To 25
Portb = &B00110111
Gosub Zweims
Portb = &B00100010
Gosub Achtms
Next Impuls
Gosub Zhufums
Goto Pruefen
Doppelblitz:
For Impuls = 1 To 15
Portb = &B00110110
Gosub Funfms
Portb = &B00100010
Gosub Funfms
Next Impuls
Gosub Ehufums
For Impuls = 1 To 15
Portb = &B00110110
Gosub Funfms
Portb = &B00100010
Gosub Funfms
Next Impuls
Gosub Zhufums
For Impuls = 1 To 50
Portb = &B00100011
Gosub Funfms
Portb = &B00100010
Gosub Funfms
Next Impuls
Gosub Dhufums
Goto Pruefen
Geo:
Portb = &B00100010
For Impuls = 1 To 100
Portb.0 = 1
Gosub Zweims
Portb.0 = 0
Gosub Achtms
Next Impuls
Start Adc
Config Portb.2 = Input 'Spannung an LED messen
Portb.2 = 0
gosub FUNFMS
Wert2 = Getadc(1)
Stop Adc
Config Portb.2 = Output
Portb.2 = 0
Schwelle = Wert1 + 75 'Schwelle (75 heller als Signal)festlegen, je kleiner so empfindlicher
If Wert2 > Schwelle Then
For Anzahl = 1 To 10 '3 LED für 10 Sekunden
For Impuls = 1 To 100
Portb = &B00110111
Gosub Funfms
Portb = &B00100010
Gosub Funfms
Next Impuls
Next Anzah
End If
Wert1 = Wert2 'Wert2 nach Wert1 verschieben
Goto Pruefen
Pruefen: 'Programmauswahl mit "Entprellung"
If Pinb.1 = 0 Then
Incr Zaehler
End If
Pruefena:
If Pinb.1 = 0 Then
Goto Pruefena
End If
If Zaehler > 6 Then
Zaehler = 0
End If
If Zaehler = 0 Then
Goto Anfang
End If
If Zaehler = 1 Then
Goto Eineled
End If
If Zaehler = 2 Then
Goto Blinkeineled
End If
If Zaehler = 3 Then
Goto Dreiled
End If
If Zaehler = 4 Then
Goto Blinkdreiled
End If
If Zaehler = 5 Then
Goto Doppelblitz
End If
If Zaehler = 6 Then
Goto Geo
End If
'Zeiten
Dhufums:
Waitms 100
Zhufums:
Waitms 100
Ehufums:
Waitms 142
Achtms:
Waitms 3
Funfms:
Waitms 3
Zweims:
Waitms 2
Return
Auswahl:
nop
Return
End
28.6.14: Revision der Revision von Martin Müller: RuecklichtRevision.pdf
'Original-Version: rucklichtlx.bas, Fahrrad-Rücklicht mit Reaktiv-Modus, von Martin Müller 09.04.2012.
'Änderunge: Ruecklicht-V2.bas / Peter Krueger, 28.06.2014
'Verwendeter uController:ATtiny13V-10PU (UB-min:1V8, UB-max:5V5)
'U-Bat. = 2V65: Strombedarf im "Powerdown" Mode = 0,113uA
'Zeile 22: Reference = "Avcc" Eine rote LED bringt im Dämmerlicht bereits eine Spannung von fast 1V (max 1V5)
'bei einer Ref von 1V1 wäre die ADC-Wandlung schon am Anschlag > 1023, die ADC-Reglschleife nicht mehr wirksam
'Zeile 26: Config Int0 = Low Level. Lösung von Ralf Beesner, vielen Dank Ralf!
'Zeile 129: Portb = &B00101010 'PB3.1, Start Zeitfenster LED1 = Input, Start Helligkeit messen
'Zeile 139: Portb = &B00100010 'PB3.0, Ende Zeitfenster LED1 = Input, Ende Helligkeit messen
$regfile = "ATtiny13.DAT" 'T13V Fuse: 1.2 MHz, BrownOut = 1V8
$crystal = 150000
'1ms Zeitverzögerung im Programmablauf entspricht jetzt: 150kHz / 1.2MHz = 125us
'Eine Blinkrate Faktor 8 mal höher als die Originalversion von Martin gefällt mir persönlich besser
$hwstack = 10 ' default use 32 for the hardware stack
$swstack = 10 'default use 10 for the SW stack
$framesize = 10 'default use 40 for the frame
Config Portb = &B11011101 'Portb.1.5 auf 'Eingang' schalten
Portb = &B00100010 'Pullups Portb.1.5 zuschalten
Config Adc = Single , Prescaler = Auto , Reference = Avcc 'Avcc: UB-potenzial / Internal: Adc Auf "Internal" = 1,1 V
Config Int0 = Low Level 'Danke für den Hinweis von Ralf Beesner !
On Int0 Auswahl 'INT0 konfigurieren, wird nur benutzt um Idle (Powerdown) zu beenden
Enable Int0
Dim Zaehler As Byte
Dim Impuls As Byte
Dim Wert1 As Word
Dim Wert2 As Word
Dim Schwelle As Word
Dim Anzahl As Byte
Wert1 = 1023
Stop Adc
Stop Ac
Anfang:
Gosub 142ms
Enable Interrupts
Portb = &B00100010
Powerdown ' Im Powerdeown Mode: 0,134uA !!
Disable Interrupts
Zaehler = 1
Eineled:
For Impuls = 1 To 25
Portb = &B00100011
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Goto Pruefen
Blinkeineled:
For Impuls = 1 To 25
Portb = &B00100011
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Gosub 100ms
Goto Pruefen
Dreiled:
For Impuls = 1 To 25
Portb = &B00110111
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Goto Pruefen
Blinkdreiled:
For Impuls = 1 To 25
Portb = &B00110111
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Gosub 100ms
Goto Pruefen
Doppelblitz:
For Impuls = 1 To 15
Portb = &B00110110
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Gosub 142ms
For Impuls = 1 To 15
Portb = &B00110110
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Gosub 100ms
For Impuls = 1 To 50
Portb = &B00100011
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Waitms 100
Goto Pruefen
Geo:
Portb = &B00100010
For Impuls = 1 To 100
Portb.0 = 1
Gosub 3ms
Portb.0 = 0
Gosub 3ms
Next Impuls
Portb = &B00101010 'PB3.1, Start Zeitfenster LED1 = Input, Helligkeit
Config Portb.2 = Input 'Spannung an LED messen
Waitms 3
'Portb.2 = 0
Start Adc
Wert2 = Getadc(1)
Stop Adc
Config Portb.2 = Output
Portb.2 = 0
Portb = &B00100010 'PB3.0, Ende Zeitfenster LED1 = Input, Helligkeit
Schwelle = Wert1 + 40 'Schwelle (100 heller als Signal)festlegen, je kleiner so empfindlicher
If Wert2 > Schwelle Then
For Anzahl = 1 To 100 '3 LED für etwa 8 Sekunden
For Impuls = 1 To 100
Portb = &B00110111
Gosub 3ms
Portb = &B00100010
Gosub 3ms
Next Impuls
Next Anzahl
End If
Wert1 = Wert2 'Wert2 nach Wert1 verschieben
Goto Pruefen
Pruefen: 'Programmauswahl mit "Entprellung"
If Pinb.1 = 0 Then
Incr Zaehler
End If
Pruefena:
If Pinb.1 = 0 Then
Goto Pruefena
End If
If Zaehler > 6 Then
Zaehler = 0
End If
If Zaehler = 0 Then
Goto Anfang
End If
If Zaehler = 1 Then
Goto Eineled
End If
If Zaehler = 2 Then
Goto Blinkeineled
End If
If Zaehler = 3 Then
Goto Dreiled
End If
If Zaehler = 4 Then
Goto Blinkdreiled
End If
If Zaehler = 5 Then
Goto Doppelblitz
End If
If Zaehler = 6 Then
Goto Geo
End If
'Zeiten
100ms:
Waitms 100
142ms:
Waitms 142
3ms:
Waitms 3
Return
Auswahl:
Nop
Return
End