'**************************************************************** ' TX Steuerung mit PLL, Tonträger und OSD und Encoder * ' * ' -- Version 0.1f 28.10.2010 * ' - Erster Versuch mit MAX7456 * ' - schreibt nicht bei hd-test und db0qi und schaltet nicht bei* ' QI(8) und HOB !!! * '**************************************************************** '**************************************************************** ' Prozessor relevante Einstellungen * '**************************************************************** $regfile = "M168def.dat" $crystal = 8000000 $baud = 19200 $hwstack = 50 $swstack = 120 $framesize = 120 '**************************************************************** ' SPI-Leitungen * '**************************************************************** 'Config Spi = Soft Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 0 Config Spi = Soft , Din = Pind.7 , Dout = Portb.1 , Ss = Portb.2 , Clock = Portb.0 '**************************************************************** ' LCD-Leitungen * '**************************************************************** Config Lcdpin = Pin , Rs = Portb.4 , E = Portb.5 , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 Config Lcdbus = 4 Config Lcd = 40 * 2 Spiinit '=== Dimension === Dim Temp As Byte , Lus As Byte Dim Regaddr As Byte Dim Regdata As Byte Dim Buffer(2) As Byte Dim Mrk1 As Bit Dim C As Byte Dim I As Byte Dim A As Byte Dim S As Byte Dim N As Word Dim Z As Byte Dim Leng As Byte Dim Wert As String * 5 Dim Tmp As String * 35 Dim Feu As String * 35 Dim Wnd As String * 35 Dim Zeile As Byte Dim Z_speicher(16) As String * 30 ' (zeilen Speicher) Dim Z_lin(16) As Byte Dim Z_an(16) As Byte Dim Xt As String * 3 Dim Upc As Word Dim Upcs As String * 5 Declare Sub Initmax7456() Declare Sub Videotext(byval Text As String , Byval Ypos As Byte , Byval Xpos As Byte) Declare Sub Writereg(byval Regaddr As Byte , Byval Regdata As Byte) Declare Sub Readreg(byval Regaddr As Byte , Byval Regdata As Byte) Declare Sub Rowbrightness(byval Row As Byte , Byval Brightness As Byte) Declare Sub Writecustomcharacter(byval Characters As Byte) Declare Sub Wait_for_string(byval S As String) Declare Function Read_string() As String '=== Const === Const Vm0 = &H00 'Video mode 1 Const Vm1 = &H01 'Video mode 2 Const Hos = &H02 'Horizontal Offset Const Vos = &H03 'Vertical Offset Const Dmm = &H04 'Display Memory Mode Const Dmah = &H05 'Display Memory Address High Const Dmal = &H06 'Display Memory Address Low Const Dmdi = &H07 'Display Memory Data In Const Cmm = &H08 'Character Memory Mode Const Cmah = &H09 'Character Memory Address High Const Cmal = &H0A 'Character Memory Address Low Const Cmdi = &H0B 'Character Memory Data In Const Osdm = &H0C 'Osd Insertion Mux Const Osdbl = &H6C 'OSD Black Level Const Readreg = &H80 'Read register = register + &H80 Const Status_read = &HA0 'Status register Const True = 1 Const False = 0 '**************************************************************** ' Konstanten für EEprom Adressen * '**************************************************************** Const Offset = 0 ' Zeilen offset im EEprom Const Zsatz = 33 ' Datensatz + 1 '**************************************************************** ' Initialiseirung * '**************************************************************** 'Init: 'Config Serialin = Buffered , Size = 100 'Konfig. der ser. Eingabe Upc = 1 Initmax7456 'Init the Max7456 Waitms 100 'Writecustomcharacter 2 'Write the customcharacters to the MAX7456 NVM, this has only need to be done one's. This line and data can be removed after that. For I = 0 To 15 ' 8 Zeilen aus dem EEprom laden N = I * Zsatz N = N + Offset Z = I + 1 Readeeprom Z_speicher(z) , N N = N + 31 'Datensatz-1 Readeeprom Z_lin(z) , N N = N + 1 Readeeprom Z_an(z) , N Next Cls 'screen erase Dim Nn As Byte Nn = 1 Do Videotext " " , 1 , Nn Nn = Nn + 1 Loop Until Nn = 193 Nn = 1 Do Videotext " " , 8 , Nn Nn = Nn + 1 Loop Until Nn = 250 'There are some controle characters implanted to controle (part of) the string. 'Ascii 133=start blinking text, 134= stop blinking text 'Ascii 131=enable the background, 132= disable the background 'Ascii 135=invert text, 136= non-inverted text 'In Bascom it's easy to use this with {133} option, like: Videotext "1234567890123456789012345678901234567890" , 0 , 0 Videotext "{133}Flashing text{134}" , 9 , 0 Videotext "{131}{135} Tomtom DL1MFK{136} (C)2011 {132}" , 15 , 3 Videotext "Warte auf Wetter-DATA " , 14 , 3 '**************************************************************** ' Initialiseirung * '**************************************************************** 'Main: Do For I = 1 To 16 Xt = Str(i) Xt = Xt + " " Videotext Xt , 15 , 0 Videotext "{135}" , Z_lin(i) , 0 Videotext Z_speicher(i) , Z_lin(i) , 0 Print Xt Print Z_speicher(i) Print Z_lin(i) Locate 1 , 1 Lcd "Videozeile :" Locate 2 , 1 Lcd Z_speicher(i) 'Waitms 500 Next 'For I = 0 To 15 ' Rowbrightness 14 , I '&B00001111 'Change the row brightness, see the SUB for the usage discription ' Wait 1 'Next Loop '**************************************************************** '=== Subroutines=== '**************************************************************** Sub Initmax7456() Writereg Vm0 , &B01001100 Writereg Vm1 , &B01111111 Writereg Dmm , &B01000000 Writereg Hos , &B00011111 Writereg Vos , &B00010000 '01001000 ; 0 , 1=PAL, 00=Auto Sync, 1=Enable OSD, 0=Enable OSD always, 0=SW Reset, 0=Enable Video Buffer '00010100 ; 0 = NA, 001=Background MODE Brightness 7%, 11=Blinking Time 160ms, 00=Blinking Duty Cycle BT:BT '01000000 ; 0=NA, 1=8bit operation, '00011111 ; 00=NA, 00000000 = Farthest left (-32 pixels),00100000 = No horizontal offset, 00111111 = Farthest right (+31 pixels) '00010000 ; 000=NA, 00000000 = Farthest up (+16 pixels), 00010000 = No vertical offset, 00011111 = Farthest down (-15 pixels) End Sub '------------------------------------------------------------------------------- Sub Videotext(byval Text As String , Byval Ypos As Byte , Byval Xpos As Byte) Local Charcount As Byte , Tempstring As String * 1 , Tempbyte As Byte , Position As Word , Chars As Byte , Controlcharcount As Byte , Attribute As Byte Controlcharcount = 0 : Attribute = 0 'Set the local variable to zero Charcount = Len(text) - 1 'Count the number of characters in the string minus, because we must start at 0 For Chars = 0 To Charcount 'do the loop as much as there are characters Position = Ypos * 30 'Position where the characters must be showed 30=characters per line Position = Position + Xpos 'Position + the xpos Position = Position + Chars 'Position + the charactercount that's handled this loop Position = Position - Controlcharcount 'There was a controle charater, deduct from the charactercount because it must not be handled as real character Regdata = High(position) 'Put the highbyte of position in the regdatabuffer Writereg Dmah , Regdata 'Write the data to the register Regdata = Low(position) 'Put the lowbyte of position in the regdatabuffer Writereg Dmal , Regdata 'Write the data to the register Tempbyte = Chars + 1 'Need the character position from the textstring Tempstring = Mid(text , Tempbyte , 1) 'Take out 1 character that we need to handle now Tempbyte = Asc(tempstring) 'Get the ascii value of this character If Tempbyte < 130 Then 'Character larger then 130 are controle characters Tempbyte = Tempbyte - 32 'Max7456 character table starts at &H00, so deduct 32 to get it even with the ascii table Regdata = Lookup(tempbyte , Characterslookup) 'Lookup the character from the datatable Writereg Dmdi , Regdata 'Write the data to the DisplayMemory register Else Incr Controlcharcount 'It's a controle character, increase the counter If Tempbyte = 131 Then Set Attribute.7 'Set the local background bit in the character attribute If Tempbyte = 132 Then Reset Attribute.7 'Reset the local background bit If Tempbyte = 133 Then Set Attribute.6 'Set the blink bit If Tempbyte = 134 Then Reset Attribute.6 'Reset the blink bit If Tempbyte = 135 Then Set Attribute.5 'Set the inverse bit If Tempbyte = 136 Then Reset Attribute.5 'Reset the inverse bit End If Regdata = High(position) 'Put the highbyte of position in the regdatabuffer Regdata = Regdata Or &B00000010 'Set bit1 for the character attribute Writereg Dmah , Regdata 'Write the data to the register Regdata = Low(position) 'Put the lowbyte of position in the regdatabuffer Writereg Dmal , Regdata 'Write the data to the register Writereg Dmdi , Attribute 'Write the attribute to the DisplayMemory register Next Carcount End Sub 'There are some controle characters implanted to controle (part of) the string. 'Ascii 133=start blinking text, 134= stop blinking text 'Ascii 131=enable the background, 132= disable the background 'Ascii 135=invert text, 136= non-inverted text 'In Bascom it's easy to use this with {133} option, like: 'Videotext "{133}Flashing text{134}" , 9 , 0 '------------------------------------------------------------------------------- Sub Rowbrightness(byval Row As Byte , Byval Brightness As Byte) If Brightness > &B00001111 Then Brightness = &B00001111 'B0000xx11 Character Black Level in % of OSD white level 00 = 0% 01 = 10% 10 = 20% 11 = 30% Regaddr = &H10 + Row 'B000011xx Character White Level in % of OSD white level 00 = 120% 01 = 100% 10 = 90% 11 = 80% Regdata = Brightness Writereg Regaddr , Regdata End Sub '------------------------------------------------------------------------------- Sub Writereg(byval Regaddr As Byte , Byval Regdata As Byte) Buffer(1) = Regaddr 'Put both bytes in the array Buffer(2) = Regdata Spiout Buffer(1) , 2 'Shift the array out the SPI End Sub Sub Readreg(byval Regaddr As Byte , Byval Regdata As Byte) Buffer(1) = Regaddr 'Put both bytes in the array Spiin Buffer(1) , 2 'Shift the array out the SPI Regdata = Buffer(2) End Sub Characterslookup: 'Convert the ascii table to the Max7456 table. (Not excist) are characters that are not in the MAX7456 table and will show a ? (&H42) Data &H00 '32 Space Data &H42 '33 ! (not excist) Data &H48 '34 "" Data &H42 '35 # (not excist) Data &H42 '36 $ (not excist) Data &H51 '37 % (Custom Percent) Data &H42 '38 & (not excist) Data &H47 '39 ' Data &H3F '40 ( Data &H40 '41 ) Data &H42 '42 * (not excist) Data &H50 '43 + (Custom Grad) Data &H45 '44 , Data &H49 '45 - Data &H41 '46 . Data &H47 '47 / Data &H0A '48 0 Data &H01 '49 1 Data &H02 '50 2 Data &H03 '51 3 Data &H04 '52 4 Data &H05 '53 5 Data &H06 '54 6 Data &H07 '55 7 Data &H08 '56 8 Data &H09 '57 9 Data &H44 '58 : Data &H43 '59 ; Data &H4A '60 < Data &H42 '61 = (not excist) Data &H4B '62 > Data &H42 '63 ? Data &H4C '64 @ Data &H0B '65 A Data &H0C '66 B Data &H0D '67 C Data &H0E '68 D Data &H0F '69 E Data &H10 '70 F Data &H11 '71 G Data &H12 '72 H Data &H13 '73 I Data &H14 '74 J Data &H15 '75 K Data &H16 '76 L Data &H17 '77 M Data &H18 '78 N Data &H19 '79 O Data &H1A '80 P Data &H1B '81 Q Data &H1C '82 R Data &H1D '83 S Data &H1E '84 T Data &H1F '85 U Data &H20 '86 V Data &H21 '87 W Data &H22 '88 X Data &H23 '89 Y Data &H24 '90 Z Data &H42 '91 [ (not excist) Data &H42 '92 \ (not excist) Data &H42 '93 ] (not excist) Data &H42 '94 ^ (not excist) Data &H42 '95 Underscore (not excist) Data &H42 '96 ` (not excist) Data &H25 '97 a Data &H26 '98 b Data &H27 '99 c Data &H28 '100 d Data &H29 '101 e Data &H2A '102 f Data &H2B '103 g Data &H2C '104 h Data &H2D '105 i Data &H2E '106 j Data &H2F '107 k Data &H30 '108 l Data &H31 '109 m Data &H32 '110 n Data &H33 '111 o Data &H34 '112 p Data &H35 '113 q Data &H36 '114 r Data &H37 '115 s Data &H38 '116 t Data &H39 '117 u Data &H3A '118 v Data &H3B '119 w Data &H3C '120 x Data &H3D '121 y Data &H3E '122 z Data &H42 '123 { (not excist) Data &H42 '124 | (not excist) Data &H42 '125 } (not excist) Data &H42 '126 ~ (not excist) '------------------------------------------------------------------------------- Customcharacter: 'Total of 2 characters in this datatable Data &H50 'Character 80 ( Grad ) Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H54 , &H01 Data &H55 , &H50 , &HA0 , &H55 , &H52 , &H58 , &H55 , &H52 Data &H58 , &H55 , &H50 , &HA0 , &H55 , &H54 , &H01 , &H55 Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 Data &H51 'Character 81 ( Percent ) Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 , &H55 Data &H55 , &H55 , &H55 , &H55 , &H41 , &H55 , &H41 , &H28 Data &H55 , &H28 , &H28 , &H54 , &HA8 , &H41 , &H52 , &HA1 Data &H55 , &H4A , &H85 , &H55 , &H2A , &H15 , &H54 , &HA8 Data &H55 , &H52 , &HA1 , &H55 , &H4A , &H85 , &H41 , &H2A Data &H15 , &H28 , &H28 , &H55 , &H28 , &H41 , &H55 , &H41 Data &H55 , &H55 , &H55 , &H55 , &H55 , &H55 '------------------------------------------------------------------------------- '**************************************************************** ' EEPromwerte beim Brennen speichern * '**************************************************************** $eeprom 'Data 11548% , 33500% , 255 , 1 , 0 , 0 , 0 , 0 ' 10 Bytes 'Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ' 10 Bytes 'Data 0 , 0 , 0 , 0 , 0 , 0 ' 6 Bytes ' 123456789012345678901234567890 Data " 1. ZEILE 1" , 0 , 1 ' 32 Bytes für eine Zeile Data " 2. ZEILE 2" , 1 , 1 ' 32 Bytes für eine Zeile Data " 3. ZEILE 3" , 2 , 1 ' 32 Bytes für eine Zeile Data " 4. ZEILE 4" , 3 , 1 ' 32 Bytes für eine Zeile Data " 5. ZEILE 5" , 4 , 1 ' 32 Bytes für eine Zeile Data " 6. ZEILE 6" , 5 , 1 ' 32 Bytes für eine Zeile Data " 7. ZEILE 7" , 6 , 1 ' 32 Bytes für eine Zeile Data " 8. ZEILE 8" , 7 , 1 ' 32 Bytes für eine Zeile Data " 9. ZEILE 9" , 8 , 1 ' 32 Bytes für eine Zeile Data "10. ZEILE 10" , 9 , 1 ' 32 Bytes für eine Zeile Data "11. ZEILE 11" , 10 , 1 ' 32 Bytes für eine Zeile Data "12. ZEILE 12" , 11 , 1 ' 32 Bytes für eine Zeile Data "13. ZEILE 13" , 12 , 1 ' 32 Bytes für eine Zeile Data "14. ZEILE 14" , 13 , 1 ' 32 Bytes für eine Zeile Data "15. ZEILE 15" , 14 , 1 ' 32 Bytes für eine Zeile Data "16. ZEILE 16" , 15 , 1 ' 32 Bytes für eine Zeile $data