3.5″ 320×240 Color touch screen

On ebay i found this very nice and cheap tft display .It contains a tft color screen with 320x240 pixels, touch-controller and Sd card reader.
The display controller used is the SSD2119 and for the touch controller they used ADS7843.
Demo is running on Atmel Avr M1284P @16Mhz with Bascom 1.12.0.0

Jumpers
Back Display
Demo
Demo
PlayPause
previous arrow
next arrow
 
Jumpers
Back Display
Demo
Demo
previous arrow
next arrow
3.5" 320x240 Color TFT Demo with touchscreen, Bascom and SSD2119 controller

Some Notes:
-- 320x240x16bits needs enormous amount of data and cpu power to get something on the screen, don’t expect live video @25fps. Take a look at the video to get an idea of the performance.
-- To get the display compatible with the Bascom 8bit BGC (Bascom Grapichs Color) files, the 8bits color are up-scaled to 16bits. Therefore the colors are maybe not always correct, you can adjust this in the look-up table.
-- The size of the BGC are limited to 255x255 pixels.
-- The 24bit colors of the BMP files are downscaled to 16bits by simply dropping the LSB.
-- Jumpers setting of the display board  are a bit strange, make the soldering connection is a logic 0 and removing the solder is a logic 1.
-- The touch controller needs Polarity =low and Phase =0 for the spi communication, the Sd cards needs Polarity =high and Phase =1. To overcome this problem in the readtouch function’s the Polarity and Phase are changed at the beginning of the function and changed back at the end.
-- Display works on 3.3V so use a level converter or an AVR that can run on 3.3V.
-- Add the Spiin = 255 option to the Config Spi line in Config_mmc.bas if your using the touch and sd-reader, else it won’t work.

3596 Downloads

 

Syntax

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

Remarks

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

 

 

 

 

 

 

 

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 file-name 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

Lcd_showpicture_bmp Filename, x , y

Remarks

 Filename  Filename of Windows BMP file (24bpp)
 x  Constant or variable with x position.
 y  Constant or variable with y position.

 

 

 

 

This will show Windows 24bpp BMP from the sd card. The 24bpp colors are downscaled to 16bpp.
Requires Avr-dos.

 

Syntax

Lcd_showpicture_sd Filename, x , y

Remarks

 Filename  Filename of Bascom BGC file
 x  Constant or variable with x position.
 y  Constant or variable with y position.

 

 

 

 

This will show Bascom BGC (Bascom Graphics Color) file from the sd-card. The 8bpp colors are up-scaled to 16bpp with the help of a look-up table. In this table you can adjust the colors if necessary.
Requires Avr-dos.

 

Syntax

Lcd_showpicture  x , y

Remarks

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

 

 

 

This will show Bascom BGC (Bascom Graphics Color) file from the flash memory. The 8bpp colors are up-scaled to 16bpp with the help of a look-up table. In this table you can adjust the colors if necessary.
Important that you first Restore the picture, for example;
Restore Girl                                                ‘FIRST restore you image before you can show it
Lcd_showpicture_sd “girl.bgc”, 150 , 10

 

Syntax

Lcd_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  RRRRRGGGGGGBBBBB

 

 

 

 

 

 

Draws a line on the lcd.

 

Syntax

Lcd_clear  backcolor

Remarks

 backcolor  RRRRRGGGGGGBBBBB

 

 

Clears the lcd in an specified color.

 

Syntax

Lcd_pset  x, y , color

Remarks

 x  The x location.
 y  The y location.
 color  RRRRRGGGGGGBBBBB

 

 

 

 

Set a pixel on the lcd.

 

Syntax

Lcd_Setcursor  x, y

Remarks

 x  The x location.
 y  The y location.

 

 

 

Set the ram address (cursor) to the specified position.

 

Syntax

Write_data  data16

Remarks

 Data16  Word

 

 

Write 16bit data to the lcd

 

Syntax

Write_Command  Command

Remarks

 Command  Word

 

 

Write 16bit command to the lcd

 

Syntax

Lcd_reset

Hardware lcd reset

 

Syntax

Lcd_init

Init the lcd

 

Syntax

Lcd_home

Set the ram address (cursor) to the home position

 

Syntax

A= Rgb16  rgb8

Remarks

 A  16bpp RGB Word
 rgb8  8bpp RGB

 

 

 

Convert 8bpp color to 16bpp color.

 

 

Syntax

A= Readtouch_X

Remarks

 A  12 Bit x position
 rgb8  8bpp RGB

 

 

 

Reads the X coordinates from the touchscreen.

 

 

Syntax

A= Readtouch_Y

Remarks

 A  12 Bit y position
 rgb8  8bpp RGB

 

 

 

Reads the Y coordinates from the touchscreen.

 

 

 

Bascom Bootloader Pc-side

 

This program is compatible with the Bascom Avr-Bootloader as it’s shipped with Bascom 1.11.9.9.
You can program the flash with it, but not the eeprom, feel free to modify the code and share it with us.
It’s written in Vb6 and uses the (Free) McsCom module from Mcselec.com for communication.

Tested with Bascom 1.11.9.9, Mega8 and M128.

Download now inclusief source code.

2251 Downloads

Screenshot.JPG

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.

2027 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
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
I2C Eeprom programmer

What is it?
It’s an Eeprom programmer controlled by Bascom Avr and is capable of programming in circuit Eeprom’s up to 512Kb. Standard Intel Hex8 file is required.
Extended Linear Address Records for Eeprom’s bigger then 16bits addresses is not (yet) supported, but easy to implant.
I wrote it primary for my other application note RC2 sound / voice playback to upload the sound files to the i2c Eeprom.
Special thanks to Mark from Mcselec how has added in the vb6 an asm to intelhex routine so Atmel studio is not needed anymore.

