Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

2.8inch 65K FullColorLCD 240x320dot [ILI9341]
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Tue May 28, 2019 2:56 am    Post subject: 2.8inch 65K FullColorLCD 240x320dot [ILI9341] Reply with quote

The graphic instructions (LINE, BOX, LCDAT, etc) of BASCOM-AVR are limited to byte addressing (0-255) for LCD.
Because of that limitation, other users have created a function for the [ILI9341] (240x320 dot) LCD.
However, I and some users would like to use BASCOM's standard graphics instructions.

Thereat, for LCDs with more than 256 dots, we added offsets to the screen addressing to enable BASCOM standard graphics instructions.
Although there are restrictions on instruction execution, this is another approach to large screen LCDs.

how to use
To specify a position where the screen address exceeds 255, put (1) in the variable [Offset256].
An address can not be drawn across 255 and 256.
If the address specification of each instruction is 256 or more, the description of the address value is the same whether 256 or 0.

Circuit diagram
https://drive.google.com/file/d/1e-ByaqDKedDtw5EJp9cQcHmUnOcFMrbn/view?usp=sharing
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4970
Location: Holland

blank.gif
PostPosted: Tue May 28, 2019 8:53 am    Post subject: Reply with quote

Hello O-Family

Thank you for sharing this smart solution.

Maybe it would be a good idea to add an option so the compiler can pass words instead of bytes. This would only work with custom libs like this.
If you think this is a good idea then please contact me.

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Tue May 28, 2019 3:05 pm    Post subject: Reply with quote

Hi, Mark

Graphic LCD functions created by other users have many functions and high performance, which is very nice.
However, the instructions (function names) and parameters differ depending on the author of the function and the LCD, so learning and understanding are required for each.
This loses the advantage of the standard command language, which is an advantage of the BASIC language, and is similar to how to handle C language.
Furthermore, I think that it will be necessary to have a detailed manual for each beginner.

It is probably the best option for the compiler to pass the graphic LCD instruction's word address and word color information to the library.
I think that will create a new library, so I want that option.

O-Family
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 19

PostPosted: Sat Jun 22, 2019 6:44 pm    Post subject: Reply with quote

Hello O-Family.

I tryed to use this LCD display (IL9341) and probably I did't understand your instructions. After compile file I get an error message:

Error : 5 Line : -2871 No more space for BIT [OFFSET256] , in File : C:\_MS PROGRAMS\BAS-AVR\LIB\GLCD-ILI9341_2R8_240X320.LIB
Error : 320 Line : 185 [syntax error, token = '{'] , in File : C:\_MS PROGRAMS\BAS-AVR\LIB\GLCD-ILI9341_2R8_240X320.LIB

Please would you be so kind and explane again, maybe more detail, what I have to do, that LCD will running. Where I have to change "Offset 256"? For test I took your example file. Different are only aliases for ports. I tryed this on ATMEGA328P and also ATXMEGA128 (using Virtual port), but error message is the same.

Best regards M.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Sun Jun 23, 2019 2:53 am    Post subject: Reply with quote

Hi,
The error has weird things.

Error: 5 Line: -2871 No more space for BIT [OFFSET 256]
I do not think that the line number of the error will be minus [-2871].

Error: 320 Line: 185 [syntax error, token = '{']
Error code [320] does not have its number in the BASCOM manual.

This little information is difficult to solve.
Is the latest version of BASCOM?
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 19

PostPosted: Sun Jun 23, 2019 2:21 pm    Post subject: Reply with quote

Hello.
I use version of Bascom 2.0.8.1.

I fixed a problem.

On ATMEGA328PU after a combination of pins start work. I forget to make

Code:
Dim Offset256 As Byte


On XMEGA128A3 I have still problem. (something with VPORT)

Thank you and
Best regards. M.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Sun Jun 23, 2019 3:23 pm    Post subject: Reply with quote

You said the same error would occur in my sample code, so deleting [Dim Offset 256 As Byte] did not give the error you presented.

