Code:
$regfile = "m128def.dat" 'ATMega 8, anpassen bei anderen
$crystal = 16000000 '8 MHz Takt, bei höherem Takt muss evtl. die Ausgabegeschwindigkeit der Daten an das
'Display gedrosselt werden. Also erst mit 8 MHz testen um zu sehen, dass alles klappt,
$include "Config_MMC.BAS"
$include "CONFIG_AVR-DOS.BAS"
Dim Temp1 As Byte , Temp2 As Byte , Temp3 As Byte , Temp4 As Byte
Dim Drehung As Byte
Dim Fontbreite As Byte , Fonthoehe As Byte , Xpixel As Byte , Ypixel As Byte
Dim R As Integer , X1 As Byte , X2 As Byte , Y1 As Byte , Y2 As Byte , E As Byte , F As Integer , G As Long , Zeichen As String * 1
Dim A As Byte , B As Byte , C As Integer , D As Integer , T1 As Byte , T2 As Byte
Dim Befehl As Byte , Ausgabe As Byte
Dim Pix As Byte , Gapx As Double , Gapy As Double , S As Byte
Dim X As Byte , Y As Byte , H As Integer , M As Integer , Pixel As Integer , Schleife As Integer , Hx As Integer , Hy As Integer , Xinc As Integer , Yinc As Integer
Dim Temp As Byte
Dim Lcd_command As Byte , Lcd_data As Byte , Lcd_string As String * 22 , Fontsize As Byte , Lcd_fcolor As Byte , Lcd_bcolor As Byte
Dim Lx1 As Byte , Ly1 As Byte , Lx2 As Byte , Ly2 As Byte , Color As Byte , Zeichenarray(6) As Byte
'---------------------------------------------------------------------------------------------------------------------------------------------------
'Übernahme der aktuellen Portbelegung in Variablen bzw. Konstanten. Durch Änderung der folgenden Zeilen kann dass Programm auf jede andere Anschlussbelegung geändert werden,
'wenn man das Display in einer anderen Konfiguration (z.B. einem eigenen Board) nutzt.
Lcd_port Alias Portb 'Port B wird also hier im Programm mittels "LCD_Port" angesprochen.
Ddrb = &B01100110 'Port B: alles display lines: output (1)
Const Rs = 6 'also Port b.6
Const Cs = 5 'also Port b.5
Const Sdata = 2 'also Port b.2
Const Sclk = 1 'also Port b.1
'---------------------------------------------------------------------------------------------------------------------------------------------------
Const Kommando = 0 'Durch eine "0" wird dem Display mitgeteilt, dass nun ein Kommando folgt
Const Parameter = 1 'Durch eine "1" wird dem Display mitgeteilt, dass nun ein Parameter folgt
Const Blau = &B00000011 'Vordefinierte Konstanten für die Farbwerte machen das Programmiererleben leichter:
Const Gelb = &B11111100
Const Rot = &B11100000
Const Gruen = &B00011100
Const Schwarz = &B00000000
Const Weiss = &B11111111
Const Hellgruen = &B00111110
Const Dunkelgruen = &B00010100
Const Dunkelrot = &B10100000
Const Dunkelblau = &B00000010
Const Hellblau = &B00011111
Const Orange = &B11111000
'----------------------------------------------------------------------------------------------------------------------------------------------------
'####---------------AD-Wandler--------------#####'
Config Adc = Single , Prescaler = Auto , Reference = Internal ' Prescaler = Auto
Start Adc
Config Portf.0 = Input 'Portf.0-3 =Input
Config Portf.1 = Input
Config Portf.2 = Input
'####--------------MMC-Karte--------------#####'
Config Serialin = Buffered , Size = 20
Config Clock = Soft
Enable Interrupts
Config Date = Dmy , Separator = .
Dim Btemp1 As Byte
Dim Text As String * 10 , Placeholder As String * 5
Placeholder = ";"
'####----------------Eingangs Variablen--------------#####'
Dim Vout1xw As Word
Dim Vout1x As Single
Dim Vout1xstr As String * 4
Dim Vout1yw As Word
Dim Vout1y As Single
Dim Vout1ystr As String * 4
Dim Vout1zw As Word
Dim Vout1z As Single
Dim Vout1zstr As String * 4
Dim Vout2xw As Word
Dim Vout2x As Single
Dim Vout2xstr As String * 4
Dim Vout2yw As Word
Dim Vout2y As Single
Dim Vout2ystr As String * 4
Dim Vout2zw As Word
Dim Vout2z As Single
Dim Vout2zstr As String * 4
Dim J As Byte
'####---------------Switches Variablen----------------#####'
Dim Marker As Single
Dim Markerstr As String * 1
Config Pind.4 = Input 'Marker
Portd.4 = 1
Config Pind.5 = Input 'RUN
Portd.5 = 1
Config Pind.6 = Input 'Halt
Portd.6 = 1
'####---------------Time Variablen----------------#####'
Config Timer1 = Timer , Prescale = 256 'Konfiguriere Timer1
On Timer1 Timer_irq 'schalte den Timer1 ein
Const Timervorgabe = 3036
Enable Timer1
Enable Interrupts 'Timer1 soll schon von 34285 wegzählen
Timer1 = Timervorgabe
Dim Second As Single
Dim Secondstr As String * 4
Second = 0
Dim Minute As Single
Dim Minutestr As String * 4
Minute = 0
Dim Hour As Single
Dim Hourstr As String * 4
Hour = 0
Dim Referenzspannung As Word
Referenzspannung = 3.85
'---------------------------------------------------------------------------------------------------------------------------------------------------
'Hauptprogramm
'---------------------------------------------------------------------------------------------------------------------------------------------------
Gosub Lcd_init
Gosub Lcd_cls
'---------------------------SD Anfang---------------------------------------------
If Gbdriveerror <> 0 Then
Lcd_string = "Drive error" : Lx1 = 5 : Ly1 = 50 : Fontsize = 1 : Lcd_fcolor = Rot : Lcd_bcolor = Weiss
Gosub Lcd_print
End If
' scratch byte
Btemp1 = Initfilesystem(1)
If Btemp1 > 0 Then
Lcd_string = "File System Error" : Lx1 = 4 : Ly1 = 51 : Fontsize = 1 : Lcd_fcolor = Rot : Lcd_bcolor = Weiss
Gosub Lcd_print
Lcd_string = Str(btemp1) : Lx1 = 5 : Ly1 = 52 : Fontsize = 1 : Lcd_fcolor = Rot : Lcd_bcolor = Weiss
Gosub Lcd_print
Else
'Else des Hauptprogramms
Lcd_string = "Card setup OK " : Lx1 = 5 : Ly1 = 51 : Fontsize = 1 : Lcd_fcolor = Gruen : Lcd_bcolor = Weiss
Gosub Lcd_print
Wait 3
Gosub Lcd_cls
'---------------------------Anfang des Auswahlmenüs---------------------------------------------
Anfang:
Lcd_string = "Run" : Lx1 = 2 : Ly1 = 56 : Fontsize = 1 : Lcd_fcolor = Schwarz : Lcd_bcolor = Weiss
Gosub Lcd_print
Lcd_string = "Stop" : Lx1 = 18 : Ly1 = 56 : Fontsize = 1 : Lcd_fcolor = Schwarz : Lcd_bcolor = Weiss
Gosub Lcd_print
Lcd_string = "RAC" : Lx1 = 5 : Ly1 = 49 : Fontsize = 1 : Lcd_fcolor = Hellgruen : Lcd_bcolor = Weiss
Gosub Lcd_print
Lcd_string = "CELLEROMETER" : Lx1 = 8 : Ly1 = 49 : Fontsize = 1 : Lcd_fcolor = Dunkelgruen : Lcd_bcolor = Weiss
Gosub Lcd_print
If Pind.5 = 0 Then
Lcd_string = "Running " : Lx1 = 3 : Ly1 = 52 : Fontsize = 2 : Lcd_fcolor = Blau : Lcd_bcolor = Weiss
Gosub Lcd_print
Open "DATA.txt" For Append As #10
'---------------------------Start / Stop Bedingung Aufnahme---------------------------------------------
Second = 0
Minute = 0
Hour = 0
While Pind.6 <> 0
Marker = 0
'------------------------Über 10 Werte mitteln------------------------------------
Vout1xw = 0
Vout1yw = 0
Vout1zw = 0
Vout2xw = 0
Vout2yw = 0
Vout2zw = 0
For J = 1 To 10
Vout1xw = Vout1xw + Getadc(0)
Vout1yw = Vout1yw + Getadc(1)
Vout1zw = Vout1zw + Getadc(2)
Vout2xw = Vout2xw + Getadc(3)
Vout2yw = Vout2yw + Getadc(4)
Vout2zw = Vout2zw + Getadc(5)
Next
Vout1xw = Vout1xw / 10
Vout1yw = Vout1yw / 10
Vout1zw = Vout1zw / 10
Vout2xw = Vout2xw / 10
Vout2yw = Vout2yw / 10
Vout2zw = Vout2zw / 10
'--------------Umrechnung in Spannung und Umwandlung in String------------------
Vout1x = Vout1xw / 1024
Vout1y = Vout1yw / 1024
Vout1z = Vout1zw / 1024
Vout1x = Vout1x * Referenzspannung
Vout1y = Vout1y * Referenzspannung
Vout1z = Vout1z * Referenzspannung
Vout1xstr = Fusing(vout1x , "#.####")
Vout1ystr = Fusing(vout1y , "#.####")
Vout1zstr = Fusing(vout1z , "#.####")
Vout2x = Vout2xw / 1024
Vout2y = Vout2yw / 1024
Vout2z = Vout2zw / 1024
Vout2x = Vout2x * Referenzspannung
Vout2y = Vout2y * Referenzspannung
Vout2z = Vout2z * Referenzspannung
Vout2xstr = Fusing(vout2x , "#.####")
Vout2ystr = Fusing(vout2y , "#.####")
Vout2zstr = Fusing(vout2z , "#.####")
'####----Marker----#####'
If Pind.4 = 0 Then
Marker = 1
End If
Markerstr = Fusing(marker , "#.#")
Secondstr = Fusing(second , "#.#")
Print #10 , Vout1xstr ; " " ; Vout1ystr ; " " ; Vout1zstr ; " " ; Vout2xstr ; " " ; Vout2ystr ; " " ; Vout2zstr ; " " ; Hour ; ":" ; Minute ; ":" ; Secondstr ; " " ; Markerstr ; " "
Waitms 1 'hier stelle ich ein wie lange das Programm noch warten muß damit
' das Schreiben genügend Zeit hat also waitms + Programmdurchlaufzeit der While Schleife
Wend
Close #10
Gosub Lcd_cls
Goto Anfang
Else
Lcd_string = "Stop" : Lx1 = 4 : Ly1 = 52 : Fontsize = 2 : Lcd_fcolor = Blau : Lcd_bcolor = Weiss
Gosub Lcd_print
Goto Anfang
End If
End If '
End
Timer_irq:
Timer1 = Timervorgabe
Incr Second
If Second = 60 Then
Incr Minute
Second = 0
End If
If Minute = 60 Then
Incr Hour
Minute = 0
End If
Return
'---------------------------------------------------------------------------------------------------------------------------------------------------
' Steuer- und Ausgaberoutinen für das Display
Lesezeichen