Usb to Rs-485

Needed to connect my Friendlyarm Mini2440 to the Joshua bus an Usb to Rs-485 converter.Idea is the same as in my Rs-485 to usb converter to connect the Joshua bus to the pc.

Schematic is not that special, it’s an copy from the datasheet of the FT232 from FTDI. Added only the OR port to prevent local echo when transmitting, this is also described in the datasheet.
The converter needed to build in the wall with the Friendlyarm touchsreen the space was limited. Using an Usb a<>b cable took to much space, the connectors of these cables are bigger then the converter itself.
Decide to make a pcb that can direct plug in the usb connector of the Friendlyarm board. Pcb’s are normally 1.6mm thick and that’s just to thin to fit properly. On the back i glued therefore an little piece of 0.5mm pcb to make it just thick enough to fit.

Download Eagle cad files

1745 Downloads

Schematic
3D Design
Bare pcb front
Bare pcb back
Finished pcb
Mounted to the friendly arm
PlayPause
previous arrow
next arrow
 
Schematic
3D Design
Bare pcb front
Bare pcb back
Finished pcb
Mounted to the friendly arm
previous arrow
next arrow

 

Video Splitter Amplifier

A simple analog 75Ω video splitter amplifier based on the NE592.
What can you tell about this? Not much. I needed a video signal splitter to get the signal from the security cams to the recorder, web server and monitor.
It splits 1 input to 3 outputs.
I made it stackable so that you need only 1 power supply, thus the stack passes only the supply no video.

In this design the gain is determined by R5 3K3, however for some cameras the gain was to high and I replaced R5 with a 25K trim pot meter so you can adjust the gain.

Schematic
3D Design
Finished
Stacked
Stacked
PlayPause
previous arrow
next arrow
 
Schematic
3D Design
Finished
Stacked
Stacked
previous arrow
next arrow

 

If you want to make one yourself, contact me for the pcb or download the Eagle-cad files here.

1498 Downloads

 

Siemens S65 Colordisplay

Landscape
Portrait
PlayPause
previous arrow
next arrow
 
Landscape
Portrait
previous arrow
next arrow

 

The Siemens S65 display with an resolution of 132×176 pixels is a very nice display, it’s bigger and clearer then the Nokia 128×128 display. It’s consumes less power then the Nokia.
Signal levels are at 3V so some level converter is needed when connecting to an 5V Avr. Nice schematic sample .
These routines are written for S65 display with the LS020 controller, other controllers are not supported.
Display can be used in landscape or portrait mode by changing the  Const Landscape = 0.
To keep the display compatible with Bascom’s BGC created with lcdconvert.exe and font files created with the font editor, it’s will switch to 8bit mode after init. This will result in 256 color’s.

2045 Downloads


Syntax

Lcdtext string, x , y , fontset , forecolor , backcolor

Remarks

 String  String to be displayd
 x  Constant or variable with x position.
 y  Constant or variable with y position.
 fontset  Fontset to be used to display the text
 Forecolor  RRRGGGBB
 Backcolor  RRRGGGBB

 

 

 

 

 

 

 

This will show text on the lcd. It uses the Bascom FONT files for compatibility.
To add or remove fontsets modify these lines in the subroutine;

If Fontset = 1 Then Restore Font8x8
If Fontset = 2 Then Restore Font16x16
If Fontset = 3 Then Restore Font6x8
If Fontset = 4 Then Restore Font5x5

Sorry, but there was no better solution.
These are the name’s that you gave to the font, NOT the filename if you don’t know the font name, open the font file in the font editor, and there it is, right on top.
Don’t forget to $Include your font files at the end of the program.

 

Syntax

S65_showpicture  x , y

Remarks

 x  Constant or variable with x position.
 y  Constant or variable with y position.

 

 

 

This will show an Bascom color BGC (Bascom graphic color) on the lcd.
Don’t forget to first RESTORE the image name, see the sample.

 

Syntax

S65_line  x1, y1 , x2 , y2 , color

