Problems with MikroC programming in SPI for LCD display

Jay23

Newbie level 6
Joined
Oct 14, 2013
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,485
Hi All,
I am trying to port my MikroC code written for 20x2 character lcd to a Newhaven 20x2 lcd display.
My working code was written a 4.bit parallel generic lcd using 4 signals and now I want to port this code to work SPI on a Newhaven display.
I hope someone can help me fix this problem.
I am using PIC16F886@4Mhxz.
 

Attachments

  • NHD-0220D3Z-NSW-BBW-V3(2).pdf
    1.3 MB · Views: 6
  • Spivakten8.txt
    11.9 KB · Views: 7

I don't have MikroC but it looks like all you have to do is replace (or rename) your LCD commands with ones sending the data by SPI. To help further we need to know which pins you have assigned as the SPI data, clock and enable lines. Mikro may already have SPI libraries, if not, it is very simple to toggle the clock line and shift the bits out one by one.

Brian.
 

Hi Brian,
The SPI pins are SPI_CLK @RC3 //Clock
SPI_SDI@RC4 //Data IN
SPI_SDO@RC5 //Data out
SPI_SS@RA5 //Chip select
Regards,Jay
 

What exatly IS the problem?

Compiler? --> show the error messages
Does not work? --> provide information about how you tested it

Klaus
 

Hi Klaus,
The problem is porting the lcd syntax into SPI syntax.
//Jay
--- Updated ---

Like what is the: Lcd_Cmd(_LCD_CLEAR); // Clear display
What is Lcd_Cmd for SPI?
 

What is Lcd_Cmd for SPI?
You probably have to write your own, it is very easy. SPI is one of the simplest protocols, it is just putting the bit on the SDO pin then toggling the CLK pin. Put it in a loop like this:
1. make SS low to mark the start of the byte,
2. make the CLK pin low,
3. put the data bit on the SDO pin,
4. make SCK high to latch the data bit,
5. repeat from step 2 until all the bits are shifted (typically in a loop of 8 times, one for each bit of the byte),
6. make SS high to mark the end of the byte.

The data bits are sent one by one so you need to shift them or isolate the bit from the byte but you can do that in the loop very easily. The actual bytes are exactly the same as Lcd_Cmd() uses.

Brian.
 

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…