ST7735 80x160 LCD Driver by WIFI RDS code

183 views
Skip to first unread message

Liu Palm

unread,
May 5, 2020, 5:16:53 AM5/5/20
to Annex WiFi RDS

Working on this ST7735 80x160 LCD module few days, 

22013383537557_978.jpg

Now success to drive it by WIFI RDS code as:


demo_1.png

This the first step only, need to add the following functions:

1. Font

2. drawing tools (dot, line, rectange , circle ...)

3. load image from file

4. Speed up!!! using "for loop" and "spi.hex$" seems not fast enough, much slower than native code. Here is my code:


' Program Code


D0=16 : D1=5 : D2=4 : D3=0 : D4=2 : D5=14 : D6=12 : D7=13 : D8=15 : D9=3 : D10=1


START:

' H/W init.

  OPTION.CPUFREQ 160

' LCD init.

  DC = D0

  CS = D8

  pin.mode DC,output

  pin.mode CS,output

  pin(CS) = 1

  spi.setup 80000000

  LCD_init

deadloop:

  LCD_test1

  pause 500

  LCD_test2

  pause 500

  LCD_window &h30, &h3f, &h30, &h3f

  LCD_test3

  LCD_window &h50, &h5f, &h40, &h4f

  LCD_test3

  LCD_window &h70, &h7f, &h50, &h5f

  LCD_test3

  pause 500

  goto deadloop

  

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

sub LCD_cmd(x)

  pin(DC) = 0

  pin(CS) = 0

  r=spi.byte(x)

  pin(CS) = 1

end sub


sub LCD_dat(x)

  pin(DC) = 1

  pin(CS) = 0

  r=spi.byte(x)

  pin(CS) = 1

end sub


sub LCD_window(xs, xe, ys, ye)

  LCD_cmd &h2a          ' ST77XX_CASET

  LCD_dat &h00

  LCD_dat xs

  LCD_dat &h00

  LCD_dat xe

  LCD_cmd &h2b          ' ST77XX_RASET

  LCD_dat &h00

  LCD_dat ys

  LCD_dat &h00

  LCD_dat ye

end sub


sub LCD_init

  LCD_cmd &h01          ' SWRESET

  pause 150 

  LCD_cmd &h11          ' SLPOUT

  pause 500

  LCD_cmd &hb1          ' ST7735_FRMCTR1

  LCD_dat &h01

  LCD_dat &h2c

  LCD_dat &h2d

  LCD_cmd &hb2          ' ST7735_FRMCTR2

  LCD_dat &h01

  LCD_dat &h2c

  LCD_dat &h2d

  LCD_cmd &hb3          ' ST7735_FRMCTR3

  LCD_dat &h01

  LCD_dat &h2c

  LCD_dat &h2d

  LCD_dat &h01

  LCD_dat &h2c

  LCD_dat &h2d

  LCD_cmd &hb4          ' ST7735_INVCTR

  LCD_dat &h07

  LCD_cmd &hc0          ' ST7735_PWCTR1

  LCD_dat &ha2

  LCD_dat &h02

  LCD_dat &h84

  LCD_cmd &hc1          ' ST7735_PWCTR2

  LCD_dat &hC5

  LCD_cmd &hc2          ' ST7735_PWCTR3

  LCD_dat &h0a

  LCD_dat &h00

  LCD_cmd &hc3          ' ST7735_PWCTR4

  LCD_dat &h8a

  LCD_dat &h2a

  LCD_cmd &hc4          ' ST7735_PWCTR5

  LCD_dat &h8a

  LCD_dat &hee

  LCD_cmd &hc5          ' ST7735_VMCTR1

  LCD_dat &hee

  LCD_cmd &hc5          ' ST7735_VMCTR1

  LCD_dat &hee

  LCD_cmd &h20          ' ST77XX_INVOFF

  LCD_cmd &h36          ' ST77XX_MADCTL

  LCD_dat &h60

  LCD_cmd &h3a          ' ST77XX_COLMOD

  LCD_dat &h05

  LCD_window &h00, &ha1, &h00, &h69

  LCD_cmd &he0          ' ST7735_GMCTRP1

  LCD_dat &h02

  LCD_dat &h1c

  LCD_dat &h07

  LCD_dat &h12

  LCD_dat &h37

  LCD_dat &h32

  LCD_dat &h29

  LCD_dat &h2d

  LCD_dat &h29

  LCD_dat &h25

  LCD_dat &h2B

  LCD_dat &h39

  LCD_dat &h00

  LCD_dat &h01

  LCD_dat &h03

  LCD_dat &h10

  LCD_cmd &he1          ' ST7735_GMCTRP2

  LCD_dat &h03

  LCD_dat &h1d

  LCD_dat &h07

  LCD_dat &h06

  LCD_dat &h2e

  LCD_dat &h2c

  LCD_dat &h29

  LCD_dat &h2d

  LCD_dat &h2e

  LCD_dat &h2e

  LCD_dat &h37

  LCD_dat &h3f

  LCD_dat &h00

  LCD_dat &h00

  LCD_dat &h02

  LCD_dat &h10

  LCD_cmd &h13          ' NORON

  pause 10

  LCD_cmd &h29          ' DISPON

  pause 100