Remarks

 x1  Starting horizontal location of the line.
 y1  Starting vertical location of the line.
 x2  Horizontal end location of the line.
 y2  Vertical end location of the line.
 color  RRRGGGBB

 

 

 

 

 

 

Draws a line on the lcd.

 

Syntax

S65_pset  x, y , color

Remarks

 x  The x location.
 y  The y location.
 color  RRRGGGBB

 

 

 

 

Set a pixel on the lcd.

 

Syntax

S65_cls  backcolor

Remarks

 backcolor  RRRGGGBB

 

 

Clears the lcd in an specified color.

 

Example code:

 '===================================================================================
'=                 Siemens S65 display routines for LS020 controller                             =
'= Special thanks to Dirk Milewski www.comwebnet.de who's routines i have used to get me going.  =
'=                Copyright, not for private use. by Evert Dekker 2009.                          =
'=                   Written and tested with Bascom version 1.11.9.3                             =
'===================================================================================
$hwstack = 100
$swstack = 100
$framesize = 100

$regfile = "m128def.Dat"
$crystal = 16000000
$baud = 19200



'=== Config the hardware ===
Rs Alias Porta.1                                            'S65 Data/command pin
Res Alias Porta.5                                           'S65 Reset pin
Cs Alias Porta.3                                            'S65 Chip Select pin
Clk Alias Portb.1                                           'S65 Clock pin
Dat Alias Portb.2                                           'S65 Data pin

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 = 128

'=== Define the constante ===
Const Blue = &B00000011                                     '8bit color  RRRGGGBB
Const Yellow = &B11111100
Const Red = &B11100000
Const Green = &B00011100
Const Black = &B00000000
Const White = &B11111111
Const Brightgreen = &B00111110
Const Darkgreen = &B00010100
Const Darkred = &B10100000
Const Darkblue = &B00000010
Const Brightblue = &B00011111
Const Orange = &B11111000

Const Displaysize_x = 176
Const Displaysize_y = 132
Const Total_pixels = Displaysize_x * Displaysize_y
Const Landscape = 0                                         'Change to 0 if you want to use the display in portrait


Declare Sub S65_init()
Declare Sub S65_pset(byval Lx As Byte , Byval Ly As Byte , Byval Color As Byte)
Declare Sub S65_line(byval Lx1 As Byte , Byval Ly1 As Byte , Byval Lx2 As Byte , Byval Ly2 As Byte , Byval Color As Byte)
Declare Sub S65_cls(byval Backcolor As Byte)
Declare Sub Lcdtext(byval S As String , Byval Xoffset As Byte , Byval Yoffset As Byte , Byval Fontset As Byte , Byval Forecolor As Byte , Byval Backcolor As Byte )
Declare Sub S65_cmdw(byval Cmd As Word)
Declare Sub S65_showpicture(byval Xoffset As Byte , Byval Yoffset As Byte)


'=== Main prog ===
S65_init                                                    'First thing to do, init the display
S65_cls White                                               'Clear the display with white background

Do
Lcdtext "Hello world" , 10 , 1 , 1 , Red , White
Lcdtext "SIEMENS" , 10 , 12 , 1 , White , Green
Lcdtext "S-65" , 10 , 23 , 2 , Blue , White
Lcdtext "By Evert Dekker 2009" , 20 , 50 , 4 , Black , White
Lcdtext "Landscape & portrait mode" , 5 , 60 , 4 , Black , White

 
Restore Plaatje                                             'FIRST restore you image before you can show it
S65_showpicture 1 , 70                                      'Show your image
Wait 2
S65_cls White
Wait 2
Loop
End


'=== Subroutines ===
Sub S65_init()                                              'Init the Siemens S65 display
Local Tempw As Word , Tempb As Byte
Set Res
Waitms 10
Reset Res                                                   'HW Reset
Set Cs
Set Clk
Set Dat
Set Rs
Waitms 1
Set Res                                                     'Reset End
Waitms 10
Set Cs
Waitms 1
Set Rs
Restore Init1
For Tempb = 1 To 12
Read Tempw
S65_cmdw Tempw
Next
Waitms 7
Restore Init2
For Tempb = 1 To 25
Read Tempw
S65_cmdw Tempw
Next
End Sub

