' TPS-T13-Poti4Led
'
' Pin5: PB0/oc0a/mosi = S1
' Pin6: PB1/0c0b/miso = LEDgrün (gelb)
' Pin7: PB2/Adc1/sck = S2
' Pin2: PB3/Adc3/clkin = LEDrot (blau)
' Pin3: PB4/Adc2/pcint4 = LEDgelb (Katoden/Anoden)
' Pin1: PB5/Adc0/Reset = 10k-Poti
'-------------------------------------------------------------------------------
' ___ grün rot ___ +Vcc
' B1/gn o--|___|--+--|>|--+--|<|--+--|___|--o B3/rt _
' 470 | | | 470 ___ | |Poti
' \--|<|--+--|>|--/ Reset o-|___|-->| |10k
' gelb | blau 2k2 |_|
' X2a X1
' o |
' B4/ge (GND = nur rot/grün) GND
'-------------------------------------------------------------------------------
' - S1 bei Res halten -> PrgMode
' - grün -> S1 halten -> Poti einstellen -> S1 loslassen -> Kom
' - rot -> S1 halten -> Poti einstellen -> S1 loslassen -> Dat(+Kom) -> EEPROM
' - am Schluss bei grün Reset
'-------------------------------------------------------------------------------
' Beispiel Voltmeter an X1(offen) = Vcc=3V in 0,2V-Stufen, Vcc=5V in 1/3V-Stufen :
' 60 Mux=Adc, 31 Jr -1
' Poti auf '0'-Anzeige stellen, dann X1 öffnen (auch für Durchgang und Led geeignet,
' ggf. für negative Spannungen das Poti vorher auf '8' verstellen/eichen).
' Beispiel Lampentest (statisch gemuxt): 15 18 32
$regfile = "attiny13.dat"
$crystal = 1200000 'FF 22 FF preserve EEPROM
'$crystal = 9600000 'FF 32 FF preserve EEPROM
$hwstack = 12
$swstack = 16
$framesize = 16
Lgruen Alias Portb.1 : Lrot Alias Portb.3 : Lgelb Alias Portb.4
S1 Alias Pinb.0 : S2 Alias Pinb.2
Res_adc Alias Getadc(0) 'Adc(0) an Reset
Config Adc = Single , Prescaler = Auto , Reference = Avcc : Start Adc
Const Entprellen = 100 'ms
Const Gblang = 1 'ms gelb/blau Leuchtdauer
Ddrb = &B0001_1010
Declare Sub Hl 'EEPROM-Adresse High+Low
Declare Sub Incadr 'PC = PC + 1
Declare Sub Mux 'Ausgabe dynamisch
Declare Sub Porb 'Ausgabe statisch
Declare Sub Poti 'Poti an Reset liefert "0 bis 15"
Declare Sub S1_0 'bis S1 = Vcc
Declare Sub S1_1 'bis S1 = Gnd
Dim A As Byte , C As Byte , Tb As Byte , Tw As Word
Dim Addr As Byte , Kom As Byte , Dat As Byte , Eebyte As Byte , Adrhi As Byte
'-------------------------------------------------------------------------------
Addr = 0 : If S1 = 0 Then Goto Programmieren 'S1 nach Reset ? Prg-Mode
Do 'Run-Mode
Readeeprom Eebyte , Addr
Dat = Eebyte And 15
Kom = Eebyte : Shift Kom , Right , 4 'Kom = Kom / 16
A = A And 15
If Kom = 1 Then Porb '1_ B4,B3,B2,B1
If Kom = 2 Then : Restore Dta : Tw = Lookup(dat , Dta) : Waitms Tw : End If '2_ Wartezeit
If Kom = 3 Then Addr = Addr - Dat Else Incadr '3_ Jr -dat
If Kom = 4 Then A = Dat '4_
If Eebyte = &H50 Then A = A + C
If Eebyte = &H51 Then A = A - C
If Eebyte = &H52 Then C = A '5_ C=A
If Eebyte = &H60 Then : Poti : : Mux : End If 'Mux=Poti
If Eebyte = &H61 Then : Poti : A = Tw : End If 'A=Poti
If Eebyte = &H62 Then : Dat = A : Porb : End If 'Port=A
If Kom = 8 Then Adrhi = Dat * 16 '8_ Oberes Nibble der Adr 0-3 = 64Byte
If Kom = 9 Then Hl '9_ Springe absolut 0...255
If Kom = 10 Then : C = C - 1 : If C > 0 Then Hl : End If 'A_ C-mal
If Eebyte = &HC4 Then : If S1 = 1 Then Incadr : End If 'C_ Skip if
If Eebyte = &HC5 Then : If S2 = 1 Then Incadr : End If
Loop
'-------------------------------------------------------------------------------
Programmieren: 'Prg-Mode
S1_0 'bis S1 = Vcc
Do
Portb = &B00111 : S1_1 : Eebyte = Tw * 16 'grün=Kom
Portb = &B01101 : S1_1 : Eebyte = Eebyte + Tw 'rot=Dat
Writeeeprom Eebyte , Addr : Incadr
Loop
'-------------------------------------------------------------------------------
Sub Hl : Addr = Adrhi + Dat : End Sub 'Byte-Adresse High+Low 00-3F
'-------------------------------------------------------------------------------
Sub Incadr : Addr = Addr + 1 : End Sub 'PC = PC + 1
'-------------------------------------------------------------------------------
Sub Mux '4Led dynamische Ausgabe
Portb = &B11111 'Pullup B0+B2
Tb = Tw And 4 : If Tb = 4 Then Lgruen = 0 'gelb (2^2)
Tb = Tw And 8 : If Tb = 8 Then Lrot = 0 'blau (2^3)
Waitms Gblang 'Leuchtdauer
Portb = &B00101 'Pullup B0+B2
Tb = Tw And 1 : If Tb = 1 Then Lgruen = 1 'grün(2^0)
Tb = Tw And 2 : If Tb = 2 Then Lrot = 1 'rot (2^1)
End Sub
'-------------------------------------------------------------------------------
Sub Porb : Tb = Dat * 2 : Portb = Tb Or 5 : End Sub 'statische Ausgabe
'-------------------------------------------------------------------------------
Sub Poti : Tw = Res_adc - 512 : Shift Tw , Right , 5 : End Sub
'-------------------------------------------------------------------------------
Sub S1_1 : Do : Loop Until S1 = 0 : Goto S22 : End Sub 'bis S1 = Gnd
'--------
Sub S1_0
S22:
Do : Poti : Mux : Loop Until S1 = 1 'bis S1 = Vcc
Waitms Entprellen 'entprellen
End Sub
End
'-------------------------------------------------------------------------------
Dta:
Data 1% , 2% , 5% , 10% , 20% , 50% , 100% , 200% , 500% , 1000% , 2000% , 5000% , 10000% , 20000% , 30000% , 60000%
'END ---------------------------------------------------------------------------