end sub  


sub LCD_test1

  LCD_window &h00, &ha1, &h00, &h69

  LCD_cmd &h2c          ' RAMWR

  pin(DC) = 1

  pin(CS) = 0

  for i = 1 to 43

    a$ = "008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f008f"

    a$ = a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ 

    b$ = spi.hex$(a$, 800)

  next i    

  pin(CS) = 1

  LCD_cmd &h00          ' NOP

end sub


sub LCD_test2

  LCD_window &h00, &ha1, &h00, &h69

  LCD_cmd &h2c          ' RAMWR

  pin(DC) = 1

  pin(CS) = 0

    for i = 1 to 43

    a$ = "1f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f001f00"

    a$ = a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ 

    b$ = spi.hex$(a$, 800)

  next i    

  pin(CS) = 1

  LCD_cmd &h00          ' NOP

end sub


sub LCD_test3

  LCD_cmd &h2c          ' RAMWR

  pin(DC) = 1

  pin(CS) = 0

  a$ = "e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007e007"

  a$ = a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$ + a$

  B$ = spi.hex$(a$, 512)

  pin(CS) = 1

  LCD_cmd &h00          ' NOP

end sub


cicciocb

unread,
May 5, 2020, 5:44:45 AM5/5/20
to Annex WiFi RDS
Hello Liu,
thanks for your efforts and sharing your code.

Unfortunately the display will be always slow when driven by the basic, compared to implement the functionalities inside the firmware.

I can see if I can implement it removing, for example, the support for another display like the ST7920 for example.

This color display looks interesting as it is very cheap

Dwight

unread,
May 5, 2020, 3:18:43 PM5/5/20
to Annex WiFi RDS
hi Cicciocb,

I have often wondered, as the feature set for Annex grows and starts to be limited by the memory size of the modules, if it would ever be possible (or worth the effort) to allow the user to select from a type of "a la carte" feature set when flashing Annex?

As in your example above where you are faced with having to choose to eliminate support for one device in order to create room for another feature.
If we could just have a check list of hardware devices (displays, sensors, etc) to install at the time of flashing Annex.
This way one could use a 1 meg module and just install the needed device support and still be able to fit in the allowed space.

I realize this would be a lot of programming work to the annex tool kit.

just a thought
thanks for all your efforts
dwight

cicciocb

unread,
May 5, 2020, 3:51:47 PM5/5/20
to Annex WiFi RDS
Dwight,
you are not the first one that raised this point but, unfortunately this is not possible as the code is compiled by the C++ compiler as a batch and cannot be decomposed and assembled as desired.

I already tried in the past to see if it was possible to create a kind of "loadable" modules to be used as libraries but it turned out to be an almost impossible task.

What the toolkit does is simply load the firmware in the module (and create partitions for the ESP32).

So, I understand the point but, unfortunately, this cannot be done.

cicciocb

Liu Palm

unread,
May 6, 2020, 4:14:36 AM5/6/20
to Annex WiFi RDS
For the speed issue, the only "bottle neck" is "spi.hex$". But if not for critical purpose, it should  be acceptable. 

Today I put more effort to make some feature:

1. LCD_dot       : draw a single dot on 160x80 display area with color$
2. LCD_dot2     : draw a 2x2 dot on 80x40 display area with color$
3. LCD_dot4     : draw a 4x4 dot on 40x20 display area with color$
4. LCD_dot8     : draw a 8x8 dot on 20x10 display area with color$
5. LCD_lineH    : draw horizontal line with start pos. , length, width with color$
6. LCD_lineV    : draw vertical line with start pos. , length, width with color$
7. LCD_fill         : fill whole screen with color$
8. LCD_image   : display a bmp (need convert to HEX format, then use "file.read$")

LCD_image.png


Please find attached:

source code : st7735-05.bas

emoji hex     : emoji.hex



emoji.hex
st7735-05.bas

cicciocb

unread,
May 6, 2020, 5:12:54 AM5/6/20
to Annex WiFi RDS
Hi Liu,
it looks that you are enjoying into developing a driver using annex.

I have a new firmware for testing that includes the IOBUFFERS; this should speedup the data transfer.

If you want, I can give you a preliminary release for testing

Liu Palm

unread,
May 7, 2020, 11:48:14 AM5/7/20
to Annex WiFi RDS
Sorry for late reply, Speed up the SPI write is useful, once improved, every SPI interface LCD and OLED can be drriven smoothly. Then no need to builtin driver in Annex. 

cicciocb

unread,
May 7, 2020, 12:21:36 PM5/7/20
to Annex WiFi RDS
OK,
as soon as I'll terminate I'll send you a version to test.
Reply all
Reply to author
Forward
0 new messages