This library has been modified for the ST7735R, so it will be solved if you check the thread corresponding to the ST7735R XMEGA.
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 19

PostPosted: Tue Jun 25, 2019 5:49 am    Post subject: Reply with quote

Error accure because [Dim Offset 256 As Byte] missed.
I try to use another LIB (ST7735R) on ATXMEGA128A3U but I'm not successful.

I don't know, how can modify LIB file.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Tue Jun 25, 2019 11:46 pm    Post subject: Reply with quote

If you can not solve with the forum information, you need to present what kind of error you will get or the source file where the error will occur.

Otherwise you can not get help.
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 19

PostPosted: Wed Jun 26, 2019 7:14 pm    Post subject: Reply with quote

Hello.
I can compile file without error, but nothing is shown on display.
In attach is modified your file on ATXMEGA128A3U.

Best regards. M.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Sun Jul 07, 2019 3:02 am    Post subject: Reply with quote

If the virtual port connected to the LCD is the same port, it will operate normally.

The problem with multiple virtual ports is unknown.
I do not know I am not familiar with Xmega.
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Mon Jul 08, 2019 1:44 am    Post subject: Reply with quote

A bug was found in the original [glcd-ST7735R.lib].
It does not work if A0=[DC] and Sclk=[SCK] are assigned to another port.
* Sbi _glcd_port_scl, _glcd_a0 -> * Sbi _glcd_port_a0, _glcd_a0
* Cbi _glcd_port_scl, _glcd_a0 -> * Cbi _glcd_port_a0, _glcd_a0

This bug also occurs in the ST7735R library and the same symptoms occur on both regular AVR and Xmega.
Attach the corrected [glcd-ILI9341_2R8_240x320.lib].
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 19

PostPosted: Mon Jul 08, 2019 5:51 pm    Post subject: Reply with quote

O-Family thank you, thank you very much.
It works now perfect also on ATXMEGA128A3U.

But I have one question more:
How can I transform my fonts (I use them on monocrome LCD) like color fonts. I tryed to do it with TT Font maker (EDC), but unsucsessful.
It works only with color8x8.fonts and color16x16.fonts.

Best regards M.
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Tue Jul 09, 2019 1:05 am    Post subject: Reply with quote

Hi,
It was good to work well!

The font for monochrome and the font for color are different in data arrangement.
It is due to the structure of the internal memory of each LCD.

Furthermore, BASCOM's early color LCD library and the original ST7735R library created by "Mrshilov" do not support through type fonts.
It takes a great deal of effort to make this possible, so expect other users' efforts.
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 173
Location: Japan

japan.gif
PostPosted: Fri Sep 27, 2019 10:40 am    Post subject: 2.8in full color LCD 240x320dot Touch screen Reply with quote

This is a test of the touch screen attached to this color LCD module.
Drawing is slow to get stable position information.

Controller [XPT2046] Resistive film type (4-wire compatible) touch screen 12bit ADC

Circuit diagram
https://drive.google.com/file/d/1jyLzyTsFuXqt9RT3E5fGonA4I1Wcze3w/view?usp=sharing

Video
https://youtu.be/CM_SGaLyvjc


Code:

   '
   '  ***********************************
   '  *  2.8inch 65K full color LCD     *
   '  *    240 x 320 dot [ILI9341] SPI  *
   '  *  Touch screen (XPT2046) test    *
   '  *           O-Family  2019. 9.26  *
   '  ***********************************
   '

$regfile = "m88pdef.dat"                                    'ATmega88P
   Config Clockdiv = 1                                      'Change the AVR operating clock to 8MHz.
$crystal = 8000000

$hwstack = 64
$swstack = 10
$framesize = 24

   '
   '  * Initial setting of G-LCD *
   '
   Const Portrait = 1                                       'LCD screen. (0: Landscape [X=320, Y=240], 1: Portrait [X=240, Y=320])
   Const Rotate_180 = 0                                     'LCD screen 180 degree rotation. (0: connector Upper side, 1: connector Lower side)
   Dim Offset256 As Byte                                    'LCD address offset flag. (0:0-255 , 1:256-319)