Sub S65_cmdw(cmd As Word)                                   'Send 16bits to the display
Reset Cs
Shiftout Dat , Clk , Cmd
Set Cs
End Sub


Sub S65_cls(byval Backcolor As Byte)                        'Clear the lcd
Local Pixel As Word
Set Rs
S65_cmdw &HEF90
S65_cmdw &H0500
S65_cmdw &H0600
S65_cmdw &H0700
Reset Rs
Reset Cs
For Pixel = 0 To Total_pixels
 Shiftout Dat , Clk , Backcolor
Next Pixel
Set Cs
End Sub



Sub S65_pset(lx As Byte , Ly As Byte , Color As Byte)       'Set a pixel
Set Rs
#if Landscape = 1
   Ly = Displaysize_y - Ly
   S65_cmdw &H0600 + Ly
   S65_cmdw &H0700 + Lx
#else
   S65_cmdw &H0600 + Lx
   S65_cmdw &H0700 + Ly
#endif
Reset Rs
Reset Cs
Shiftout Dat , Clk , Color
Set Cs
End Sub



Sub S65_line(byval Lx1 As Byte , Byval Ly1 As Byte , Byval Lx2 As Byte , Byval Ly2 As Byte , Byval Color As Byte)       '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
M1 = Ly2 - Ly1
M2 = Lx2 - Lx1
Cv = M1 / M2
Bn = Int(cv)
M = Low(bn)
B = M * Lx1
B = -1 * B
B = B + Ly1
For R = Lx1 To Lx2
Yg = M * R
Yg = Yg + B
S65_pset R , Yg , Color
Next R
End Sub



Sub S65_showpicture(xoffset As Byte , Yoffset As Byte)      'Draw an Bascom BGC image on the lcd
' Important that you first RESTORE the image before calling this sub. Examp:  [ Restore Plaatje ]
Local Ysize As Byte , Xsize As Byte , Xpos As Byte , Ypos As Byte       'Dim some local variable
Local Tempx As Byte , Tempy As Byte
Local Imagesize As Word , Imagesize_l As Byte , Imagesize_h As Byte
Local L As Word , Pixel As Byte , Prevpixel As Byte , Repeat As Byte
Read Ysize                                                  'Read the first 4 bytes from the BGC, this contains info about the image
Read Xsize
Read Imagesize_l
Read Imagesize_h
Imagesize = Makeint(imagesize_l , Imagesize_h)              'Byte 3&4 contains the image size, add them together
Xpos = 1 : Ypos = 1                                         'Set the pointers to 1
Do
Read Pixel                                                  'Read the value for the pixel
   If Pixel = &HAA Then                                     'BGC file is lre coded &HAA represents this, the byte after &HAA is the number of times that the byte before &HAA wil be repeated
     Read Repeat                                            'Byte after &HAA contains the number of times to repeat
     Repeat = Repeat - 1
      For L = 1 To Repeat                                   'Loop the repeat
          Tempx = Xpos + Xoffset                            'Pixel position is the image postion + the offset
          Tempy = Ypos + Yoffset
          S65_pset Tempx , Tempy , Prevpixel                'Set the pixel, for repeating it's the byte before &HAA (prevpixel)
          Decr Imagesize                                    'Decrease the bytes still to be processed
          Incr Xpos                                         'Incr the xpos
            If Xpos > Xsize Then                            'If the xpos is larger then xsize of the image start at a new y line
               Xpos = 1                                     'and set the xpos pos back to the first position on the new line
               Incr Ypos                                    'Start a new y line
            End If
      Next L                                                'Next repeat loop
   Else                                                     'It's a regular byte, not LRE encoded
      Tempx = Xpos + Xoffset                                'Pixel position is the image postion + the offset
      Tempy = Ypos + Yoffset
      S65_pset Tempx , Tempy , Pixel                        'Set the pixel
      Prevpixel = Pixel                                     'Store the pixel in a temp byte, maybe we need it if the next byte is &HAA
      Decr Imagesize                                        'Decrease the bytes still to be processed
      Incr Xpos
         If Xpos > Xsize Then                               'If the xpos is larger then xsize of the image start at a new y line
          Xpos = 1                                          'and set the xpos pos back to the first position on the new line
          Incr Ypos                                         'Start a new y line
         End If