Required tools
For the Pc side there’s an upload program that sends the Intel Hex file to the AVR.
Program is written in VB6-Sp6, source code is also available.

The code
Code is written and tested in Bascom 1.11.9.0.001 license.
Download the Bascom source code here

 

'--------------------------------------------------------------------
'                       I2C Eeprom programmer
'Upload your Eeprom files through serial connection in the I2c Eeprom
'       No extended address supported, so max 512K Eeprom
'     By Evert Dekker 2008 i2cprogrammer@Evertdekker dotje com
'                Created with Bascom-Avr: 1.11.9.0.100
'--------------------------------------------------------------------

$regfile = "m128def.DAT"
$crystal = 16000000
$baud = 19200
$hwstack = 70
$swstack = 70
$framesize = 60

$lib "I2C_TWI.LBX"                                          'Setting up i2c hardware bus
Config Twi = 400000                                         'Hardware i2c bus speed
Config Scl = Portd.0                                        'TWI (i2c) ports on the Mega128
Config Sda = Portd.1
Const Addressw = &B10100000                                 'slave write address eeprom
Const Addressr = &B10100001                                 'slave read address eeprom


Dim Startbyte As Byte , Instring As String * 45 , Complete As Bit
Dim Temp As Byte , Temps As String * 3
Dim Bytecount As Byte , Addresshigh As Byte , Addresslow As Byte , Recordtype As Byte , Databyte(16) As Byte , Checksm As Byte
Dim Lus As Byte , Pos As Byte , Checksum_calc As Byte , Checksum_error As Bit

Enable Urxc
Enable Interrupts
On Urxc Bytereceived_isr


'=== Main  ===
Do
If Complete = 1 Then                                        'Wait until the buffer is filled with one line
  Gosub Process_buffer                                      'Process the buffer
  Gosub Calculate_checksum                                  'Calculate the cheksum
     If Recordtype = &H01 Then                              'EOF finished, send a ACK and return
      Print "Y";
     Else
       If Checksum_error = 0 Then                           'If there's no error continue
         Select Case Recordtype                             'do something with the recordtype
            Case &H00                                       'Data byte
                Gosub Prog_eeprom                           'Recordtype &H00 = databyte, so lets programm the Eeprom
            Case &H02                                       'Extended Linear Address Records, not (yet) supported
               nop
         End Select
       Print "Y";                                           'Checksum ok, send a ACK
      Else
       Print "Z";                                           'Checksum error send a Nack
     End If
    End If
  Complete = 0 : Instring = ""                              'Reset the variable
End If
Loop
End


'=== Subroutines ===
Prog_eeprom:
    I2cstart                                                'start condition
    I2cwbyte Addressw                                       'slave address
    I2cwbyte Addresshigh                                    'Highaddress of EEPROM
    I2cwbyte Addresslow                                     'Lowaddress of EEPROM
       For Lus = 1 To Bytecount
         I2cwbyte Databyte(lus)                             'value to write
       Next Lus
    I2cstop                                                 'stop condition
    Waitms 10                                               'wait for 10 milliseconds
Return


Process_buffer:
Temps = Mid(instring , 1 , 2) : Bytecount = Hexval(temps)   'Read the numbers of bytes
Temps = Mid(instring , 3 , 2) : Addresshigh = Hexval(temps) 'Read the high adress
Temps = Mid(instring , 5 , 2) : Addresslow = Hexval(temps)  'Read the low adress
Temps = Mid(instring , 7 , 2) : Recordtype = Hexval(temps)  'Read the recordtype
For Lus = 1 To Bytecount                                    'Process the number of data bytes
      Pos = Lus * 2
      Pos = Pos + 7
      Temps = Mid(instring , Pos , 2) : Databyte(lus) = Hexval(temps)       'Read the databytes
Next Lus
Pos = Pos + 2                                               'read the last byte
Temps = Mid(instring , Pos , 2) : Checksm = Hexval(temps)   'Read checksum
Return


Calculate_checksum:
Temp = 0                                                    'Add up all the databytes
Temp = Temp + Bytecount
Temp = Temp + Addresshigh
Temp = Temp + Addresslow
Temp = Temp + Recordtype
   For Lus = 1 To Bytecount
    Temp = Temp + Databyte(lus)
   Next Lus
Checksum_calc = 256 - Temp                                  'taking its two's complement
   If Checksum_calc <> Checksm Then                         'Compare it with the readed value
    Checksum_error = 1
   Else
    Checksum_error = 0
   End If
Return

Bytereceived_isr:
Temp = Udr                                                  'get the binary value that came across
If Temp = &H0D Then                                         'Received CR = end of line, line complete
 If Len(instring) < 8 Then                                  'To short, startover again
   Complete = 0
   Instring = ""
 Else
   Complete = 1                                             'String is complete set the flag
 End If
End If

If Startbyte = &H3A Then                                    'we have previously received the start byte and this is now data
  If Temp > &H0F Then                                       'Add incoming data to buffer
     Instring = Instring + Chr(temp)
    If Len(instring) > 45 Then Instring = ""                'String is to long, reset and startover again
 End If
End If

If Temp = &H3A Then                                         'if we received an : then its the beginning of an new line.
   Startbyte = Temp
   Complete = 0
   Instring = ""
End If
Return