$lib "glcd-ILI9341_2R8_240x320.lib"                         'Incorporate the ILI9341 2.8inch 240x320 library.
   ' Designate the connection port of LCD. Cs1 = [CS] , Rst = [RESET] , A0 = [DC] , Si = [SDI] , Sclk = [SCK]
   Config Graphlcd = Color , Cs1 = Portd.3 , Rst = Portd.4 , A0 = Portd.5 , Si = Portd.6 , Sclk = Portd.7       '[Cs1] and [Rst] are optional.
   Initlcd                                                  'Initialize ILI9341.
   Cls                                                      'Erase the entire screen of the G-LCD.

   '
   '  * Define the color name *  [RRRG_GGBB] = [R2,R1,R0,G2_G1,G0,B1,B0]
   '
   Const Black = &B0000_0000
   Const Red = &B1110_0000
   Const Green = &B0001_1100
   Const Blue = &B0000_0011
   Const Magenta = &B1110_0011
   Const Yellow = &B1111_1100
   Const Cyan = &B0001_1111
   Const White = &B1111_1111
   '
   Const Orange = &B1111_0100
   Const Brightgreen = &B0011_1110
   Const Brightblue = &B0001_1111
   Const Darkred = &B1100_0000
   Const Darkgreen = &B0001_0100
   Const Darkblue = &B0000_0010

'--------------------------------------------------------------------------------------------------

   '
   '  * Touch screen controller settings *   (XPT2046 , ADS7846 , TSC2046 , AK4182A)
   '
   Touch_clk Alias Portd.7                                  'XPT2046 [Touch_CLK] Connection port.
   Touch_cs Alias Portd.2                                   'XPT2046 [Touch_CS] Connection port.
   Touch_din Alias Portd.6                                  'XPT2046 [Touch_DIN] Connection port.
   Touch_do Alias Pind.1                                    'XPT2046 [Touch_DO] Connection port.
   Touch_irq Alias Pind.0                                   'XPT2046 [Touch_IRQ] Connection port.
   '
   Config Touch_clk = Output                                'XPT2046 Set the connection port of [Touch_CLK] to output.
   Config Touch_cs = Output                                 'XPT2046 Set the connection port of [Touch_CS] to output.
   Set Touch_cs                                             'XPT2046 Set [Touch_CS] to [H].
   Config Touch_din = Output                                'XPT2046 Set the connection port of [Touch_DIN] to output.
   Config Touch_do = Input                                  'XPT2046 Set the connection port of [Touch_DO] to input.
   Config Touch_irq = Input                                 'XPT2046 Set the connection port of [Touch_IRQ] to input.
   '
   Dim Touchx As Word                                       '[X] data of touch screen.
   Dim Touchy As Word                                       '[Y] data of touch screen.
   Dim Touchflag As Byte                                    'Touch screen detection flag.
   Dim Temptclk As Byte                                     '[Touch_CLK] for port state storage.
   Dim X_command As Byte , Y_command As Byte : X_command = &B1101_0000 : Y_command = &B1001_0000       'XPT2046 A/D measurement start command.
   '
   Temptclk = Touch_clk                                     'Save the status of the [Touch_CLK] port.
   Reset Touch_cs                                           'Set [Touch_CS] of XPT2046 to [L].
   Shiftout Touch_din , Touch_clk , X_command , 1           'Send the touch controller setting command.
   Set Touch_cs                                             'Set [Touch_CS] of XPT2046 to [H].
   Touch_clk = Temptclk                                     'Return the state of [Touch_CLK] port.
   '
   Dim Touchxmin As Word : Touchxmin = 300                  'Minimum specified value of [X]. (Adjustment is required due to individual differences in touch screen)
   Dim Touchxmax As Word : Touchxmax = 3800                 'Maximum specified value of [X]. (Adjustment is required due to individual differences in touch screen)
   Dim Touchymin As Word : Touchymin = 400                  'Minimum specified value of [Y]. (Adjustment is required due to individual differences in touch screen)
   Dim Touchymax As Word : Touchymax = 3900                 'Maximum specified value of [Y]. (Adjustment is required due to individual differences in touch screen)


