Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Display TFT ST7789 (OshonSoft Basic).

DogFlu66

Member
I leave the library to use ST7789 TFT display, I have translated one that is in C language. But unfortunately I have not been able to get it to work yet. I leave the files in case someone with more experience with these displays can review it.
 

Attachments

  • Main_ST7789.bas
    1.5 KB · Views: 227
  • ST7789_240X240.bas
    15 KB · Views: 198
  • _SPI_Library.bas
    6 KB · Views: 206
  • _Pic18F26K22Library.bas
    46.4 KB · Views: 195
  • _SetUpAmicus18.bas
    2.9 KB · Views: 187
Hi C, here’s a description of the PIC18F16K22 fuses:

' Fuse Configuration:
' Crystal 10 MHz x 4 PLL = 40 MHz, MCLR = On (External Reset)
#define CONFIG1L = 0x00 ' Configuration bits for oscillator and memory settings
#define CONFIG1H = 0x33 ' External oscillator with PLL enabled
#define CONFIG2L = 0x1E ' Brown-out reset and power-up timer enabled
#define CONFIG2H = 0x3C ' Watchdog timer settings
#define CONFIG3L = 0x00 ' Low-voltage programming disabled
#define CONFIG3H = 0xBD ' Port configuration settings
#define CONFIG4L = 0x80 ' Stack overflow/underflow reset enabled
#define CONFIG4H = 0x00 ' Reserved bits
#define CONFIG5L = 0x0F ' Code protection settings
#define CONFIG5H = 0xC0 ' Data EEPROM code protection
#define CONFIG6L = 0x0F ' Write protection settings
#define CONFIG6H = 0xE0 ' Configuration protection bits
#define CONFIG7L = 0x0F ' Boot block protection enabled
#define CONFIG7H = 0x40 ' Configuration settings for block protection

I usually stick to the default configuration, only adjusting the settings related to the oscillator (type and frequency in MHz). I ensure that options capable of generating a reset to the microcontroller are disabled, which is typically the default setting.

During project development, I find this initial configuration to be the most stable. Once the project is complete, I adjust the settings based on the environment where it will be installed. These adjustments are rarely critical because I incorporate various protections into the PCB, such as anti-parasitic suppressors, a high-quality power supply, proper component placement, ground planes, and so on.

If you ask me what CONFIGS 2L, 2H, 3L, and 3H are, I don’t usually take the time to analyze them. I just go into the fuse configuration window and enable or disable the options I’m interested in. Remember, in this window, the fuses are listed by description rather than by numbers. Also, every time you change a value in the fuse configuration window, the corresponding configuration word at the bottom updates and shows its value in hexadecimal format.



Const ST77XX_NOP = 0x00 ' No operation
Const ST77XX_SWRESET = 0x01 ' Software reset
Const ST77XX_RDDID = 0x04 ' Read display ID
Const ST77XX_RDDST = 0x09 ' Read display status

and some looks like this, so there's some confusion.
Const ILI9341_NOP = 0x00
Const ILI9341_SWRESET = 0x01
Const ILI9341_RDDID = 0x04
Const ILI9341_RDDST = 0x09

Initially, we used a TFT with the ST77xx controller, but after all the testing we’ve done, we’ve found that the configuration is almost identical to the ILI93xx. Therefore, our goal is to publish a generic library compatible with both TFT controllers. Remember that names are not important, what is important is that the value is the same.
Once the library is finished, it is more appropriate to change them to this more generic form:

Const LCD_NOP = 0x00 ' No operation
Const LCD_SWRESET = 0x01 ' Software reset
Const LCD_RDDID = 0x04 ' Read display ID
Const LCD_RDDST = 0x09 ' Read display status
Hi D,
OK.
Ian and I have 18F46K20 PICs.

I see that your CONFIGS (Are these fuses?) are different from the CODE you posted, so you are a bit more advanced that I am.

If I can suggest that you use as few lines as possible so us slow ones can keep up, please.

I also noticed that the CONSTANTS names were identical ,so I changed them, and here they are, to save you typing :)
C.
Code:
Const LCD_NOP = 0x00
Const LCD_SWRESET = 0x01
Const LCD_RDDID = 0x04
Const LCD_RDDST = 0x09

Const LCD_SLPIN = 0x10
Const LCD_SLPOUT = 0x11
Const LCD_PTLON = 0x12
Const LCD_NORON = 0x13

Const LCD_INVOFF = 0x20
Const LCD_INVON = 0x21
Const LCD_DISPOFF = 0x28
Const LCD_DISPON = 0x29
Const LCD_CASET = 0x2a
Const LCD_RASET = 0x2b
Const LCD_RAMWR = 0x2c
Const LCD_RAMRD = 0x2e

Const LCD_PTLAR = 0x30
Const LCD_COLMOD = 0x3a
Const LCD_MADCTL = 0x36
Const LCD_DISP_FUNC = 0xB6


Const LCD_MADCTL_MY = 0x80
Const LCD_MADCTL_MX = 0x40
Const LCD_MADCTL_MV = 0x60'20
Const LCD_MADCTL_ML = 0x10
Const LCD_MADCTL_RGB = 0x00

Const LCD_RDID1 = 0xda
Const LCD_RDID2 = 0xdb
Const LCD_RDID3 = 0xdc
Const LCD_RDID4 = 0xdd


Const LCD_BLACK = 0x0000
Const LCD_RED = 0x001f
Const LCD_BLUE = 0xf800
Const LCD_GREEN = 0x07E0
Const LCD_YELLOW = 0x07ff
Const LCD_MAGENTA = 0xf81f
Const LCD_CYAN = 0xffe0
Const LCD_WHITE = 0xffff
 
After MANY attempts I cannot get this LCD working on this board.

I fear the pic18f46k20 isn't good.. I have ordered one and I'll make a little circuit to mimick yours.

I'll let you know how I get on.
 
After MANY attempts I cannot get this LCD working on this board.

I fear the pic18f46k20 isn't good.. I have ordered one and I'll make a little circuit to mimick yours.

I'll let you know how I get on.
Hi I,
I can't remember if I tested it or not, but I'd be surprised if I didn't!

Anyway:
Is the screen lighting up?
Is the LED flashing, at the beginning, and in the LOOP?
Have you tried removing the PICKIT3?

If all these fail, then send it back, and I'll swap the PIC. I'll PM my address.

EDIT: Lastly, try RESET by shorting the MCLR pin to GND.
C.
PCB9.jpg
 
Last edited:
Trust me.. I can not see a clean clock on the SPI.. I am going to build a dummy, USING THE SAME CODE and if it works the chip on the lil board has been hammered by some spurious electrical goul!
 
Back
Top