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: 302
  • ST7789_240X240.bas
    15 KB · Views: 268
  • _SPI_Library.bas
    6 KB · Views: 278
  • _Pic18F26K22Library.bas
    46.4 KB · Views: 263
  • _SetUpAmicus18.bas
    2.9 KB · Views: 256
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.
 
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!
 
I have tested the TFT with a 10 MHz SPI clock and the PIC18F46K20 running with an external 10 MHz crystal and a 4x PLL, and everything works perfectly. It’s worth mentioning that I’m using an HL-K18 prototype board, which usually has extra-long traces. Even though the clock signal is more sinusoidal than square, it still works without issues.
 
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!
Hi I,
Of course I trust you, I remember your Oscilloscope image. I wanted to test if there are differences between your PCB and mine. I've had none working programs that start after a RESET, and I wanted to exoperiment with yours.
C.
 
Hi D,
I'm interested in the differences between our 3x set-ups, starting with Ian's, and mine.
C.
 
Hi C; I have already left the configuration several times but I leave it again for the PIC18F46K20 with the oscillator using an external crystal.

View attachment 148466
Hi D,
Yes, thanks, but for some reason I have difficulty with reading this, and the combinations that make up a CONFIG.

e,g, for my PCB with on board programming, I need the MCLR PIN enabled, so if I simply switch to your settings, without reading all of the changes, I can get problems, so I need to know accurately if the changes apply to me.
C.
 
Okay... Much observations.. I think there is a problem with the pic18f46k20 series.
I have a dummy board running at 8Mhz --> 32Mhz I run the test program

Pic18f46k20 nada
pic18f46k22 runs fine... Same hardware..

When looking at the clock pulse 50% of the time the clock pulses are missing

In a run of 8 pulses only 5 are seen. Then you get a spurt of perfection, then back to pants.
Same on your lil board. I have tried 2Mhz and 500Khz both show the same.
I have trawled through Vlads asm and there is nothing there.

Giving up now.. Taking far too long.
 
Hi I,
I've spent hours and hours on this little problem, so your tests, verify a common denominator, good!
'My' 3x boards all have the same sourced 18F46K20s, aliexpress. I thought they would be ok as they were on a strip, but of course they could have been in the reject bin, and the person on the disposal team got the idea of flogging them, who knows.
Anyway, I'll order some 18F46K22s from a more reliable source and change them.

If you want to send back the board, I can swap the PIC for you.

EDIT: Bag of chips on order (Microchip)
C.
 
Last edited:
The 3 pic18f46k20's I got were from RS here in England.. I just feel like the low voltage variety just cant cope. If thats the case then none will work with these screens.

I have a SPI memory module here and that works... I aslo have the old pic18f4620 which also works.

I think a buffer on the output may work better. Or run the pic a little higher. Max is 3.6V if you supply 3.6 and see if it works better.

When I first got to grips with these screens I use a pic18f26k80 and I had to power the screen at 5v through its internal reg, then it worked. BTW I had already bridged J1 so 3v3 get to the display
 
Hi I,
I ought to try and cancel my Microchip order, if they will, while we figure something out.

I wonder if the screens can be powered by 5V, but use the existing 3.3V SPI?
C.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…