End If
Loop Until Imagesize = 0                                    'Do until all bytes are processed
End Sub


Sub Lcdtext(byval S As String , Xoffset As Byte , Yoffset As Byte , Fontset As Byte , Forecolor As Byte , Backcolor As Byte )       'Print text on the display
Local Tempstring As String * 1 , Temp As Byte               'Dim local the variables
Local A As Byte , Pixels As Byte , Count As Byte , Carcount As Byte , Lus As Byte
Local Row 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 Byte , Pixelcount As Byte
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

 If Fontset = 1 Then Restore Font8x8                        'Add or remove here fontset's that you need or not,
 If Fontset = 2 Then Restore Font16x16                      'this is the name that you gave to the font, NOT the filename
 If Fontset = 3 Then Restore Font6x8                        'If you dont know the name, open the font file in wordpad, and there it is,
 If Fontset = 4 Then Restore Font5x5                        'right on top.

 Temp = Carcount + 1                                        'Cut the text string in seperate caracters
Tempstring = Mid(s , Temp , 1)
Read Row : Read Byteseach : Read Blocksize : Read Dummy     'Read the first 4 bytes from the font file
Temp = Asc(tempstring) - 32                                 'Font files start with caracter 32
For Lus = 1 To Temp                                         'Do dummie read to point to the correct line in the fontfile
   For Count = 1 To Blocksize
    Read Pixels
   Next Count
Next Lus
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
   For Rowcount = 0 To Row Step 8                           'Loop for numbers of rows
     A = Rowcount + Yoffset
       For Columcount = 0 To Colums                         'Loop for numbers of Colums
         Read Pixels
         Xpos = Columcount                                  'Do some calculation to get the caracter on the correct Xposition
         Temp = Carcount * Byteseach
         Xpos = Xpos + Temp
         Xpos = Xpos + Xoffset
            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.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
       Next Columcount
   Next Rowcount
Next Carcount
End Sub                                                     'End of this amazing subroutine


'=== Includes ===
$include "Font8x8.font"                                     'Includes here your font files
$include "Font16x16.font"                                   'If you don't need the files in your program, don't include them,
$include "Font6x8.font"                                     'these are flash memory eaters.
$include "Font5x5.font"


Plaatje:
$bgf "mcse.bgc"


Init1:
Data &HFDFD% , &HFDFD%,
Data &HEF00%,
Data &HEE04% , &H1B04%,
Data &HFEFE% , &HFEFE%,
Data &HEF90% , &H4A04% , &H7F3F% , &HEE04% , &H4306%

Init2:
Data &HEF90% , &H0983% , &H0800% , &H0BAF% , &H0A00% , &H0500% , &H0600% , &H0700%,
Data &HEF00%,
Data &HEE0C%,
Data &HEF90% , &H0080%,
Data &HEFB0% , &H4902%,
Data &HEF00%,
Data &H7F01% , &HE181%,
Data &HE202%,
Data &HE276%,
Data &HE183%,
Data &H8001%,
Data &HEF90%,
Data &H0000%
Data &HEF90% , &HE801%                                      'Switch to 8-bit mode
GSM Gateway

UnderConstruction

New module under construction for the Joshuabus .
With this Gsm gateway we connect the Joshuabus with the outside world trough the gsm network.
It will send and receive sms to monitor and control the various devices.
The 128×64 graphic display will show some information about the gsm network, the prepaid saldo and the last callers with the commands they have send.

The Siemens Tc35i modem was given to me by my mate Anton. Unfortunately it was broken, communication with the mcu was most of the time working crappy. After some searching I found the problem, the charge pump of the Rs-232 driver chip was defect so the driver had to be replaced. Free sample from Maxim-ic.com and some fine soldering to bring it back online.

