'S55-Display-Ansteuerung ' ' - umgebaut auf anderes Board kein Hardware SPI mehr !!! ' $regfile = "M168def.dat" $crystal = 8000000 $baud = 256000 $hwstack = 100 $swstack = 100 $framesize = 100 '=== Config the hardware === Cs Alias Portc.5 'S65 Chip Select pin 1 Res Alias Portc.4 'S65 Reset pin 2 Rs Alias Portc.3 'S65 Data/command pin 3 Clk Alias Portc.2 'S65 Clock pin 4 Dat Alias Portc.1 'S65 Data pin 5 Config Rs = Output Config Dat = Output Config Cs = Output Config Clk = Output Config Res = Output 'config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 Config Spi = Soft , Din = Pinb.0 , Dout = Portc.1 , Ss = None , Clock = Portc.2 Dim Vg As Word Dim Hg As Word Dim Font As Byte Dim Dx As Byte Dim Dy As Byte Dim Lbl_ptr As Word Dim Seg_adr As Word Dim Lbyte_seg_adr As Byte At Seg_adr Overlay Dim Hbyte_seg_adr As Byte At Seg_adr + 1 Overlay '=== Define the constante === Const Blue = &H00F '8bit color RRRGGGBB Const Yellow = &HFF0 Const Red = &HF00 Const Green = &H0F0 Const Black = &H000 Const White = &HFFF Const Brightgreen = &H0D0 Const Darkgreen = &H0D0 Const Darkred = &HA0 Const Darkblue = &H00A Const Brightblue = &H00D Const Orange = &HDD0 Declare Sub S55_init() Declare Sub Setwindow(byval Xstart As Byte , Byval Ystart As Byte , Byval Xend As Byte , Byval Yend As Byte) Declare Sub S65_pset(byval Lx As Byte , Byval Ly As Byte , Byval Color As Word) Declare Sub S65_line(byval Lx1 As Byte , Byval Ly1 As Byte , Byval Lx2 As Byte , Byval Ly2 As Byte , Byval Color As Word) Declare Sub S55_cls(byval Backcolor As Word) Declare Sub Lcdtext(byval S As String , Byval Xoffset As Byte , Byval Yoffset As Byte , Byval Fontset As Byte , Byval Forecolor As Word , Byval Backcolor As Word ) Declare Sub S55_cmd(byval Cmd As Byte) Declare Sub Glcdout(byval S As String) '=== Main prog === Spiinit S55_init Dx = 1 Dy = 1 Font = 1 Hg = Blue Vg = White Do S55_cls White Lcdtext "1234567890123456789012" , 1 , 1 , 1 , Black , White S65_line 0 , 6 , 100 , 8 , Blue Lcdtext "Hallo Welt" , 10 , 9 , 1 , Red , Brightgreen Lcdtext "Alles Schoen !" , 10 , 17 , 1 , Darkgreen , Black Lcdtext "Feine Sach" , 10 , 42 , 3 , Black , Orange Lcdtext "123456789012345" , 10 , 52 , 2 , Black , Orange Lcdtext "Tach !" , 10 , 59 , 3 , Black , Red Lcdtext "Letzte Zeile" , 15 , 68 , 2 , Blue , Yellow Dim I As Byte Dim Ii As Byte Dim J As Byte Dim K As Byte Dim L As String * 2 Hg = Blue Vg = White Font = 1 For I = 0 To 12 'vorne Reihennummern anzeigen J = I + 1 K = I * 6 Dy = K + 1 Dx = 1 L = Str(j) Glcdout L Next Wait 20 Loop End '=== Subroutines === Sub S55_init() 'Init the Siemens S65 display Local Ib As Byte , Tempb As Byte Reset Res 'LCD Reset Waitms 10 Set Res 'HW Reset Waitms 1 Set Rs Reset Cs ' Initialisierungsbytes ausgeben Restore Init1 For Ib = 1 To 142 Read Tempb S55_cmd Tempb Next End Sub Sub S55_cmd(cmd As Byte) 'Send 8bits to the display 'Shiftout Dat , Clk , Cmd , 1 Spiout Cmd , 1 End Sub Sub Setwindow(byval Xstart As Byte , Byval Ystart As Byte , Byval Xend As Byte , Byval Yend As Byte) Local Tempb As Byte Shift Xstart , Left , 1 ' <<= 1; Xstart = Xstart + 6 Shift Xend , Left , 1 ' <<= 1; Xend = Xend + 7 Set Rs 'PORTC |= (1 << P_LCD_CD); Reset Cs 'PORTC &= ~(1 << P_LCD_CS); S55_cmd &HF0 Tempb = Xstart And &H0F Tempb = Tempb Or &H00 S55_cmd Tempb '&H00 Or(xstart And &H0F) Shift Xstart , Right , 4 Tempb = &H10 Or Xstart S55_cmd Tempb '&H10 Or(xstart >> 4)) Tempb = Ystart And &H0F Tempb = Tempb Or &H20 S55_cmd Tempb '&H20 Or(ystart And &H0F)) Shift Ystart , Right , 4 Tempb = &H30 Or Ystart S55_cmd Tempb '&H30 Or(ystart >> 4)) S55_cmd &HF5 Tempb = Xend And &H0F Tempb = Tempb Or &H00 S55_cmd Tempb '&H00 Or(xend And &H0F)) Shift Xend , Right , 4 Tempb = &H10 Or Xend S55_cmd Tempb '&H10 Or(xend >> 4)); Tempb = Yend And &H0F Tempb = Tempb Or &H20 S55_cmd Tempb '&H20 Or(yend And &H0F)) Shift Yend , Right , 4 Tempb = &H30 Or Yend S55_cmd Tempb '&H30 Or(yend >> 4)); Set Cs 'PORTC |= (1 << P_LCD_CS); Reset Rs 'PORTC &= ~(1 << P_LCD_CD); End Sub Sub S55_cls(byval Backcolor As Word) 'Clear the lcd Local I As Word Local Hib As Byte Local Lob As Byte Lob = Backcolor Shift Backcolor , Right , 8 Hib = Backcolor Setwindow 0 , 0 , 100 , 79 Reset Cs 'PORTC &= ~((1 << P_LCD_CS) | (1 << P_LCD_CD)); Reset Rs For I = 0 To 8079 S55_cmd Hib 'spi(0xFF); spi(0xFF); S55_cmd Lob 'spi(0xFF); spi(0xFF); Next Set Cs 'PORTC |= (1 << P_LCD_CS); End Sub Sub S65_pset(lx As Byte , Ly As Byte , Color As Word) 'Set a pixel Local Hib As Byte Local Lob As Byte Lob = Color Shift Color , Right , 8 Hib = Color S55_cmd Hib 'fgColor >> 8); S55_cmd Lob 'fgColor & 0xFF); End Sub Sub S65_line(byval Lx1 As Byte , Byval Ly1 As Byte , Byval Lx2 As Byte , Byval Ly2 As Byte , Byval Color As Word) 'Draw a line on the lcd Local M As Byte , M1 As Single , M2 As Single Local Yg As Byte , Cv As Single , Bn As Integer Local R As Byte , B As Byte Setwindow Lx1 , Ly1 , Lx2 , Ly2 M1 = Ly2 - Ly1 M2 = Lx2 - Lx1 Cv = M1 / M2 Bn = Int(cv) M = Low(bn) B = M * Lx1 B = -1 * B B = B + Ly1 Reset Cs 'füs pset Reset Rs For R = Lx1 To Lx2 Yg = M * R Yg = Yg + B S65_pset R , Yg , Color Next R Set Cs 'PORTC |= (1 << P_LCD_CS); End Sub Sub Lcdtext(byval S As String , Xoffset As Byte , Yoffset As Byte , Fontset As Byte , Forecolor As Word , Backcolor As Word ) 'Print text on the display Local Tempstring As String * 1 , Temp As Byte 'Dim local the variables Local A As Byte , Pixels As Byte , Carcount As Byte ', Count As Byte , Lus As Byte Local Row As Byte , Row1 As Byte , Byteseach As Byte , Blocksize As Byte , Dummy As Byte Local Colums As Byte , Columcount As Byte , Rowcount As Byte , Stringsize As Byte Local Xpos As Byte , Ypos As Byte , Pixel As Word , Pixelcount As Byte , Bs As Byte If Fontset = 2 Then Lbl_ptr = Loadlabel(font6x8) ' Add or remove here fontset's that you need or not, If Fontset = 3 Then Lbl_ptr = Loadlabel(font8x8) ' this is the name that you gave to the font, NOT the filename If Fontset = 1 Then Lbl_ptr = Loadlabel(font5x5) Seg_adr = Lbl_ptr !LDS R8, {Lbyte_seg_adr} ' In Bascom Read-Pointer Low Byte schreiben !LDS R9, {Hbyte_seg_adr} ' In Bascom Read-Pointer High Byte schreiben Read Row1 : Read Byteseach : Read Blocksize ' Read the first 3 bytes from the font file Print S Stringsize = Len(s) - 1 ' Size of the text string -1 because we must start with 0 For Carcount = 0 To Stringsize ' Loop for the numbers of caracters that must be displayed Temp = Carcount + 1 ' Cut the text string in seperate caracters Tempstring = Mid(s , Temp , 1) Seg_adr = Asc(tempstring) - 32 ' Font files start with caracter 32 Seg_adr = Seg_adr * Blocksize Seg_adr = 5 + Seg_adr Seg_adr = Lbl_ptr + Seg_adr !LDS R8, {Lbyte_seg_adr} ' In Bascom Read-Pointer Low Byte schreiben !LDS R9, {Hbyte_seg_adr} ' In Bascom Read-Pointer High Byte schreiben Colums = Blocksize / Row1 ' Calculate the numbers of colums Row = Row1 * Byteseach ' Row is max 8 pixels high = 1 byte Row = Row - 1 ' Want to start with row=0 instead of 1 Colums = Colums - 1 ' Same for the colums For Rowcount = 0 To Row Step Byteseach ' Loop for numbers of rows A = Rowcount + Yoffset For Columcount = 0 To Colums ' Loop for numbers of Colums Print "Colum: " ; Columcount Read Pixels Xpos = Columcount ' Do some calculation to get the caracter on the correct Xposition Temp = Carcount * Blocksize Xpos = Xpos + Temp Xpos = Xpos + Xoffset Bs = Byteseach - 1 Ii = A + Bs Setwindow Xpos , A , Xpos , Ii Reset Cs ' für Pset Reset Rs For Pixelcount = 0 To Bs ' Loop for 8 pixels to be set or not Print "Row: " ; Pixelcount Ypos = A + Pixelcount ' Each pixel on his own spot Pixel = Pixels.0 ' Set the pixel (or not) If Pixel = 1 Then Pixel = Forecolor Else Pixel = Backcolor End If S65_pset Xpos , Ypos , Pixel ' Finaly we can set the pixel Shift Pixels , Right ' Shift the byte 1 bit to the right so the next pixel comes availible Next Pixelcount Set Cs ' für Pset Next Columcount Next Rowcount Next Carcount End Sub 'End of this amazing subroutine Sub Glcdout(byval S As String) Lcdtext S , Dx , Dy , Font , Hg , Vg End Sub '=== Includes === ' $include "Font5x5.font" $include "Font6x8.font" $include "Font8x8.font" Init1: Data &HF4 , &H90 , &HB3 , &HA0 , &HD0 , Data &HF0 , &HE2 , &HD4 , &H70 , &H66 , &HB2 , &HBA , &HA1 , &HA3 , &HAB , &H94 , &H95 , &H95 , &H95 , Data &HF5 , &H90 , Data &HF1 , &H00 , &H10 , &H22 , &H30 , &H45 , &H50 , &H68 , &H70 , &H8A , &H90 , &HAC , &HB0 , &HCE , &HD0 , Data &HF2 , &H0F , &H10 , &H20 , &H30 , &H43 , &H50 , &H66 , &H70 , &H89 , &H90 , &HAB , &HB0 , &HCD , &HD0 , Data &HF3 , &H0E , &H10 , &H2F , &H30 , &H40 , &H50 , &H64 , &H70 , &H87 , &H90 , &HAA , &HB0 , &HCB , &HD0 , Data &HF4 , &H0D , &H10 , &H2E , &H30 , &H4F , &H50 , Data &HF5 , &H91 , Data &HF1 , &H01 , &H11 , &H22 , &H31 , &H43 , &H51 , &H64 , &H71 , &H86 , &H91 , &HA8 , &HB1 , &HCB , &HD1 , Data &HF2 , &H0F , &H11 , &H21 , &H31 , &H42 , &H51 , &H63 , &H71 , &H85 , &H91 , &HA6 , &HB1 , &HC8 , &HD1 , Data &HF3 , &H0B , &H11 , &H2F , &H31 , &H41 , &H51 , &H62 , &H71 , &H83 , &H91 , &HA4 , &HB1 , &HC6 , &HD1 , Data &HF4 , &H08 , &H11 , &H2B , &H31 , &H4F , &H51 , Data &H80 , &H94 , Data &HF5 , &HA2 , Data &HF4 , &H60 , Data &HF0 , &H40 , &H50 , &HC0 , Data &HF4 , &H70 , &HF0 , &HE0 , &H81