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.

Touch Panels and Screens

Status
Not open for further replies.
Well, I finally got my PIC18F45K20 and my LCD
LCD1.jpg
It is this one over here
http://www.wvshare.com/product/3.2inch-320x240-Touch-LCD-C.htm

I have been reading a lot of how to program it (I read code for other processors including a STM32, I have now to adapt it to a PIC) while waiting for it to arrive but now that is here, I am nervous like a groom before his wedding :nailbiting::rolleyes: lol...

Anyway, before I start working on this allow me a stupid question:angelic:
I suppose I am going to have to build a custom made connection board for the LCD since the connections are like this

LCD2.jpg
obviously I cant put this on a breaboard :D so I guess I am going to look for a connection socket for this and solder it to a perfboard...


One non stupid question though. In the connections specs it says:

27 BLCNT Backlight brightness adjustment Control the backlight brightness via PWM

ummmm, do I have to control the backlight through PWM?? So far I was thinking to do what I did for my text LCD, which is to put a potentiometer, and to connect the brightness pin to the potentiometer and in that way increase or decrease it.. therefore providing a voltage lower than VCC. Does it have to be PWM??

Any comment, question, welcomed
 
obviously I cant put this on a breaboard :D so I guess I am going to look for a connection socket for this and solder it to a perfboard..

hi KR.
That is a standard 0.1inch connector, you can buy sockets and pins for that pitch.
Use a small piece of perf board to mount the socket, then insert pins in the perf board so that they match your bread board.
You can then insert the display in the socket and the perf board into your bread board.

For the back light it depends upon the internal circuitry of the display, it may not accept DC control, you try it.
If it must be PWM, a simple 555 timer IC can be wired to give PWM

E
 
hi KR.
That is a standard 0.1inch connector, you can buy sockets and pins for that pitch.
Use a small piece of perf board to mount the socket, then insert pins in the perf board so that they match your bread board.
You can then insert the display in the socket and the perf board into your bread board.

For the back light it depends upon the internal circuitry of the display, it may not accept DC control, you try it.
If it must be PWM, a simple 555 timer IC can be wired to give PWM

E

Thank you very much for your reply.

I am reading very quickly about the LM555, can this be used with 3.3V (which is the voltage I am going to be using)??
 
I am reading very quickly about the LM555, can this be used with 3.3V (which is the voltage I am going to be using)??

Use the CMOS version of the 555 ie: 7555 . TLC555, it works down to 2Volts
The LM555 is Vmin of only 4.5v!

E
 

Attachments

  • TLC555.pdf
    316.3 KB · Views: 155
I didn't think you would select a device that has only a 16bit interface I chose one that I could configure...

There are several screens that are SPI ( that would be quick enough )..

Yeah, there was a smaller one that was SPI. I was running out of time, and didn't find another one for that price,:facepalm: I realize a 16 bit interface and not customizable is not the ideal but well I suppose I will start with that. I would be grateful if you keep helping me with your advice and insights:)
 
hi KR.
That is a standard 0.1inch connector, you can buy sockets and pins for that pitch.
Use a small piece of perf board to mount the socket, then insert pins in the perf board so that they match your bread board.
You can then insert the display in the socket and the perf board into your bread board.
E

Hello Eric
I did as you said (well ok, I am in the process of doing-I am that slow soldering:facepalm:) , at least the 5v and 3.3 V parts and it worked well. Now the LCD powers up my PIC, that is still just blinking a LED... On monday I will finish the connections and start programming.

Now two things happened on my way to building this and I would appreciate a comment.
1) First I tried to do this on the usual perfoard I use. This has the holes covered with metal on only one side so, but in this case I am soldering the socket on one side (for the LCD) and the pins on the other side (for the perfboard), so when I tried to solder the pins from the side that had no metal, it was impossible. I couldn't do it.

