View previous topic :: View next topic |
Author |
Message |
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Tue Dec 17, 2013 4:32 am Post subject: Solved Mikromedia for AtmegaM1280 module |
|
|
I'm trying to configure code from Ben Zijlstra to adapt it to drive the Mikromedia for Atmega1280 module.
However I have not been able to make it work.
Ben worked on a great piece of software to drive the TFT LCD using the HX8347-A controller.
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10835
The module Ben used is also M1280 but the TFT connection is different than mine. The MikroE module I have is hardwired so I cannot remap the data mode. I have grabbed a couple of units to test it at $86 from Mouser
To use with the MikroE M1280 module I have changed the data port:
Code: | VH Alias PortC
VL Alias PortA
|
For the command signals, I have configured as:
Code: | RS Alias PortG.2
Lcd_WR Alias PortG.0
CS Alias PortJ.5
Lcd_RES Alias PortJ.6 |
8Mhz for the Crystal, and all the rest seems to be compatible.
However, the module Ben is using has the HX8347-A controller, and the MikroE uses the HX8347-D controller.
Also, the MikroE uses the "8080 MCU 16 Bit parallel Type II" mode. I mean DB1-DB8 & DB10-DB17 (non DB0 & Db9).
Could be different the initialization from "A" to "D" controller..? Also I think the configuration Bytes is different.
Have someone tested by any chance this module, Mikromedia for Atmega1280 module, with this TFT code...?
BTW, this is the connection of the Mikromedia M1280 module: Code: | LCD Atmega1280
------------------
DB0 Not used, GND
DB1 PA.0
DB2 PA.1
DB3 PA.2
DB4 PA.3
DB5 PA.4
DB6 PA.5
DB7 PA.6
DB8 PA.7
DB9 Not Used, GND
DB10 PC.0
DB11 PC.1
DB12 PC.2
DB13 PC.3
DB14 PC.4
DB15 PC.5
DB16 PC.6
DB17 PC.7
RESET PJ.6
RS PG.2
CS PJ.5
RD PG.1
WR PG.0
Uses IM0=0 IM1=1 IM2=0 IM3=0 |
(BASCOM-AVR version : 2.0.7.6 )
Last edited by Matrixx on Sat Jan 25, 2014 4:46 am; edited 1 time in total |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Sat Jan 25, 2014 4:23 am Post subject: |
|
|
Well.. after some more research, I have the Mikromedia for Atmega TFT module finally working with Bascom, and its integrated Atmega1280
Controller: HX8347-D
The code from Ben Zijlstra did it all; my problem was on to change the initialization section with the correct bytes to correctly drive the TFT with "D" version.
The rest is the same at execption I renamed some LCD alias.
Thanks Ben!!! |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
Posted: Sat Jan 25, 2014 10:00 am Post subject: |
|
|
Would like to post the final result?
Thanks, meister |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Thu Feb 13, 2014 6:19 pm Post subject: |
|
|
Sure, this is the init code that worked for me with the HX8347-D and the Mikromedia for Atmega (M1280) module.
Code: | '**
' * @brief Configures sets of TFT controllers register to work with parameters
' * assigneg in TFT_Init. Also it resets the TFT controller.
' *
Sub Tft_reset_device
' Hold in reset
Tft_16bit_rst = 0
' Set reset pin as output
' Enable data access
Tft_16bit_rs = 1
' Set RS pin as output
' Disable LCD
Tft_16bit_cs = 1
' Set LCD CS pin as output
Tft_16bit_rd = 1
Tft_16bit_wr = 1
' Release from reset
Waitms 100
Tft_16bit_rst = 1
Waitms 100
Waitms 100
' Driving ability setting
Call Tft_16bit_set_reg(&Hea , &H00) ' PTBA[15:8]
Call Tft_16bit_set_reg(&Heb , &H20) ' PTBA[7:0]
Call Tft_16bit_set_reg(&Hec , &H0C) ' STBA[15:8]
Call Tft_16bit_set_reg(&Hed , &HC4) ' STBA[7:0]
Call Tft_16bit_set_reg(&He8 , &H40) ' OPON[7:0]
Call Tft_16bit_set_reg(&He9 , &H38) ' OPON1[7:0]
Call Tft_16bit_set_reg(&Hf1 , &H01) ' OTPS1B
Call Tft_16bit_set_reg(&Hf2 , &H10) ' GEN
Call Tft_16bit_set_reg(&H27 , &HA3)
' Gamma 2.8 setting
Call Tft_16bit_set_reg(&H40 , &H00) '
Call Tft_16bit_set_reg(&H41 , &H00) '
Call Tft_16bit_set_reg(&H42 , &H01) '
Call Tft_16bit_set_reg(&H43 , &H13) '
Call Tft_16bit_set_reg(&H44 , &H10) '
Call Tft_16bit_set_reg(&H45 , &H26) '
Call Tft_16bit_set_reg(&H46 , &H08) '
Call Tft_16bit_set_reg(&H47 , &H51) '
Call Tft_16bit_set_reg(&H48 , &H02) '
Call Tft_16bit_set_reg(&H49 , &H12) '
Call Tft_16bit_set_reg(&H4a , &H18) '
Call Tft_16bit_set_reg(&H4b , &H19) '
Call Tft_16bit_set_reg(&H4c , &H14) '
Call Tft_16bit_set_reg(&H50 , &H19) '
Call Tft_16bit_set_reg(&H51 , &H2F) '
Call Tft_16bit_set_reg(&H52 , &H2C) '
Call Tft_16bit_set_reg(&H53 , &H3E) '
Call Tft_16bit_set_reg(&H54 , &H3F) '
Call Tft_16bit_set_reg(&H55 , &H3F) '
Call Tft_16bit_set_reg(&H56 , &H2E) '
Call Tft_16bit_set_reg(&H57 , &H77) '
Call Tft_16bit_set_reg(&H58 , &H0B) '
Call Tft_16bit_set_reg(&H59 , &H06) '
Call Tft_16bit_set_reg(&H5a , &H07) '
Call Tft_16bit_set_reg(&H5b , &H0D) '
Call Tft_16bit_set_reg(&H5c , &H1D) '
Call Tft_16bit_set_reg(&H5d , &HCC) '
' Window setting
If Tft_16bit_disp_rotation = 90 Then
Call Tft_16bit_set_reg(&H04 , &H00)
Call Tft_16bit_set_reg(&H05 , &HEF)
Call Tft_16bit_set_reg(&H08 , &H01)
Call Tft_16bit_set_reg(&H09 , &H3F)
Else
Call Tft_16bit_set_reg(&H02 , &H00)
Call Tft_16bit_set_reg(&H03 , &H00)
Call Tft_16bit_set_reg(&H06 , &H00)
Call Tft_16bit_set_reg(&H07 , &H00)
'-----
Call Tft_16bit_set_reg(&H04 , &H01)
Call Tft_16bit_set_reg(&H05 , &H3F)
Call Tft_16bit_set_reg(&H08 , &H00)
Call Tft_16bit_set_reg(&H09 , &HEF)
End If
If Tft_16bit_disp_rotation = 90 Then
If Is_tft_16bit_rotated_180() = 1 Then
Call Tft_16bit_set_reg(&H16 , &HC8) ' MY=1, MX=1, MV=0, BGR=1
Else
Call Tft_16bit_set_reg(&H16 , &H08) ' MY=0, MX=0, MV=0, BGR=1
End If
Else
If Is_tft_16bit_rotated_180() = 1 Then
Call Tft_16bit_set_reg(&H16 , &HA8) ' MY=0, MX=1, MV=1, BGR=1
Else
Call Tft_16bit_set_reg(&H16 , &H68) ' MY=1, MX=0, MV=1, BGR=1
End If
End If
' Power Voltage Setting
Call Tft_16bit_set_reg(&H1b , &H1B) ' VRH = 4.65
Call Tft_16bit_set_reg(&H1a , &H01) ' BT
Call Tft_16bit_set_reg(&H24 , &H2F) ' VMH
Call Tft_16bit_set_reg(&H25 , &H57) ' VML
' Vcom offset
Call Tft_16bit_set_reg(&H23 , &H8D) ' FLICKER ADJUST
' Power ON Setting
Call Tft_16bit_set_reg(&H18 , &H36) '
Call Tft_16bit_set_reg(&H19 , &H01) '
Call Tft_16bit_set_reg(&H01 , &H00) '
Call Tft_16bit_set_reg(&H1f , &H88) '
Waitms 5
Call Tft_16bit_set_reg(&H1f , &H80) '
Waitms 5
Call Tft_16bit_set_reg(&H1f , &H90) '
Waitms 5
Call Tft_16bit_set_reg(&H1f , &HD0) '
Waitms 5
' 65K Color Selection
Call Tft_16bit_set_reg(&H17 , &H05) '
' Set Panel
Call Tft_16bit_set_reg(&H36 , &H00) ' Panel characteristic control register
' Display ON Setting
Call Tft_16bit_set_reg(&H28 , &H38) '
Waitms 10 : Waitms 10 : Waitms 10 : Waitms 10
Call Tft_16bit_set_reg(&H28 , &H3C) '
End Sub |
|
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Thu Feb 13, 2014 6:24 pm Post subject: |
|
|
Question for Ben:
In your code, I see you use a couple of fonts:
Code: | $include "Font8x8.font"
$include "Font12x16.font" |
I'm trying to use bigger fonts but the result is scrambled pixels output.
I would like to use say, 32x32, 48x48 etc.
Do you have already fonts like that..?
I'm understanding how to make my our fonts but until now, don't have a good clue. |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Thu Feb 13, 2014 7:17 pm Post subject: font25x32 |
|
|
If you check the wiki, the 7 inch board, you will see I have used a 25x32 font.
have fun
Ben Zijlstra |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Thu Feb 13, 2014 7:56 pm Post subject: |
|
|
Thanks Ben, I will check it now.
About creating fonts, I didn't realized about the FontEditor is the required tool.
I still have the problem of correct interpret the bytes (scrambled output). |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Thu Feb 13, 2014 9:46 pm Post subject: font |
|
|
If you check the first datalines of the fontfile you will find how many bytes are used to create the characters.
These are read and used to put the character on the display.
you could open the font25x32 in the bascom fonteditor to check if they are placed in the right direction, so not up side down.
have fun
Ben Zijlstra |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Thu Feb 13, 2014 9:56 pm Post subject: |
|
|
Ok, tested also the font "Font32x32.font", upside down too.
FontEditor shows chars are all Ok.
The font content
Code: | Font32x32:
$asm
.db 4,32,128,0 |
Char rows = 4
Row lenght = 32
Char bytes = 128
Dummy = 0 |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Fri Feb 14, 2014 2:11 am Post subject: |
|
|
Ok, this is what is happening:
For this fragment of code:
Code: | If Fontset = 2 Then
Restore Font12x16
Else
Restore Font8x8
End If
'-----------------------------
For Py = Char_rows To 1 Step -1
Ptemp = Py - 1
Ptemp = Ptemp * Char_row_len
For Zeichen_row = 0 To 7
For Px = 1 To Char_row_len
Ptemp2 = Ptemp + Px
Ben1 = Ptemp2
If Fontset = 2 Then
If Ben1 > 12 Then
Ben1 = Ben1 - 12
Goto Quit
End If
If Ben1 < 13 Then
Ben1 = Ben1 + 12
End If
End If
Quit:
If Zeichenarray(ben1).zeichen_row = 1 Then
Tft_16bit_dataport_lo = Low(forecolor)
Tft_16bit_dataport_hi = High(forecolor)
nop
Tft_16bit_wr = 0
nop
Tft_16bit_wr = 1
Else 'backgroundcolor
Tft_16bit_dataport_lo = Low(backcolor)
Tft_16bit_dataport_hi = High(backcolor)
nop
Tft_16bit_wr = 0
nop
Tft_16bit_wr = 1
End If
Next Px
Next Zeichen_row
Next Py |
you handle something special when the restored font is 12x16 (Fontset 2) at this part:
Code: | If Fontset = 2 Then
If Ben1 > 12 Then
Ben1 = Ben1 - 12
Goto Quit
End If
If Ben1 < 13 Then
Ben1 = Ben1 + 12
End If
End If |
If I comment out that condition, the original code outs garbage to the LCD with the same font12x16 too.
You substract 12 from the original Ptemp2 (now Ben1) and use it to write the LCD. When I add a different font other than 12x16, say 32x32, this condition is not satisfied as I use Fonset=3.
I played a bit with the font names so I load font32x32 with the fontset ID=2 so the condition match. But seems there is need some new calculation for the chars to be displayed correctly.
I added the routine from the wiki project page, and changed the For..Next value descending to ascending, and after some other changes I was able to let it work as the previous one, with the font8x8 and font12x16. I had to add the condition (If fontset=2) and the related vars to get it to work.
I still do not understand very well how the bytes are stored at the font file. Did some bunch of binary writes on paper to better understand or visualize the character bitmap pattern. i know the header provides that 4 values, but how is read and sent to the LCD is what I'm trying to learn. Also i have been looking at your example of the "!" character but still do not relate.
So I played a bit about your way to substract 12 when font is <> 8x8. I set a Proteus Virtual Terminal to debug some Prints, so not having to flash the micro everytime.
From what I see, when Ptemp2 is >12 you substract and the final values for Ben1 runs from 1 to 32.
I know that my garbage at the screen is caused by not interpreting correctly the bytes from the font file.
I would like to know why you susbtract 12 to make the font12x16 to work (and add 12 if <13), and how you deducted that...
Because when I load the font32x32 that operation should change.
|
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Sat Feb 15, 2014 10:32 pm Post subject: |
|
|
Ok, after the study I have identified now how the data and bit pattern is distributed on the font file.
Now, to figure out about the procedure |
|
Back to top |
|
|
Matrixx
Joined: 30 Nov 2005 Posts: 158
|
Posted: Mon Feb 17, 2014 10:18 pm Post subject: |
|
|
Problem solved. It was need to redesign a little bit the inner loops for the character bits sweep.
Here the output at virtual terminal of the bit patterns
And the 32x32 LCD test
Last edited by Matrixx on Tue Feb 18, 2014 2:49 pm; edited 1 time in total |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Tue Feb 18, 2014 10:20 am Post subject: Well done!! |
|
|
Very well done!!
All credits for the display routines go to (Heiko) HKipnik and SIX1. You can find a lot of there work in the German Bascom-forum.
[url]bascomforum.de[/url]
And also Evert Dekker, he found the trick to create a small window (with a font of 25 x 32 - 25 wide and 32 high) and fill it with the character data in one single stream, without pointing to X and Y. You can find it at the set_window subroutine.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|