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: 189
  • ST7789_240X240.bas
    15 KB · Views: 171
  • _SPI_Library.bas
    6 KB · Views: 185
  • _Pic18F26K22Library.bas
    46.4 KB · Views: 174
  • _SetUpAmicus18.bas
    2.9 KB · Views: 161
Hi Cam.. Looking at your code... a) RASET and CASET have to be set before writes

RASET and CASET are byte only for some reason you have 360 in both?

if you use X1 and Y1 as a word you cam use x1.HB and x1.LB then the RASET will initialise properly
Hi I,
Yes, RASET confused me, in the CODE it's PASET, no RASET?
I have Call SPI_sendcmd(ST77XX_RASET) //Row addr set ? ] commented out, I can't remember if I changed it to get it to compile?
C
 
There is no need to set the column address and row address in the init.

Just remember... RASET and CASET has two WORD parameters... two sets of high and low. ( 4 bytes in total)

if you need to plot a point only x1 and y1 are needed.. If you set a window the pixels are automatically drawn within the window.

I will use window when I draw characters as the will be x pixels wide and y pixels high.
 
Hi I,
I just used your CODE within mine, and much of this didn't compile?

---------------------------------------------
If x >= width Then
x=x0
y = y + size
If(y>=height)Break;//
LCD_ShowChar(x,y,*P,size,1);
x+=size/2;
P++;
Wend
-------------------------
C
 
The post in #81 is working here.. BUT!! I'm on a pic18f46k22 so there will be slight differences..

The video shows that code running.. I almost always show skeletal code. I then beef up with error checking and comments..
 
The post in #81 is working here.. BUT!! I'm on a pic18f46k22 so there will be slight differences..

The video shows that code running.. I almost always show skeletal code. I then beef up with error checking and comments..
Hi I,
Yes, well done.
I'll just keep trying, and look for the differences, or use my OSC and SPI set up.
I'll also recheck my wiring. I could add a digital anayliser to see what the SPI is doing.
C.
 
the SPI init is DEAD simple.... SSPSTAT and SSPCON1...

TRISC = 0x0 // until i do read
SSPSTAT = 0x40 // bit 6 is CKE which is on
SSPCON1 = 0x31 // SPEN on CPK on and fosc /16

I can only get it to read in mode 3.. However! Datasheet said the LCD runs in mode 0..

mode 0 is cke and cpk = 0. sspstat = 0 sspcon1 = 0x11
 
the SPI init is DEAD simple.... SSPSTAT and SSPCON1...

TRISC = 0x0 // until i do read
SSPSTAT = 0x40 // bit 6 is CKE which is on
SSPCON1 = 0x31 // SPEN on CPK on and fosc /16

I can only get it to read in mode 3.. However! Datasheet said the LCD runs in mode 0..

mode 0 is cke and cpk = 0. sspstat = 0 sspcon1 = 0x11
Hi I,
I'll bear this in mind!
Regarding the LED connection on the screen. How do you switch it?
C
 
Mine just has a wire to 3V as there is a current limit resistor on mine... To be safe

the circuit on mine has a 1k into a NPN with a 3R9 to ground.. so a 3v supply will turn it on.

If your screen is white, then its working or you wouldn't see anything.. If it was initializing the screen would have a random mess all over the screen until you clear it.
 
Mine just has a wire to 3V as there is a current limit resistor on mine... To be safe

the circuit on mine has a 1k into a NPN with a 3R9 to ground.. so a 3v supply will turn it on.

If your screen is white, then its working or you wouldn't see anything.. If it was initializing the screen would have a random mess all over the screen until you clear it.
Hi I,
Mine has a 3.3v rack, that I switch on, and it goes white, then it goes messy as you say. This is with my set up, but I'm trying your OSC at the moment.

I always have trouble with SDO and SDI! Is the TFT_SDI MOSI or MISO (Master Out Save In)?

EDIT: I think I've figured out SDO on the screen TFT_SDO = MISO
C
 
