PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
Driver for 84x48 TCM8448A GLCD (ST7541 cntllr) |
Posted: Thu Feb 05, 2009 6:40 am |
|
|
Code: |
#ifndef TCM8448A_H
#define TCM8448A_H
///////////////////////////////////////////////////////////////////////////////
// signals
#bit A0 = PORTB.0
#bit CS = PORTB.1
#bit RSET= PORTB.2
///////////////////////////////////////////////////////////////////////////////
// commands
#define NOP 0x00
#define FUNCSET 0x20
#define DISPCNT 0x08
#define YADDRSS 0x40
#define XADDRSS 0x80
#define BIASSYS 0x10
#define V0VOLTG 0x80
//-----------------------
#define PD 0x04
#define V 0x02
#define H 0x01
//-----------------------
#define DISPBLNK 0x00
#define DISPNORM 0x04
#define DISPAON 0x01
#define DISPINV 0x05
///////////////////////////////////////////////////////////////////////////////
// GLCD RAM image
BYTE GLCDRAM[6][84];
///////////////////////////////////////////////////////////////////////////////
#define GLCD_WIDTH 84
///////////////////////////////////////////////////////////////////////////////
// Function to write commands
void glcd_WriteCommand(unsigned int8 C)
{
A0 = 0; //command
delay_cycles(1);
CS = 0;
delay_cycles(1);
spi_write(C);
delay_cycles(1);
CS = 1;
}
///////////////////////////////////////////////////////////////////////////////
// Function to write data
void glcd_WriteData(unsigned int8 D)
{
A0 = 1; //data
delay_cycles(1);
CS = 0;
delay_cycles(1);
spi_write(D);
delay_cycles(1);
CS = 1;
}
///////////////////////////////////////////////////////////////////////////////
// GLCD initialization; should be called before any other opreation
void glcd_init()
{
unsigned int8 i,j;
setup_spi(SPI_MASTER|SPI_XMIT_L_TO_H|SPI_L_TO_H|SPI_CLK_DIV_4);
RSET = 1;
delay_ms(1);
glcd_WriteCommand(FUNCSET | V |H);
glcd_WriteCommand(BIASSYS | 0x04);
glcd_WriteCommand(V0VOLTG | 0x70);
glcd_WriteCommand(FUNCSET);
glcd_WriteCommand(DISPCNT | DISPNORM);
glcd_WriteCommand(XADDRSS | 0x00);
glcd_WriteCommand(YADDRSS | 0x00);
delay_cycles(1);
//clear display:
for (i=0;i<6;i++)
for(j=0;j<84;j++)
{
glcd_WriteData(0x00);
GLCDRAM[i][j] = 0x00;
}
}
///////////////////////////////////////////////////////////////////////////////
// function to draw a pixel at a specific location and color
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 color)
{
unsigned int8 yo;
yo = y/8;
if (color)
{
bit_set(GLCDRAM[yo][x], y%8);
}
else
{
bit_clear(GLCDRAM[yo][x], y%8);
}
glcd_WriteCommand(XADDRSS | x);
glcd_WriteCommand(YADDRSS | yo);
glcd_WriteData(GLCDRAM[yo][x]);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#endif
|
|
|