Justin Ray

Interfacing the LCD on the MCU project board with CSM12C32

Discussion created by Justin Ray on Sep 16, 2006
Latest reply on Sep 21, 2006 by bigmac
All,

I the Freescale project board (PBMCUSLK) and the CSM12C32 development module. The version of the board I have came populated with an 8x2 LCD display. According to the documentation, it is the DMC-50448N. The interface from the MCU to the LCD is via SPI and an HC595 serial-to-parallel shifter.

There's no documentation for the LCD, other than the pin designations in the user's guide and on the schematic. I've managed to piece together enough to use the SPI to write data to the HC595, and I've found the recommended startup sequence for the LCD. But when I hook it up, nothing happens with the LCD.

The SPI connects to the HC595 and the 8-bit output is connected as:

Q0 LCD_D4
Q1 LCD_D5
Q2 LCD_D6
Q3 LCD_D7
Q4 --
Q5 --
Q6 RS
Q7 EN

the R/W* pin on the LCD is tied low (presumably because this is a write-only connection)

I've stepped through the code (see below), and after each SPI write, the expected values show up on the right pins of the LCD. The sequence I'm going for is:

SPI write the Data and the EN low
SPI write the Data and the EN high
SPI write the Data and the EN low

This should cause the LCD controller to pick up the nibble. But nothing happens with the LCD.

I've looked all over for more documentation, and I haven't found anything. My code is below. If someone has any tips, or can point me to an application note or other documentation for the LCD on the project board, I would be greatful.


#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12c32"


#define EN_BIT 0x80

void spiWrite(volatile unsigned char data);
void LCDShortWrite(volatile unsigned char data);
void sleep(unsigned long ms);


void main(void) {

EnableInterrupts;

//set up SPI to write to LCD
//01011110
SPICR1 = 0x5E;
//00010000
SPICR2 = 0x10;
//baud rate = 8 MHz / 640 = 12.5 KHz
//0100 0110
//baud rate = 8 MHz / 8 = 1 MHz
//0111 0000
SPIBR = 0x70;

LCDShortWrite(0x03);
sleep(5);
LCDShortWrite(0x03);
sleep(1);
LCDShortWrite(0x03);
LCDShortWrite(0x02);
//LCDShortWrite(0x08);
//set N and F
LCDShortWrite(0x02);
LCDShortWrite(0x08);
sleep(1);
//set Display OFF
LCDShortWrite(0x00);
LCDShortWrite(0x08);
sleep(1);
//set clear display
LCDShortWrite(0x00);
LCDShortWrite(0x01);
sleep(16);
//set entry mode
LCDShortWrite(0x00);
LCDShortWrite(0x06);
sleep(1);
//set display on (w / cursor and blink)
LCDShortWrite(0x00);
LCDShortWrite(0x0F);

for(;:smileywink: {} /* wait forever */
/* please make sure that you never leave this function */
}

void LCDShortWrite(volatile unsigned char data) {
//unsigned char newdata;

//spiWrite(0x00); //clear en
spiWrite(data & ~EN_BIT);

spiWrite(data | EN_BIT); //set en and data

spiWrite(data & ~EN_BIT); //clear the high bit but leave the data

}

void spiWrite(volatile unsigned char data) {
// unsigned char readval;

while (!(SPISR & 0x20)) { } //wait for SPTEF = 1
SPIDR = data; //write value to data reg

//to receive
//while (!(SPISR & 0x80)) { } //wait for SPIF = 1
//readval = SPIDR; // read value

}

void sleep(unsigned long ms) {
char i;

for (i=0;i
asm {
PSHX
LDX #$640
sleepLoop:
NOP
NOP
DBNE X, sleepLoop
PULX
}
}

}

Outcomes