Datasheet
Memory LCD Programming
4 LCD Application Note
SOFTWARE IMPLEMENTATION
This section contains code for interfacing with the
panel. The SPI port should be set up so that when in
the idle state, the serial chip select (SCS) and the serial
clock (SC) are LOW. Data is clocked on the rising edge
of SC. Care should be taken to meet all of the timing
such as Setup and Hold times and SC clock speed as
given in your part’s Specifications.
It is important to note which bit (MSB or LSB) gets
shifted out of the SPI port first. The code in the example
here is written for an ARM Cortex M3 processor which
shifts the MSB out first. Because the memory LCD
expects the LSB first, the bits within each byte need to
be swapped before being sent. This is done using the
“swap” routine.
Also, because the particular processor picked has a
DMA controller, it relieves the processor load of writing
individual bytes. The Cortex DMA unit disables itself
after the transfer is complete, then generates an inter-
rupt using the SPI vector. The SPI interrupt vector
should point to the routine “show_frame”. It is assumed
that when show_frame is called from an interrupt, that
the processor context has already been saved; and
that it will be restored when show_frame exits.
The code can of course be modified if the processor
picked doesn’t have DMA or an SPI port.
// LCD commands - Note: the bits are reversed per the memory LCD data
// sheets because of the order the bits are shifted out in the SPI
// port.
#define MLCD_WR 0x80 //MLCD write line command
#define MLCD_CM 0x20 //MLCD clear memory command
#define MLCD_NO 0x00 //MLCD NOP command (used to switch VCOM)
//LCD resolution
#define MLCD_XRES 400 //pixels per horizontal line
#define MLCD_YRES 240 //pixels per vertical line
#define MLCD_BYTES_LINE MLCD_XRES / 8 //number of bytes in a line
#define MLCD_BUF_SIZE MLCD_YRES * MLCD_BYTES_LINE
//defines the VCOM bit in the command word that goes to the LCD
#define VCOM_HI 0x40
#define VCOM_LO 0x00
static char *frmbufter; //current address of buffer to be displayed
static char locbuf[MLCD_BYTES_LINE + 3]; //local line buffer
static char linenum; //current line number being transmitted
static int stage = 0; //there are 3 stages in transmitting a buffer:
//stage 0: first line (has command in it)
//stage 1: 2nd through last line (no command)
//stage 2: null byte trailer
extern char vcom; //current state of vcom. This should alternate
//between VCOM_HI and VCOM_LO on a 1-30 second
//period.