'--------------------------------------------------------------------
' GRAPHIC FONT
' Use the Bascom font file's for all the graphic display's,
' include inverted and/or rotated text.
' By Evert Dekker 2007 GraphicFont@Evertdekker dotje com
' Created with Bascom-Avr: 1.11.8.8
' Optimized by Mladen Bruck 2009, mladen.bruck@avrbit dotje com
'--------------------------------------------------------------------
$regfile = "m16def.dat" ' specify the used micro
$crystal = 16000000 ' used crystal frequency
'$baud = 19200 ' use baud rate
$hwstack = 100 ' default use 32 for the hardware stack
$swstack = 120 ' default use 10 for the SW stack
$framesize = 100 ' default use 40 for the frame space
'=== T6963 graphics module PIN's setup. Change this according to your hardware !
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 4 , Cd = 7 , Wr = 5 , Rd = 6 , Reset = 3 , Fs = 2 , Mode = 8
'The dataport is the portname that is connected to the data lines of the LCD
'The controlport is the portname which pins are used to control the lcd
'CE, CD etc. are the pin number of the CONTROLPORT.
' For example CE =2 because it is connected to PORTC.2
'mode 8 gives 240 / 8 = 30 columns , mode=6 gives 240 / 6 = 40 columns
Cursor Off
Cls
'=== Subprocedure declarations
'SYNTAX Lcdtest String , Xoffset , Yoffset , Inverse , Rotation
Declare Sub Lcdtext(byval S As String , Byval Xoffset As Byte , Byval Yoffset As Byte , Byval Inverse As Byte , Byval Rotation As Byte)
'* Xoffset and Yoffset is in pixels, so you can place text on every spot on the display
'SYNTAX Set_font FontSet
Declare Sub Set_font(byval Fontset As Byte)
'* You determine yourself in the subroutine witch font belongs to the fontset
'=== Alias declarations
Font8x8_font Alias 1
Coop8x8_font Alias 2
Font6x8_font Alias 3
Font6x16_font Alias 4
Font21x16_font Alias 5
Font12x14_font Alias 6
Font10x15_font Alias 7
Font6_8_font Alias 8
Font11x16_font Alias 9
Font14x16_font Alias 10
Font15x16_font Alias 11
Font12x16_font Alias 12
Font19x16_font Alias 13
Font13x8_font Alias 14
Inverted Alias 1
No_inverted Alias 0
Rotate_0 Alias 0
Rotate_90 Alias 1
Rotate_180 Alias 2
Rotate_270 Alias 3
'=== Variables declarations
Dim Row As Byte , Colums As Byte , Byteseach As Byte , Blocksize As Byte
Dim Font_adress As Word
'-----
'=== Your main prog here ====
Set_font Font8x8_font
Lcdtext "#,# $(*)'&) %&+" , 0 , 0 , No_inverted , Rotate_0
Set_font Coop8x8_font
Lcdtext "#)# $&&'%(" , 128 , 1 , No_inverted , Rotate_0
Set_font Font6x8_font
Lcdtext "#+$%)(*)'&*" , 2 , 10 , No_inverted , Rotate_0
Set_font Font6x16_font
Lcdtext "$,#$ %*)+(- '&" , 72 , 10 , No_inverted , Rotate_0
Set_font Font21x16_font
Lcdtext "#$'&%!" , 0 , 91 , No_inverted , Rotate_0
Set_font Font12x14_font
Lcdtext "$#'%#'&" , 2 , 25 , No_inverted , Rotate_0
Set_font Font10x15_font
Lcdtext "$&('#(%" , 160 , 12 , No_inverted , Rotate_0
Set_font Font6_8_font
Lcdtext "#$%&'()*+, -/01.! )2+" , 100 , 30 , No_inverted , Rotate_0
Set_font Font11x16_font
Lcdtext "&/.1 '*-+0 ,/0 $#)%('" , 3 , 42 , No_inverted , Rotate_0
Set_font Font14x16_font
Lcdtext "$#%&'(" , 5 , 55 , No_inverted , Rotate_0
Set_font Font15x16_font
Lcdtext "#-+,)( %'$*$%,&*" , 0 , 110 , No_inverted , Rotate_0
Set_font Font12x16_font
Lcdtext ",&*+')( $#%!" , 98 , 55 , No_inverted , Rotate_0
Set_font Font19x16_font
Lcdtext "#$%&'()*+,!" , 15 , 73 , No_inverted , Rotate_0
Set_font Font13x8_font
Lcdtext "%&)$'($#" , 125 , 95 , No_inverted , Rotate_0
End
'=== Sub Routines ===
Sub Set_font(byval Fontset As Byte)
Local Dummy_word As Word
'Add or remove here fontset's that you need or not,
'This is the name that you gave to the font, NOT the filename
'If you dont know the name, open the font file in wordpad, and there it is,
'right on top.
Select Case Fontset ' You may use case 1, case 2 etc insted of alias names
Case Font8x8_font : Font_adress = Loadlabel(font8x8) 'This is the name that you gave to the font, NOT the filename
Case Coop8x8_font : Font_adress = Loadlabel(coop8x8)
Case Font6x8_font : Font_adress = Loadlabel(font6x8)
Case Font6x16_font : Font_adress = Loadlabel(font6x16)
Case Font21x16_font : Font_adress = Loadlabel(font21x16)
Case Font12x14_font : Font_adress = Loadlabel(font12x16)
Case Font10x15_font : Font_adress = Loadlabel(font10x16)
Case Font6_8_font : Font_adress = Loadlabel(forte6x8)
Case Font11x16_font : Font_adress = Loadlabel(font11x16)
Case Font14x16_font : Font_adress = Loadlabel(comic14x16)
Case Font15x16_font : Font_adress = Loadlabel(font15x16)
Case Font12x16_font : Font_adress = Loadlabel(temp12x16)
Case Font19x16_font : Font_adress = Loadlabel(font19x16)
Case Font13x8_font : Font_adress = Loadlabel(font13x8)
End Select
' --- Load font info needed for Lcdtext subroutine calculations ---
Dummy_word = Font_adress : Row = Cpeek(dummy_word)
Incr Dummy_word : Byteseach = Cpeek(dummy_word)
Incr Dummy_word : Blocksize = Cpeek(dummy_word)
' -----
Colums = Blocksize / Row 'Calculate the numbers of colums
Row = Row * 8 'Row is always 8 pixels high = 1 byte, so working with row in steps of 8.
Row = Row - 1 'Want to start with row=0 instead of 1
Colums = Colums - 1 'Same for the colums
Font_adress = Font_adress + 4 'Skip first 4 bytes in fontfile
End Sub
Sub Lcdtext(byval S As String , Xoffset As Byte , Yoffset As Byte , Inverse As Byte , Rotation As Byte)
Local Tempstring As String * 1 , Temp As Byte 'Dim local the variables
Local A As Byte , Pixels As Byte , Pixels_adress As Word , Carcount As Byte
Local Columcount As Byte , Rowcount As Byte , Stringsize As Byte
Local Xpos As Byte , Ypos As Byte , Pixel As Byte , Pixelcount As Byte
Local Dummy_word As Word
If Inverse > 1 Then Inverse = 0 'Inverse can't be greater then 1
If Rotation > 3 Then Rotation = 0 'There are only 4 rotation'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)
Temp = Asc(tempstring) - 32 'Font files start with caracter 32
Dummy_word = Blocksize * Temp
Pixels_adress = Font_adress + Dummy_word 'Do dummie read to point to the correct line in the fontfile
Temp = Carcount * Byteseach 'Do first part of calculation to get the character on the correct X or Y position
Select Case Rotation
Case 0 '0 degrees rotation
Temp = Temp + Xoffset
For Rowcount = 0 To Row Step 8 'Loop for numbers of Row
A = Rowcount + Yoffset
For Columcount = 0 To Colums 'Loop for numbers of Colums
Pixels = Cpeek(pixels_adress)
Incr Pixels_adress
If Inverse = 1 Then Toggle Pixels 'Read the byte from the file and if inverse = true then invert de byte
Xpos = Columcount
Xpos = Xpos + Temp 'Do rest of calculation to get the character on the correct X position
For Pixelcount = 0 To 7 'Loop for 8 pixels to be set or not
Ypos = A + Pixelcount 'Each pixel on his own spot
Pixel = Pixels.pixelcount 'Set the pixel (or not)
Pset Xpos , Ypos , Pixel 'Finaly we can set the pixel
Next Pixel
Next Columcount
Next Rowcount
Case 1 '90 degrees rotation
For Rowcount = Row To 0 Step -8 'Loop is now counting down
A = Rowcount + Xoffset
A = A - 15 'Correction to set Xpos on Xoffset with rotation
For Columcount = 0 To Colums
Pixels = Cpeek(pixels_adress)
Incr Pixels_adress
If Inverse = 1 Then Toggle Pixels
Xpos = Columcount
Xpos = Xpos + Yoffset
Xpos = Xpos + Temp 'We want that Xoffset is still Xoffset, so we need here the change from x to y
For Pixelcount = 7 To 0 Step -1
Ypos = A + Pixelcount
Pixel = Pixels.0
Pset Ypos , Xpos , Pixel
Shift Pixels , Right
Next Pixel
Next Columcount
Next Rowcount
Case 2 '180 degrees rotation
For Rowcount = Row To 0 Step -8
A = Rowcount + Yoffset
A = A - 7 'Correction to set Xpos on Xoffset with rotation
For Columcount = Colums To 0 Step -1
Pixels = Cpeek(pixels_adress)
Incr Pixels_adress
If Inverse = 1 Then Toggle Pixels
Xpos = Columcount
Xpos = Xpos - Temp
Xpos = Xpos - 8 'Correction to set Xpos on Xoffset with rotation
Xpos = Xpos + Xoffset
For Pixelcount = 7 To 0 Step -1
Ypos = A + Pixelcount
Pixel = Pixels.0
Pset Xpos , Ypos , Pixel
Shift Pixels , Right
Next Pixel
Next Columcount
Next Rowcount
Case 3 '270 degrees rotation
For Rowcount = 0 To Row Step 8
A = Rowcount + Xoffset
For Columcount = Colums To 0 Step -1
Pixels = Cpeek(pixels_adress)
Incr Pixels_adress
If Inverse = 1 Then Toggle Pixels
Xpos = Columcount
Xpos = Xpos - Temp
Xpos = Xpos - 8 'Correction to set Xpos on Xoffset with rotation
Xpos = Xpos + Yoffset
For Pixelcount = 0 To 7
Ypos = A + Pixelcount
Pixel = Pixels.pixelcount
Pset Ypos , Xpos , Pixel
Next Pixel
Next Columcount
Next Rowcount
End Select
Next Carcount
End Sub
'End of this amazing subroutine
'=== Includes ===
$include "project8x8_Courier New.font"
$include "project8x8_Cooper Black.font"
$include "project6x8_Consolas.font"
$include "project6x16_Agency FB.font"
$include "project21x16_Ravie.font"
$include "project12x14_Bauhaus 93.font"
$include "project10x15_Bernard.font"
$include "project6x8_Forte.font"
$include "project11x10_Stencil.font"
$include "project14x16_Comic.font"
$include "project15x16_Viner Hand.font"
$include "project12x16_Tempus.font"
$include "project19x16_Snap.font"
$include "project13x8_Goudy.font"