'--------------------------------------------------------------------------------------------------

   '
   '  ****************
   '  * Drawing test *
   '  ****************
   '
   Dim Coefficientx As Word , Coefficienty As Word          'Screen position factor for [X] and [Y].
   Dim Temp1 As Byte                                        'General-purpose temporary variable.
   Dim Temp2 As Byte                                        'General-purpose temporary variable.
   Dim Tempw1 As Word                                       'General-purpose temporary variable.
   Dim Tempw2 As Word                                       'General-purpose temporary variable.
   Dim Tempdw1 As Dword                                     'General-purpose temporary variable.
   Dim Tempstr As String * 10                               'General-purpose temporary variable.
   '
   '
Main:
   Tempw1 = Touchxmax - Touchxmin                           'Calculate the A/D value range of [X].
   Tempdw1 = 2400000 / Tempw1                               '[X](240dot * 10000) / [X]A/D value range
   Coefficientx = Tempdw1                                   'Find the screen position coefficient of [X].
   Tempw1 = Touchymax - Touchymin                           'Calculate the A/D value range of [Y].
   Tempdw1 = 3200000 / Tempw1                               '[Y](320dot * 10000) / [Y]A/D value range
   Coefficienty = Tempdw1                                   'Find the screen position coefficient of [Y].
   '
   Cls                                                      'Erase the entire screen of the G-LCD.
   Setfont Color8x8                                         'Select a font.
   Offset256 = 0                                            'LCD address offset value. (0: 0-255)
   Box(0 , 0) -(239 , 255) , White                          'Display area frame.
   Offset256 = 1                                            'LCD address offset value. (1: 256-319)
   Box(0 , 256) -(239 , 319) , Red                          'Display area frame.
   Offset256 = 0                                            'LCD address offset value. (0: 0-255)
   Boxfill(229 , 0) -(239 , 10) , Yellow                    'Erase area frame.
   '
Mainloop:
   Gosub Touchget                                           'Touch screen controller reading.
   If Touchflag <> 0 Then                                   'Did you touch the screen?
      Touchflag = 0
      '
      Tempstr = Str(touchx)                                 'Displays the A/D coordinate value of [X].
      Lcdat 100 , 90 , "X: " ; Format(tempstr , "   0") , White , Blue
      Tempstr = Str(touchy)                                 'Displays the A/D coordinate value of [Y].
      Lcdat 120 , 90 , "Y: " ; Format(tempstr , "   0") , White , Blue
      '
      Tempw1 = Touchx - Touchxmin                           'The screen coordinates of [X] are calculated from the A/D value and coefficient of [X].
      Tempdw1 = Coefficientx * Tempw1
      Tempdw1 = Tempdw1 / 10000
      Temp1 = Tempdw1
      Temp1 = 239 - Temp1                                   'The [X] axis is corrected because the left and right addresses are reversed.
      '
      Tempw2 = Touchy - Touchymin                           'The screen coordinates of [Y] are calculated from the A/D value and coefficient of [Y].
      Tempdw1 = Coefficienty * Tempw2
      Tempdw1 = Tempdw1 / 10000
      Tempw2 = Tempdw1
      Temp2 = Tempw2
      '
      If Temp1 > 229 And Tempw2 < 10 Then Goto Main         'Is the screen erase area?
      If Tempw2 < 256 Then                                  'Is [Y] coordinate within 255?
         Offset256 = 0
      Else                                                  '[Y] Coordinate exceeds 255.
         Offset256 = 1
      End If
      If Temp1 > 238 Then                                   'Does [X] circle drawing exceed the screen?
         Temp1 = 238
      End If
      Circle(temp1 , Temp2) , 2 , Green                     'Draw a circle at the touched location.
      Offset256 = 0
      '