Design
Gsm Modem
Finished front
Finished back
PlayPause
previous arrow
next arrow
 
Design
Gsm Modem
Finished front
Finished back
previous arrow
next arrow

At this moment i’m working on the software to finish the project. Stay tuned…

Max7456 video overlay

The Max7456 from Maxim is a monochrome video overlay chip. With this you can overlay text and simple graphics over your PAL or NTSC video signal. You can also use it with no overlay, just like a simple monitor.

Osd with background
Osd with no background
Software
PlayPause
previous arrow
next arrow
 
Osd with background
Osd with no background
Software
previous arrow
next arrow

Included in this sample is a tutorial how you cam make your own characters with my converter tool. This tool converts the Maxim mcm files to Bascom data lines.

 

Syntax

Videotext string, y , x

Remarks

 String  String to be displayd
 y  Constant or variable with y position.
 x  Constant or variable with x position.

 

 

 

 

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

 

Syntax

Rowbrightness row, brightness

Remarks

Row  Row number to change 1-13 for NTSC , 1-16 for PAL
Brightness &B0000xx11 Character Black Level in % of OSD white level
00 = 0% 01 = 10% 10 = 20% 11 = 30%
&B000011xx Character White Level  in % of OSD white level
00 = 120%  01 = 100%  10 = 90% 11 = 80%

 

 

 

 

 

 

 

Syntax

Writecustomcharacter Characters

Remarks

Characters  Number of characters theat need to be programmed in the VRAM

 

 

Because the max7456 has NVM memory (eeprom) the writecustomercharacter routine only needs to be used one’s. The custom characters wil be left in the NVM memory even after power lost.

 

Downloads

Sample Bascom code , same as below
Maxim’s evaluation kit software , needed to edit the character table
Converter tool , to convert the mcm file.
Converter manual
Source code of the converter tool in VB6

And for the people who want to take it a step further, here a nice site (In German language) where is showed how to make your own graphics.

 

Update: 2009-03-24, Bug in the Bascom code and in the Converter tool, both fixed .
-Bascom: Max7456 was disabled in the Writecustomcharacter sub routine, but not enabled at the end of the sub.
-Converter tool: loops in exportarray was counting to 56 instead of 54, removed the loops and made fixed lines.

Example:

'=================================================
'=           MAX7456 Video overlay Demo          =
'=            By EvertDekker.com 2009            =
'= Created with Bascom-Avr: 1.11.9.3.001 license =
'=          No copyright for private use         =
'=                 Version 1.1                   =
'=================================================

$regfile = "m128def.DAT"
$crystal = 7372800
$baud = 19200
$hwstack = 75
$swstack = 75
$framesize = 50

Config Spi = Hard , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 0       'Setup the hardware spi
Spiinit                                                     'Init the spi bus

'=== Dimension ===
Dim Temp As Byte , Lus As Byte
Dim Regaddr As Byte
Dim Regdata As Byte
Dim Buffer(2) As Byte

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 Rowbrightness(byval Row As Byte , Byval Brightness As Byte)
Declare Sub Writecustomcharacter(byval Characters As Byte)

'=== 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

'=== Main ===
Initmax7456                                                 'Init the Max7456
Waitms 100
Writecustomcharacter 3                                      '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.

Do
Videotext "HELLO WORLD" , 1 , 8                             'Demo of the various possibilitys
Videotext "MAX7456 Video overlay" , 3 , 3
Videotext "Code written with Bascom-avr" , 4 , 0
Videotext "By Evertdekker.com" , 5 , 5
Videotext "{133}Flashing text{134}" , 9 , 0                 '{133}=start blinking text, {134}= stop blinking text
Videotext "{131}WITH BACKGROUND{132}" , 10 , 0              '{131}=enable the background, {132}= disable the background
Videotext "{135}Inverted TEXT{136}" , 11 , 0                '{135}=invert text, {136}= non-inverted text
Videotext "Adjust rowbrightness" , 12 , 0
Videotext "INCLUDE CUSTOM CHARS: + " , 7 , 0
'Rowbrightness 12 , &B00001111                               'Change the row brightness, see the SUB for the usage discription
Wait 5
Loop
End

