Interface 2x16 serial LCD to PIC16F767 via SPI

Thread Starter

ash8090

Joined Jul 24, 2017
7
Hello there
I have PIC16F767 and one 2x16 LCD and I want to lat PIC write any thing to the LCD but in vain, and help in sample code for MPLAB XC8?




16F767.png lcd.png
 

shteii01

Joined Feb 19, 2010
4,644
How do we know that you connected lcd correctly?
Does your lcd even have spi capability?

In my limited experience cheap/common 2x16 lcd do not have spi capability.
 

spinnaker

Joined Oct 29, 2009
7,830
How do we know that you connected lcd correctly?
Does your lcd even have spi capability?

In my limited experience cheap/common 2x16 lcd do not have spi capability.

Extremely poor detail in the TS's post but I assume the chart posted is the pinout for the LCD display. Very odd that it would have 20 pins for SPI. What on earth would be the purpose of all of those extra pins.
 

shteii01

Joined Feb 19, 2010
4,644
Extremely poor detail in the TS's post but I assume the chart posted is the pinout for the LCD display. Very odd that it would have 20 pins for SPI. What on earth would be the purpose of all of those extra pins.
I did a quick look on Ebay. They now sell 2 board kit. First board is the regular 40? year old design parallel 8 bit 2x16 lcd. Second board is the i2c/spi to 8 bit parallel translator board. Kinda interesting if you can stack the two boards on top of each other.

At this point I would be tempted to just use 4 bit parallel connection from PIC directly to 2x16 lcd, and skip the expanse and physical addition of the translator board. However, I have no idea about OP requirements, it is possible that they don't have the pins to do the 4 pin parallel connection (4 pins data+enable+RW+reset, that 7 pins vs spi 3 or 4 pins).
 

philba

Joined Aug 17, 2017
959
Take a look at the 240x320 SPI TFT ILI9341 based displays on ebay. I use them with AVRs. They are dirt cheap and work great. 3.3V or 5V versions available. People have adapted the adafruit library for the PIC. From china they are less than $10.
 

Picbuster

Joined Dec 2, 2013
1,047
Hello there
I have PIC16F767 and one 2x16 LCD and I want to lat PIC write any thing to the LCD but in vain, and help in sample code for MPLAB XC8?




View attachment 137461 View attachment 137462
hi,
here are some working routines output only. (Xc8)
Do not forget to set the enable bit before a write. ( normal active low depending on display)
and clear it after.
Picbuster

C:
// -------------------spi bus master  setup------------------
  
CKP=0; //0=idle clock state is low
SSPSTAT.CKE=1; //0=Data transmitted on falling edge of SCK
SSPSTAT.SMP=1; //1=SPI mode-Input data sampled at end of data output time
SSPCON.SSPM3=0; //FOSC/4
SSPCON.SSPM2=0; //FOSC/4
SSPCON.SSPM1=0; //FOSC/64
SSPCON.SSPM0=1; //FOSC/4  1=/16

//SSPIE=1; no need for xmit
  SSPCON.SSPEN=1;   // enable
//----------------------------------------------
PEIE=1;   // Enable peripheral int.
GIE=1;   // Global int. enable




/================  send byte to SPI bus ==============


void Xt_SPI(unsigned char byte)
{
        SSPCON.WCOL=0;  // clear collision bit
       while(SSPSTAT.BF);
        {
        SSPBUF =byte; 
  __delay_us(100);   // wait time depending on pic/SPI & clock chip speed
       } 
}
Moderators note: Please use code tags for pieces of code
 

Thread Starter

ash8090

Joined Jul 24, 2017
7
dear mates,
excuse me for lack of information in my post, this LCD is from HP Laser Jet 4500, I found some good information about it in this link:
https://kbiva.wordpress.com/2012/12/30/hp-laserjet-4500-front-panel/
he interface it with Arduino by the information that I sent in the table, the information say that we are facing a SPI serial LCD, if you see any thing different just tell me, all I want is how to make a simple code that can talk to this LCD by PIC16F767..
Any help

by the way thanks to Picbuster for the code..
 

Attachments

spinnaker

Joined Oct 29, 2009
7,830
dear mates,
excuse me for lack of information in my post, this LCD is from HP Laser Jet 4500, I found some good information about it in this link:
https://kbiva.wordpress.com/2012/12/30/hp-laserjet-4500-front-panel/
he interface it with Arduino by the information that I sent in the table, the information say that we are facing a SPI serial LCD, if you see any thing different just tell me, all I want is how to make a simple code that can talk to this LCD by PIC16F767..
Any help

by the way thanks to Picbuster for the code..

Are you sure you are getting SPI out of the Pic?

That is the first step.
 
Wow, Very Small world. I am about to start my own thread due to my chip being way different than yours but I'll tell you how far I am. If you don't find this relevant then skip over my post as I see your model is different.

https://images-na.ssl-images-amazon.com/images/I/51fDBZV-ebL._SY355_.jpg

The SPI chip is a "Backpack" for the LCD1602 and in and of itself is it's own part completely. The LCD has its own protocol like 4Wire or 8Wire for data. Most people use 4 Wire using the 'E' pin to toggle back and forth to cut up the 4 bits to make the Ascii Char (8bits).

Now the LCD requires this to happen, The Backpack is nothing more than a chip emulating those Pin Logic's High and Low, nothing more.
So if you put a Logic reader or scope on the pins of your LCD you should see the same pins get thrown up and down as if you were to connect to it directly through a microcontroller.

So two thing's, Connecting via SPI is one thing.. Even if you were to talk to SPI you would have to predict the correct Hex values that would then trigger the correct Pin Up's and Down's in the correct order to trigger the LCD to interpret your commands correctly. It is possible the SPI board has some sort of Firmware that will instead of taking straight Pin Hex values just takes string values/commands and takes it from there but if you don't know that then more then likely it wouldn't?

I hope this was helpful but it seems what I would do is get the Datasheet for the product and see if the SPI part is made specifically for the LCD to access string command, It's doubtful but possible.
-Agent
 

philba

Joined Aug 17, 2017
959
SPI is a super simple interface. You can use built in hardware or you can bit-bang it (somewhere in those links they also call it pin toggling). If you have 2 digital pins free you can bit bang it. One pin is for the clock (SCLK) and one for the data (MOSI). Technically, there is data out (MISO) so you'd need another pin but it looks like that isn't needed for the LCD. If using HW SPI with another device, hook up both MISO and MOSI. If you want to share SPI, you'll need to use a Slave Select (SS) pin.

What you need to know is the command codes to send - you can figure that out from the arduino library linked to on that page. Note that the arduino library page has the wrong circuit diagram on it (for a motor driver, weird). Personally, I'd try to move the arduino library over as it has a lot nice features.
 
Top