'      Waitms 1                                             'The waiting time for continuous drawing.
   End If
   Goto Mainloop


'--------------------------------------------------------------------------------------------------

   '
   '  **************************************************
   '  * Reading subroutine for touch screen controller *  (Touchx = A/D value of [X] , Touchy = A/D value of [Y])
   '  *     (XPT2046 , ADS7846 , TSC2046 , AK4182A)    *  (Touchflag = Touch detection flag, 1: Detected)
   '  **************************************************
   '
   Dim Touch_mean As Byte , Touchx_sum As Word , Touchy_sum As Word

Touchget:
   If Touch_irq = 0 Then                                    'Did you touch the screen [Touch_IRQ]=[L]?
      Temptclk = Touch_clk                                  'Save the status of the [Touch_CLK] port.
      '
      Touchx_sum = 0                                        'Initialize the average sum.
      Touchy_sum = 0
      '
      For Touch_mean = 1 To 16                              'Sample the A/D value of the touch screen 16 times.
         Waitus 30                                          'A/D value stabilization wait time.
         Reset Touch_clk                                    'Set [Touch_CLK] to [L].
         Reset Touch_din                                    'Set [Touch_DIN] to [L].
         Reset Touch_cs                                     'Set [Touch_CS] to [L].
         '
         Shiftout Touch_din , Touch_clk , X_command , 1 , 8 , 2       'Send [X] A/D start command.
         Reset Touch_din                                    'Set [Touch_DIN] to [L].
         Set Touch_clk                                      'Set [Touch_CLK] to [H].
         Waitus 2                                           'Make a 9th clock pulse.
         Reset Touch_clk                                    'Set [Touch_CLK] to [L].
         Waitus 2
         '
         Shiftin Touch_do , Touch_clk , Touchx , 1 , 12 , 2 'Receive A/D data of [X].
         Shift Touchx , Right , 4                           'Set right-justified 12bit.
         '
         Shiftout Touch_din , Touch_clk , Y_command , 1 , 8 , 2       'Send [Y] A/D start command.
         Reset Touch_din                                    'Set [Touch_DIN] to [L].
         Set Touch_clk                                      'Set [Touch_CLK] to [H].
         Waitus 2                                           'Make a 9th clock pulse.
         Reset Touch_clk                                    'Set [Touch_CLK] to [L].
         Waitus 2
         '
         Shiftin Touch_do , Touch_clk , Touchy , 1 , 12 , 2 'Receive A/D data of [Y].
         Shift Touchy , Right , 4                           'Set right-justified 12bit.
         '
         Set Touch_cs                                       'Set [Touch_CS] to [H].
         '
         Touchx_sum = Touchx_sum + Touchx                   'Add the average sum.
         Touchy_sum = Touchy_sum + Touchy
      Next Touch_mean
      Touch_clk = Temptclk                                  'Return the state of [Touch_CLK] port.
      '
      Shift Touchx_sum , Right , 4                          'Take the average of [X] values.
      Touchx = Touchx_sum
      Shift Touchy_sum , Right , 4                          'Take the average of [Y] values.
      Touchy = Touchy_sum
      '
      If Touchx > Touchxmin Then                            'Is the [X] value greater than the minimum specified value?
         If Touchx < Touchxmax Then                         'Is the [X] value smaller than the maximum specified value?
            If Touchy > Touchymin Then                      'Is the [Y] value greater than the minimum specified value?
               If Touchy < Touchymax Then                   'Is the [Y] value smaller than the maximum specified value?
                  Touchflag = 1                             'Set the touch screen detection flag.
               End If
            End If
         End If
      End If
   End If
   Return


   End

'--------------------------------------------------------------------------------------------------

   '
   '  * Font data *
   '
$include "color8x8.font"
 
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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