'=== Subroutines===
Sub Initmax7456()
Writereg Vm0 , &B01001100
'01001000 ; 0 , 1=PAL, 00=Auto Sync, 1=Enable OSD, 0=Enable OSD always, 0=SW Reset, 0=Enable Video Buffer
Writereg Vm1 , &B01111111
'00010100 ; 0 = NA, 001=Background MODE Brightness 7%, 11=Blinking Time 160ms, 00=Blinking Duty Cycle BT:BT
Writereg Dmm , &B01000000
'01000000 ; 0=NA, 1=8bit operation,
Writereg Hos , &B00011111
'00011111 ; 00=NA, 00000000 = Farthest left (-32 pixels),00100000 = No horizontal offset, 00111111 = Farthest right (+31 pixels)
Writereg Vos , &B00010000
'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


Sub Writecustomcharacter(byval Characters As Byte)
 Local Count As Byte
  Restore Customcharacter                                   'Goto the begin of the data
 For Count = 1 To Characters                                'Number of characters that need to be programmed, must match with the characters in the data
  Writereg Vm0 , &B01000100                                 'Disable osd
  Read Regdata                                              'Read the first databyte, is the character to will be programmed
  Writereg Cmah , Regdata                                   'Write to the register
  For Lus = 0 To 53                                         'Each Character is made of 54bytes
       Writereg Cmal , Lus                                  'Write the byteno of the character
       Read Regdata                                         'Read the data from the datatable
       Writereg Cmdi , Regdata                              'program the data in the shadowram
  Next Lus
  Writereg Cmm , &HA0                                       'Copy shadowram to NVram
  Waitms 200                                                'Wait until copy is ready
 Next Count
  Writereg Vm0 , &B01001100                                 'enable osd
End Sub

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


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 &H42                                                   '37 % (not excist)
Data &H42                                                   '38 & (not excist)
Data &H47                                                   '39 '
Data &H3F                                                   '40 (
Data &H40                                                   '41 )
Data &H42                                                   '42 * (not excist)
Data &H50                                                   '43 + (not excist)
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 3 characters in this datatable
Data &H50 ' Character 80
Data &H55, &H55, &H55, &H55, &H55, &H55, &H55, &H00
Data &H15, &H54, &HAA, &H85, &H52, &HAA, &HA1, &H52
Data &HA0, &HA8, &H52, &H85, &H28, &H02, &H80, &H41
Data &H2A, &HAA, &H15, &H2A, &HAA, &H15, &H42, &H80
Data &H55, &H2A, &HAA, &H15, &H2A, &HAA, &H01, &H02
Data &H85, &H28, &H52, &HA0, &HA8, &H52, &HAA, &HA1
Data &H54, &HAA, &H85, &H55, &H00, &H15
Data &H51 ' Character 81
Data &H55, &H55, &H55, &H55, &H55, &H55, &H55, &H55
Data &H55, &H55, &H56, &H55, &H55, &H56, &H55, &H55
Data &H56, &H55, &H6A, &HAA, &HAA, &H55, &H5A, &H55
Data &H55, &H66, &H55, &H55, &H66, &H55, &H55, &H96
Data &H55, &H55, &H96, &H55, &H56, &H56, &H55, &H59
Data &H56, &H55, &H65, &H56, &H55, &H55, &H56, &H55
Data &H55, &H5A, &H55, &H55, &H55, &H55
Data &H52 ' Character 82
Data &H55, &H55, &H55, &H55, &H55, &H55, &H55, &H55
Data &H55, &H55, &H59, &H55, &H55, &H59, &H55, &H55
Data &H59, &H55, &H6A, &HAA, &HAA, &H55, &H59, &H56
Data &H55, &H59, &H56, &H55, &H65, &H56, &H55, &H65
Data &H56, &H55, &H65, &H56, &H55, &H95, &H56, &H55
Data &H95, &H56, &H56, &H55, &H56, &H56, &H55, &H56
Data &H59, &H55, &H69, &H55, &H55, &H55