2) Next, I tried a perfboard with metal on both sides of the holes. And it worked, I could solder the socket on one side and the pins on the other but then I realized something... How am I going to connect the pins of the socket (coming from the LCD) to the pins of the connection pins(for the breadboard)? This because this pins have some plastic on that side so I cant solder them...
So far I have connected only the power pins, so what I did was for each pin, put some wire across a hole near the pin holes, solder them (on the side where it is possible to solder) and then connect the socket pins to this wire since I cant connect it directly to the connection pins.

to give a clear idea:

connection.jpg

Any idea , comment or pointer about this?

Thanks in advance :)
 
so when I tried to solder the pins from the side that had no metal, it was impossible. I couldn't do it.

Hi,
The 0.1 inch pitch pins I use are fixed to a black plastic header strip, I physically push the metal pins into the plastic body until they are flush with the plastic, then I insert the pins into the perf board from the face that has no copper, then solder the pin on the other side of the perf board.
Do you follow that OK.?
I have modified your drawing to show the method.
The pins will slide thru the plastic if you push them hard
E
 

Attachments

  • connection.jpg
    connection.jpg
    16.7 KB · Views: 192
Well, to report , I built a kind messy interface board.:confused: (for several silly reasons, couldnt find appropriate cables, blabla ,disregard that:banghead:) and finally connected the LCD to the 18F45K20. Then I took the sample code provided by the manufacturer (for another micro), analyzed it and rewrote it for the PIC. Then I tried clearing the screen and drawing a rectangle.

Good news: the rectangle got draw successfully.

Bad news: The clear screen function does not work properly. (only a part of the screen got clear)
The drawing is a bit slow (specially for the clear function)

I guess, the slowness is not really a problem since I am running the PIC at default speed which is low (1MHz) and all I need is to speed it up.
Right now I am concerned about the clear function so I am going to reread the ILI9325 datasheet to see what is wrong.

I noticed that all functions (except the clear screen) do the following: write an "index" ( a command I suppose) and then write the data (color for example). Then repeat again if necessary
The clear screen function first write an index, and then enters a for loop with each iteration writing data . Which does not work since it clears only 1/5 of the whole screen...

Also , debug does not work. First of all sometimes delay functions ruin debug, and on top of that, even if I run it in debug mode, the results are different,. The screen becomes really small and the rectangle is not draw. So I stopped using debug...

Will update my findings. :wideyed:
 
Well to no avail.
I read the datasheet, check some source code that I found in obscure parts of the web... and no, they are same as mine. And yet clear function does not work well
LCD3.jpg

As you can see, the rectangle is draw ok, the circle is draw ok but the clear function (the yellow part) is not complete, it just fill a minimum part of the screen

And, I found there are undocumented features that does not appear on the datasheet!.. (some other people have found this too, it seems)

Sigh...
 
Update. I solve the problem:
LCD4.jpg

Theoretically it is very strange though

This code does not work:
Code:
 for(index = 0; index < MAX_X * MAX_Y; index++)
     {
    LCD_WriteData(Color);
     }

But this code does the trick
Code:
 for(x_index = 0; x_index < MAX_X; x_index++)
    {
        for(y_index = 0; y_index < MAX_Y; y_index++)
        {
             LCD_WriteData(Color);
        }
    }

Now, I dont know if I am tired, but they seem equivalent to me....:confused:

