' Insanity
' Test mit OLED
$Regfile="M328pdef.dat"
$Crystal=8000000
$hwstack=64
$swstack=64
$framesize=64
' Spannungsteiler mit 12K zu 1K
' Bei 12V = 859 Digits
Const Spannung_Faktor = 12/885
' Shunt mit 0.01 Ohm
' Bei 15A = 140 Digits
Const Strom_Faktor = 15/120
'I2C Config
CONFIG I2CBUS= 0 , SCL=Port , SDA=sda
Config Scl = PortB.2
Config Sda = PortB.0
'Display Config
$lib "glcdSSD1306-I2C.lib" ' SSD1306 LIB einbinden
Config I2cdelay = 1
I2cinit
Waitms 10
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306" 'SSD1106 oder SSD1306
Cls
' Anlogfunktionen
Declare Function Analog(byval Kanal As Byte , Byval Anzahl As Word ) As Word
Config Adc = single , Prescaler = Auto , Reference = INTERNAL_1.1
Start Adc
Config Single = Scientific , Digits = 1
Wait 1
Dim Wert_U as Integer
Dim Wert_I as Integer
Dim Ergebnis As Single
Dim Ergebnis_U As Single
Dim Ergebnis_I As Single
Dim Dummy as String * 8
Setfont font12x16
Cls
Lcdat 1 , 1 , "Volt"
Lcdat 4 , 1 , "Amp."
Lcdat 7 , 1 , "Watt"
Lcdat 1 , 117 , "V"
Lcdat 4 , 117 , "A"
Lcdat 7 , 117 , "W"
Setfont Digital11x16
Do
Wert_U = Analog(3,1000)
Wert_I = Analog(2,1000)
Ergebnis_U = Wert_U * Spannung_Faktor
Dummy = Str(Ergebnis_U,1)
Ergebnis_U = Val(Dummy)
Dummy = " " + Dummy
Dummy = Right(Dummy,4)
Lcdat 1 , 70 , Dummy
Ergebnis_I = Wert_I * Strom_Faktor
Dummy = Str(Ergebnis_I,1)
Ergebnis_I = Val(Dummy)
Dummy = " " + Dummy
Dummy = Right(Dummy,4)
Lcdat 4 , 70 , Dummy
Ergebnis = Ergebnis_I * Ergebnis_U
Dummy = Str(Ergebnis,1)
Dummy = " " + Dummy
Dummy = Right(Dummy,5)
Lcdat 7 , 59 , Dummy
Loop
' Analog messen
Function Analog(Kanal , Anzahl)
Local Schleife As Word
Local Analogmesswert As Word
Local Analogmesswert_summe As Long
Local Analog_mittel As Long
If Anzahl = 0 Then Anzahl = 1
Analogmesswert_summe = 0
For Schleife = 1 To Anzahl
Analogmesswert = Getadc(Kanal)
Analogmesswert_summe = Analogmesswert_summe + Analogmesswert
Next
Analog_mittel = Analogmesswert_summe / Anzahl
Analogmesswert = Analog_mittel
Analog = Analogmesswert
End Function
'LCD-Font
$include "font12x16.font"
$include "Digital11x16.font"
|