Last edited:
SPI... Pin 3 is clk.. Pin 5 is SD0 (data to the LCD ) .. Pin 4 comes later SDI ( data from the LCD )

Micro SDO pin 5 ____ LCD pin6 MOSI (SDI)
Micro SDI pin 4 ____ LCD pin9 MISO (SDO)

One other thing... may be important. Some of these initialize wrong so you may need to try rotation.

the MADCTL does this.... MY up'ends the rows.. MV up'ends the columns MV exchanges them.
ML up'ends the vertical refresh, MH up'ends the Horizontal refresh .. Up'ends is my way of saying it draws the pixels backwards..
_________________________________________
| MY | MX | MV | ML | BGR | MH | X | X | // 0x36

I set mine to 0x8 as the colors are inverted

Swap the 0x8 in my code to 0x48..

if it don't work swap it back... Funnily enough the code I pinched had 0x48 in the init.
 
SPI... Pin 3 is clk.. Pin 5 is SD0 (data to the LCD ) .. Pin 4 comes later SDI ( data from the LCD )

Micro SDO pin 5 ____ LCD pin6 MOSI (SDI)
Micro SDI pin 4 ____ LCD pin9 MISO (SDO)

One other thing... may be important. Some of these initialize wrong so you may need to try rotation.

the MADCTL does this.... MY up'ends the rows.. MV up'ends the columns MV exchanges them.
ML up'ends the vertical refresh, MH up'ends the Horizontal refresh .. Up'ends is my way of saying it draws the pixels backwards..
_________________________________________
| MY | MX | MV | ML | BGR | MH | X | X | // 0x36

I set mine to 0x8 as the colors are inverted

Swap the 0x8 in my code to 0x48..

if it don't work swap it back... Funnily enough the code I pinched had 0x48 in the init.
Hi I,
Thanks.
I have added a digital analyser, and it's showing the CLK is not equal 'ticks'. This is happening even with any of my old 'other' programs too. I'll have to sort this out first.
C
 
Sorry about my absence, but I was in Edinburgh last week.. Mini hiliday.

I need to email Vlad as there doesn't seem to be a "large table" function.

I remember now, this is where I fell last time! I need to store the character set in ROM, but messing with lookup or CONST is a bad way forward.. I could lob an ASM table lookup into the code, but that doesn't help you.
 
Sorry about my absence, but I was in Edinburgh last week.. Mini hiliday.

I need to email Vlad as there doesn't seem to be a "large table" function.

I remember now, this is where I fell last time! I need to store the character set in ROM, but messing with lookup or CONST is a bad way forward.. I could lob an ASM table lookup into the code, but that doesn't help you.
Hi I,
If you mean me, If it's easier for you, then add ASM. I've used ASM before when this happened previously.
C.
 
I also had the same problem, let's see if this solution allows you to continue, I leave the file.
Hi D,
I think you are referring to Ian, as my lack of ability, means I can't keep up.
I am only able to use programs when they are working or just need a little coaxing.
When you are both happy with your system will you post all of it in one post please?
I can see that you're both making interesting CODE, thanks.
C
 
Hi C.. We haven't got oodles of resources... That is why I'm concerned that a font set will take up too much space.

an 8 x 8 font has 127 characters. 1 k of memory.. BUT!! its so small on a TFT LCD you'll only just be able to read it.. So a double size height 16 x 16 takes 4k of code space.. Again a small font but readable.

The fonts I use on a 128 x128 screen are 8x8... 12 x 16 and 24 x 33 so forget the 8x8 unless you have 20:20 vision. 24 x 33 will be 12.5k + the 4k for the nearly readable..

Now factor in the lookup tables 25 bytes per lookup .. that another 4k per font.. 24k for just two fonts..
Now we could just resize fonts but at 24x24 they will look like 8bit graphics.

If I could create a large table it minimizes the code space..
First I will create a font using lookups and print something on screen.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top