SO FAR I HAVE TRIED EVERYTHING, FOLLOWED THE DATA SHEET AND LOOKED OVER THE CRYSTALFONTZ C++ TEST APP.....NO LUCK!! I AM SURE IT'S SOMETHING STUPID THAT I AM MISSING IN MY DRIVER.
THE FOLLOWING IS MY DRIVER WRITTEN FOR A PIC18 uCONTROLLER USING THE CCS C COMPILER:
/////////////////////////////////////////////////////////////////////////
//// ////
//// ////
//// This file contains drivers for using a CrystalFontz CFAG14432B ////
//// that uses a ST7920 display controller. The CFAG14432B is 144 by ////
//// 32 pixels. ////
//// The driver treats the upper left pixel as (0,0). ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// LCD Pin connections: ////
//// * 1: VSS is connected to GND ////
//// * 2: VDD is connected to +5V ////
//// * 3: V0 - LCD operating voltage (Constrast adjustment) ////
//// * 4: R/S - Data or Instruction is connected to C7 ////
//// * 5: R/W - Read or Write is connected to C6 ////
//// * 6: Enable is connected to C5 ////
//// * 7-14: Data Bus 0 to 7 is connected to port B ////
//// * 15: Positive voltage for LED backlight is connected to +5V ////
//// * 16: Negavtive voltage for LED backlight is connected to GND ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// glcd_init () ////
//// * Must be called before any other function. ////
//// ////
//// glcd_pixel (x,y,color) ////
//// * Sets the pixel to the given color. ////
//// - color can be ON or OFF ////
//// ////
//// glcd_fillScreen (color) ////
//// * Fills the entire LCD with the given color. ////
//// - color can be ON or OFF ////
//// ////
/////////////////////////////////////////////////////////////////////////
#define GLCD_RS RC7 // Display Data / Control Data.
#define GLCD_RW RC6 // Read / Write
#define GLCD_E RC5 // Enable Signal.
#define GLCD_WIDTH 144
#define RS_FUNCTION 0
#define RS_DATA 1
#define RW_WRITE 0
#define RW_READ 1
#define TRIS_READ 0xFF
#define TRIS_WRITE 0x00
// Color Values
#define ON 1
#define OFF 0
typedef union
{
int16 word;
int8 byte[2];
} Dots;
typedef struct
{
int1 refresh;
Dots pix[32][12]; // Max dimensions for display (x,y) = (144,31)
} GDRAM; // (0,0) corresponds to upper lefthand corner.
GDRAM gdram;
/*----------------------------------------------------------------------------------------------
* glcd_readByte
*
* Reads a byte of data from the LCD.
*
* In/Out:
*
* Return: A byte of data read from the LCD.
*
*--------------------------------------------------------------------------------------------*/
unsigned int8 glcd_readByte (unsigned int8 address)
{
unsigned int8 data; // Stores the data read from the LCD
set_tris_b (TRIS_READ); // Set PORTB to input
delay_us(15);
GLCD_RS = address;
GLCD_RW = RW_READ; // Set for reading
delay_us(50);
GLCD_E = 1; // Pulse the enable pin
delay_us(50);
data = PORTB; // Get the data from the display's output register
GLCD_E = 0;
delay_us(15);
GLCD_RS = 1;
return (data);
}
/*----------------------------------------------------------------------------------------------
* Function Name: CheckBusyFlag()
*
* Function: Reads the status of bit 7 to test busy flag
*
* In/Out:
*
* Return: Flagdata
*
*
*
*--------------------------------------------------------------------------------------------*/
unsigned int8 CheckBusyFlag ()
{
unsigned int8 Flagdata; // flag data value
set_tris_b (TRIS_READ); // Set PORTB to input
delay_us(15);
GLCD_RS = 0;
GLCD_RW = RW_READ; // Set for reading
delay_us(5);
GLCD_E = 1; // Pulse the enable pin
delay_us(15);
Flagdata = (PORTB & 0x40); // mask bit 7 to test busy flag data from the display's output register
delay_us(15);
GLCD_E = 0;
delay_us(15);
GLCD_RS = 1;
return (Flagdata);
}
/*----------------------------------------------------------------------------------------------
* glcd_writeByte
*
* Write a byte of data to the LCD.
*
* - data (in): the byte of data to write.
*
*
*--------------------------------------------------------------------------------------------*/
void glcd_writeByte (unsigned int8 address, unsigned int8 data)
{
GLCD_RS = RS_FUNCTION;
//while ( CheckBusyFlag () ) ; // Whait Busy Flag = FALSE!
set_tris_b (TRIS_WRITE); // Set PORTB to output
delay_us(1000);
GLCD_RS = address;
GLCD_RW = RW_WRITE; // Set for writing
GLCD_E = 0;
delay_us(1000);
PORTB = data; // Put the data on the port
//GLCD_E = 1;
delay_us(1000);
GLCD_E = 1;
// PORTB = data; // Put the data on the port
delay_us(1000);
GLCD_E = 0; // Pulse the enable pin
GLCD_RW = 1;
}
/*----------------------------------------------------------------------------------------------
glcd_fillScreen
*
* Fill the LCD screen with the passed in color.
*
* - color (in):
* ON - turn all the pixels on.
* OFF - turn all the pixels off.
*
*--------------------------------------------------------------------------------------------*/
void glcd_fillScreen (unsigned int1 color)
{
int8 v, h;
int16 d;
d = (color == ON ? 0xFFFFL : 0x0000L);
for (v=0; v<32; v++)
{
for (h=0; h<12; h++)
{
gdram.pix[v][h].word = d;
}
}
gdram.refresh = TRUE;
}
/*----------------------------------------------------------------------------------------------
* glcd_update
*
* Update the LCD with data from the display cache.
*
*--------------------------------------------------------------------------------------------*/
void glcd_update ()
{
int8 v, h;
if (gdram.refresh)
{
for (v=0; v<32; v++)
{
glcd_writeByte (RS_FUNCTION, 0x80 | v); // Set Vertical Address.
glcd_writeByte (RS_FUNCTION, 0x80 | 0); // Set Horizontal Address.
for (h=0; h<12; h++)
{
glcd_writeByte (RS_DATA, gdram.pix[v][h].byte[1]); // Write High Byte.
glcd_writeByte (RS_DATA, gdram.pix[v][h].byte[0]); // Write Low Byte.
}
}
gdram.refresh = FALSE;
}
}
/*----------------------------------------------------------------------------------------------
* glcd_init
*
* Initialize LCD.
*
* - mode (in): OFF/ON - Turns the LCD off/on.
*
* Call before using any other LCD function.
*
*--------------------------------------------------------------------------------------------*/
void glcd_init ()
{
set_tris_b (TRIS_WRITE); // PORTB as output.
GLCD_RS = RS_FUNCTION;
GLCD_RW = RW_WRITE;
GLCD_E = 0;
delay_ms (40);
glcd_writeByte (RS_FUNCTION, 0x30); // Specify 8 bit interface and basic instruction set.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x30); // Specify 8 bit interface and basic instruction set.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x0C); // Specify Display on, Cursor off and Blink off.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x01); // Display clear.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x06); // AC Increase (cursor move right), don't shift the display.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x34); // Select extended instruction set.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x36); // Graphic display ON.
delay_ms (10);
glcd_fillScreen (1);
glcd_update ();
}
/*----------------------------------------------------------------------------------------------
* Turn a pixel on a graphic LCD on or off.
*
*
* - x (in): the x coordinate of the pixel.
* - y (in): y - the y coordinate of the pixel.
* - color (in): ON or OFF.
*--------------------------------------------------------------------------------------------*/
void glcd_pixel(int8 x, int8 y, int1 color)
{
int8 v, h, b;
v = y;
h = x/16;
b = 15 - (x%16);
// Modify the actual word.
if (color == ON) bit_set (gdram.pix[v][h].word, b);
else bit_clear (gdram.pix[v][h].word, b);
gdram.refresh = TRUE;
}