CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ST7070 SPI LCD Hello World - Help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
microJuan



Joined: 08 Mar 2008
Posts: 6

View user's profile Send private message

ST7070 SPI LCD Hello World - Help
PostPosted: Sun Apr 03, 2016 10:53 pm     Reply with quote

G'day folks,

I normally use a serial LCD and can get away with printf and cout commands with no problem. However, recently I acquired an SPI LCD and although it accepts the normal 8/4 bit interface, I am only able to use SPI as my microcontroller has the other pins used up already. I have been trying to read the datasheet and wiring up a vero board circuit without much luck. My code is below, has anyone played with any of these LCDs and able to help out with what I'm doing wrong. Thanks very much.

Datasheet can be found here:

http://www.melt.com.ru/docs/ST7070V1.4.pdf

Code:

#include <16F88.h>

//#fuses NOWDT, NOPROTECT, NOLVP, INTRC, NOPUT, NOWRT, NODEBUG, NOMCLR, NOBROWNOUT, NOPROTECT,NOCPD, NOWRT, NODEBUG
#fuses NOWDT, NOPROTECT, NOLVP, HS, NOPUT, NOWRT, NODEBUG, NOMCLR, NOBROWNOUT, NOPROTECT,NOCPD, NOWRT, NODEBUG

#use delay(clock=16000000)


//#use spi(FORCE_HW, BITS=16, stream=SPI_STREAM) // uses hardware SPI and gives this stream the name SPI_STREAM

#use spi(MASTER, DI=PIN_B1, DO=PIN_B2, CLK=PIN_B5, BITS=8)  // uses software SPI




#define Led_PIN       PIN_B0

#define CS_PIN        PIN_B3

void main()
{
   
   int loop = 0; 

   output_low(Led_PIN);
   output_high(CS_PIN);
   
   for (loop = 0; loop <50; loop++)
   {
      output_toggle(Led_PIN);
      delay_ms(50);
   }
   delay_ms(500);   // wait for LCD to boot up
       
//   output_high(Led_PIN);
     
   while(1)
      {     
         output_low(CS_PIN);
         
         spi_write(0x254);     
         delay_us(60);
       
         spi_write(0x1);
         delay_us(60);
         
         
         
         spi_write(0x68);
         delay_us(60);
         
         spi_write(0x65);
         delay_us(60);
       
         spi_write(0x6C);
         delay_us(60);
         
         spi_write(0x6C);
         delay_us(60);
         
         spi_write(0x6F);
         delay_us(60);
         
         spi_write(0x21);
         delay_us(60);
                   
         
         output_high(CS_PIN);
         
         delay_ms(1000);
         
         
         
      }//end While
 
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sun Apr 03, 2016 11:52 pm     Reply with quote

This is a classic 'read the manual' one, and don't make assumptions.....

There are two different ways of handling SPI with CCS.

The older only uses hardware SPI, and uses spi_setup, spi_read and spi_write. Look at the manual for any of these functions, and it will only refer you to the others from this list.
The latter one supports software or hardware spi, and uses #use spi, and spi_xfer. Again the manual for each of these only refers to the other functions for this way of working.

Unfortunately, people don't look at the 'related commands' part of the manual, and start trying to mix the two ways of working. Sometimes parts of this will work (if you happen to be actually using the hardware), but it is wrong, and to use software SPI won't work.

You need to specify a mode number for your SPI transfers. Your chip expects clock to idle high, change data on the falling edges, and to send data on the rising edge of the clock. This is SPI mode 2.
Code:

#use spi(MASTER, DI=PIN_B1, DO=PIN_B2, CLK=PIN_B5, BITS=8, MODE=2)  // uses software SPI

Then to send a byte:
Code:

spi_xfer(xx);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group