'**************************************************************** '* Name : 1mfk_LC_OSD.BAS * '* Author : Tomtom DL1MFK * '* Version : 1.0 * '* Notes : erster Versuch einen LC zu programmieren * '* : adaptiert auf ATMega8 von DJ7DA * '**************************************************************** '**************************************************************** ' Deklarationen * '**************************************************************** $regfile = "M8def.dat" $crystal = 4000000 Dim Bytes As Word Dim Byte1 As Byte Dim Byte2 As Byte Dim Value As Bit ' für Datenausgabe Dim I As Byte Dim Stelle0 As Word Dim Stelle1 As Word Dim Stelle2 As Word Dim Stelle3 As Word Dim Lin As Byte ' Zeilennummer Dim Col As Byte ' Spaltennummer Dim Pegel As Word Dim Pegel_l As Long ' um Single-Arithmetik zu vermeiden Dim Ergebnis As Word Dim L_balken As Byte ' Länge des Balkens Dim N As Byte ' Zählvariable Config Portd = &B0000_0111 ' Pin 0 - 2 output, Rest input Portd = &B0000_1100 ' alle LOW bis auf Lc_ce und pind.3 Config Portb = 1 ' Pin0 als output wg LED Lc_dat Alias Portd.0 ' Daten (LC pin 11) Lc_clk Alias Portd.1 ' Clock (LC pin 10) Lc_ce Alias Portd.2 ' Enable (LC pin 9) Config Adc = Single , Prescaler = Auto , Reference = Avcc ' ADC setup '**************************************************************** ' Konstanten * '**************************************************************** Const Faktor = 488 ' für ADC Const Command0 = &B1000_0000_0000_0000 '**************************************************************** ' Initialisierung * '**************************************************************** Start Adc Gosub Osd_init Gosub Rufz_anzeigen Cls lcd "Hallo W" '**************************************************************** ' Hauptschleife * '**************************************************************** Do If Pind.3 = 0 Then Gosub Disp_an Else Gosub Disp_aus End If 'Gosub Alle_zeichen 'Gosub Zaehlen 'Gosub Display_pegel_db 'Gosub Display_pegel Waitms 200 Toggle Portb.0 ' ...lebt er noch ? Loop ' End '**************************************************************** ' OSD Initialisierung * '**************************************************************** Osd_init: Waitms 100 Bytes = &B1100_0000_0000_0000 ' Com4 Display aus Gosub Leitung Bytes = &B1100_0100_0000_0000 ' Com4 Ram löschen !!! Gosub Leitung Bytes = &B1100_0001_0000_0000 ' Com4 Reset OSD-IC Gosub Leitung Bytes = &B1010_0000_0000_1010 ' Com2 V-Schriftgröße V-POS 2fsc Gosub Leitung Bytes = &B1011_0000_0010_1000 ' Com3 H-Schriftgröße H_Pos LC für Dot-Clock Gosub Leitung Bytes = &B1101_1011_0000_0111 ' Com5 Pal,625Zeilen,Zeilensprung(interlaced),HG-Farbe ' Gosub Leitung ' Normal-Mode, HG-Farbe Ein,Color-Burst out,magenta Bytes = &B1100_1101_0100_0111 ' WAS IST DAS ???? Gosub Leitung Bytes = &B1110_0000_0000_0000 ' Com6 DAV-Ausgang (Pin 19), 12 Zeilen, Normal-Mode Gosub Leitung ' kein ext sync Bytes = &B1111_0000_0110_0000 ' Com7 CVr-Einstellungen gesetzt Gosub Leitung Bytes = &B1111_0101_0000_0001 ' Com12 Nur Dot-Clock auf X-Oszillator gesetzt Gosub Leitung Bytes = &B1100_0000_0011_0001 ' Com4 Display angeschaltet mit Hg unter Zeichen 'Bytes = &B1100_0000_0000_0001 ' Com4 Display angeschaltet ohne Hg unter Zeichen Gosub Leitung Bytes = &B1111_0010_0000_1110 ' Com9 Zeile 1 andere Farbe Gosub Leitung Bytes = &B1111_0100_0000_1010 ' Com11 Zeile 1 andere Farbe Gosub Leitung Return '**************************************************************** ' Rufzeichen einblenden * '**************************************************************** Rufz_anzeigen: ' Rufzeichen anzeigen: 'Bytes = &B1000_1011_0001_0011 ' Lin = 1 : Col = 1 Gosub Position Gosub Leitung Byte1 = &B1001_0000 Byte2 = "D" Gosub Leitung2 Byte2 = "J" Gosub Leitung2 Byte2 = "7" Gosub Leitung2 Byte2 = "D" Gosub Leitung2 Byte2 = "A" Gosub Leitung2 Return '**************************************************************** ' Bis 100 zählen und Anzeigen * '**************************************************************** Zaehlen: For I = 0 To 100 'Bytes = &B1000_0001_0000_0001 ' Pos: Line 0, Col 0 Lin = 1 : Col = 1 Gosub Position ' Position aus Zeile und Spalte Gosub Leitung Byte1 = &B1001_0000 Stelle0 = I \ 100 Byte2 = 48 + Stelle0 'Print Chr(byte2); Gosub Leitung2 Stelle0 = I Mod 100 Stelle1 = Stelle0 \ 10 Byte2 = 48 + Stelle1 'Print Chr(byte2); Gosub Leitung2 Stelle2 = Stelle0 Mod 10 Byte2 = 48 + Stelle2 'Print Chr(byte2) Gosub Leitung2 Waitms 50 Next Return '**************************************************************** ' Pegel Anzeigen * '**************************************************************** Display_pegel: ' in Volt Pegel = Getadc(0) ' Portc.0 Pegel_l = Faktor * Pegel Pegel_l = Pegel_l / 100 Ergebnis = Pegel_l ' in mV 'Bytes = &B1000_0010_0001_0001 Lin = 2 : Col = 17 Gosub Position Gosub Leitung Byte1 = &B1001_0000 Stelle0 = Ergebnis / 1000 Byte2 = 48 + Stelle0 Gosub Leitung2 Byte2 = "," Gosub Leitung2 Stelle0 = Ergebnis Mod 1000 Stelle1 = Stelle0 / 100 Byte2 = 48 + Stelle1 Gosub Leitung2 Stelle0 = Ergebnis Mod 1000 Stelle1 = Stelle0 Mod 100 Stelle2 = Stelle1 / 10 Byte2 = 48 + Stelle2 Gosub Leitung2 Stelle0 = Ergebnis Mod 1000 Stelle1 = Stelle0 Mod 100 Stelle3 = Stelle1 Mod 10 Byte2 = 48 + Stelle3 Gosub Leitung2 Byte2 = "V" Gosub Leitung2 Waitms 200 Return '----------------------------------------------------------------------------------- Display_pegel_db: 'für AGC von 0-4 V (0-40 dB) Pegel = Getadc(0) Pegel_l = Faktor * Pegel Pegel_l = Pegel_l / 10000 Ergebnis = Pegel_l Lin = 12 : Col = 23 Gosub Position Gosub Leitung Byte1 = &B1001_0000 Stelle0 = Ergebnis \ 10 Byte2 = 48 + Stelle0 Gosub Leitung2 Stelle1 = Ergebnis Mod 10 Byte2 = 48 + Stelle1 Gosub Leitung2 L_balken = Ergebnis \ 2 ' Zahl der Balkensegmente If L_balken > 20 Then L_balken = 20 Lin = 12 : Col = 1 ' letzte Zeile von Anfang an Gosub Position Gosub Leitung Byte1 = &B1001_0000 For N = 1 To L_balken Byte2 = 28 Gosub Leitung2 Next N L_balken = L_balken + 1 For N = L_balken To 20 ' mit "." aufüllen Byte2 = "." Gosub Leitung2 Next N Waitms 100 Return '**************************************************************** '' AlleZeichen Schleife * '**************************************************************** Alle_zeichen: Bytes = &B1000_0000_0000_0000 ' Pos: Line 0, Col 0 Gosub Leitung Byte1 = &B1001_0000 For I = 0 To 255 Byte2 = I Gosub Leitung2 Next Return '**************************************************************** ' Daten auf die 3 Leitungen * '**************************************************************** Leitung: ' Byte1 und Byte2 aus Bytes Byte1 = High(bytes) Byte2 = Low(bytes) Lc_ce = 0 Waitus 3 Shiftout Lc_dat , Lc_clk , Byte1 , 2 ' Mode 2 (LSB out first, clock falling edge) Waitus 3 ' Shiftout Lc_dat , Lc_clk , Byte2 , 2 Waitus 3 Lc_ce = 1 Return Leitung2: ' Byte1 und Byte2 einzeln gesetzt Lc_ce = 0 Waitus 3 Shiftout Lc_dat , Lc_clk , Byte1 , 2 Waitus 3 Shiftout Lc_dat , Lc_clk , Byte2 , 2 Waitus 3 Lc_ce = 1 Return '***************************************************************** ' Position aus Zeile und Spalte * '***************************************************************** Position: Lin = Lin - 1 ' 1. Zeile = 0 Col = Col - 1 ' 1. Spalte = 0 Bytes = Makeint(col , Lin) Bytes = Bytes Or Command0 Return '**************************************************************** ' Display An/Ausschalten * '**************************************************************** Disp_an: Bytes = &B1100_0000_0011_0001 ' Com4 Display angeschaltet mit Hg unter Zeichen 'Bytes = &B1100_0000_0000_0001 ' Com4 Display an ohne Hg Gosub Leitung Return Disp_aus: Bytes = &B1100_0000_0011_0000 ' Com4 Display aus mit Hg 'Bytes = &B1100_0000_0000_0000 ' Com4 Display aus ohne Hg Gosub Leitung Return '***************************************************************** ' Alternativ: Ausgabe ohne "Shiftout" geht auch * '***************************************************************** 'Leitung: ' Rotate Bytes , Right , 8 ' Lc_ce = 0 ' Waitus 3 ' For N = 1 To 16 ' Lc_clk = 0 ' Value = Bytes And 1 ' Lc_dat = Value ' Waitus 3 ' Lc_clk = 1 ' Waitus 3 ' Shift Bytes , Right , 1 ' Waitus 3 ' Next N ' Waitus 3 ' Lc_ce = 1 'Return 'Leitung2: ' Bytes = Makeint(byte1 , Byte2) ' 'Rotate Bytes , Right , 8 ' Lc_ce = 0 ' Waitus 3 ' For N = 1 To 16 ' Lc_clk = 0 ' Value = Bytes And 1 ' Lc_dat = Value ' Waitus 3 ' Lc_clk = 1 ' Waitus 3 ' Shift Bytes , Right , 1 ' Waitus 3 ' Next N ' Waitus 3 ' Lc_ce = 1 'Return