Well now, to write more libraries and speed up the micro (cause right now it is sloooow.. although clearing the screen is faster than drawing a full rectangle...
 
although clearing the screen is faster than drawing a full rectangle...
Have you got Bresenham's line algorithm code??? Do a search... There are may ways to optimize line drawing..
Especially straight lines..
 
Haha, really! I didnt even think about it! Thanks for the comments.
I think that I am using Bresenham algorithm to draw empty rectangles,. they are pretty fast. For the full rectangle is just write pixel by pixel

I changed my PIC from 1MHz to 16 MHz (the maximum of the internal oscilator ) and to 64MHz (using the PLL function)
The results are (approx)

clock clearing, drawing a full rect ,an empty rect and a circle
1MHz ---- 2 minutes
16MHz ---10 seconds
64 MHz-- 4 seconds

Well that is quite a difference.!

Thing is, I am afraid that is the max I can go with the internal oscillator...

Any experience running a PIC18 with faster crystal oscillators?? (are there faster ones???
 
How is it connected.. 16 bit interface.... I would expect much faster drawing speeds....A rectangle 320 x 240 should take mS not seconds... If your clear takes mS to do and the rectangle takes seconds... You need to optimize!!
 
Update. I solve the problem:
View attachment 95271
Theoretically it is very strange though

This code does not work:
Code:
 for(index = 0; index < MAX_X * MAX_Y; index++)
     {
    LCD_WriteData(Color);
     }

But this code does the trick
Code:
 for(x_index = 0; x_index < MAX_X; x_index++)
    {
        for(y_index = 0; y_index < MAX_Y; y_index++)
        {
             LCD_WriteData(Color);
        }
    }

Now, I dont know if I am tired, but they seem equivalent to me....:confused:

Well now, to write more libraries and speed up the micro (cause right now it is sloooow.. although clearing the screen is faster than drawing a full rectangle...
I agree with Ian, you should get faster full screen.
Code:
 for(index = 0; index < MAX_X * MAX_Y; index++)
     {
    LCD_WriteData(Color);
     }
When you multiply 2 int and get a number larger than int the code fails.
Try casting:
Code:
unsigned long index;
for(index = 0; index <( unsigned long)MAX_X *( unsigned long) MAX_Y; index++)
Try also this. On my compiler it works much faster maybe because the code does the multiplication only once when the loop starts.
Code:
unsigned long index;
for(index =( unsigned long)MAX_X *( unsigned long) MAX_Y; index >0; index--)
 
Oh, I just checked and the index was indeed a uint32_t, ergo an unsigned long int!
However it just goes till 11264! (0x2C00)

The solution is to cast the product like
Code:
uint32_t product= (uint32_t)MAX_X*MAX_Y;


Well now time to program the rest of functions...
 
Last edited:
When using LCD's you MUST learn to ditch divide and multiply!!

The two methods..
1) Calculate first before looping..
2) Use shifting..

Analyze your "putpixel" routine and get rid of any maths that involve divide or multiply..

"y * 320" ( trying to get the line from a linear memory map. )

y = y<<8 + y<<6; Is hundreds of cycles faster than y = y * 320..
C:
END = (long)XMAX*YMAX;

for(i = 0; i<END;i++)     // <--- no calculation
   LCD_WriteData(color);

There is a guy called David Brackeen who wrote several articles about fast VGA routines

http://www.brackeen.com/vga/basics.html

Extremely good reading!!
 
Hello Again

I am currently implementing the code for the Touch Panel part based on the XPT2046 controller.It uses a SPI interface. It is almost done (I havent tried it yet)
However I just noticed something.
Take a look at the datasheet
https://www.waveshare.com/w/upload/9/98/XPT2046-EN.pdf

You can see there is a PENIRQ output. "Theoretically" this seems to be a "interrupt" pin.

Following the ideas of this thread
https://www.electro-tech-online.com/threads/pic-spi-with-interruptions.145357/

and since SPI is always started by the master, I was thinking of using interruptions so that the LCD can notify the PIC (master) to start transmition whenever it has been touched, through an interruption.
And for this I thought of using the PENIRQ pin, since.. you know... it is supposed to trigger an interrupt.

BUT, then I notice what it says on page 25 of the datasheet
The PENIRQ output is disabled ... during the measurement cycle...

in order to re-enable the pen interrupt output function under these circumstances a control byte needs to be written toi the XPT2046 with PD0=0. If the last control byte written to the XPT2046 contains PD0=0 the pen interrupt output function is enabled at the end of the conversion.

So, I am understanding that the "interruption" is only enabled whenever the master sends a control byte with a PD0= 0 to the slave!!

So, ok the interruption will tell me when the transmission has finished, but what use is this!. How use is this "interruption" if to use the interruption I have to be constantly looping and sending control bytes from the master??
Isnt supposed that interruptions save me from doing these pooling wasteful thing???

Am I understanding this wrong???

Any comment greatly appreciated
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top