?? ssd1289.c
字號:
/*
*************************************************************************************************
* FG020214 262k color Graphical LCD Display Driver (SOLOMON SYSTEM's SSD1289 controller)
* All Rights Reserved
* File name : SSD1289.c
* Programmer : John Leung, TechToys Co. Hong Kong
* Web presence : www.TechToys.com.hk
* Note :
* Language : C18 complier version 2.40, MPLAB v7.41
* Hardware : PIC18LF4550-STK1 connected to a prototype board for FG020214 via strip wires
* Date : 16 Nov 2006 Version 1.0a
*************************************************************************************************
* DESCRIPTION
*
* This module provides an interface to FG020214 262k color graphical LCD module of 240*320dots
* Display controller chip is SSD1289
* Module requires 3.3V DC supply to Vdd, LED backlight requires 15mA typical
* Backlight driven by CAT32 for 15mA constant current driver
* <PS3:PS1:PS0> in <1:0:0> for 8-bit data bus mode 8080
*
* LCD pinout function on PCB (FG020214_BO) summarized as below
* --------- LCD MCU -----------------
* pin 2 SHDN_BL - NOT used here, short to VCC via 100k resistor
* pin 4 GND - GND
* pin 6 VCC - 3.3V supply
* pin 8 n.c. - n.c.
* pin 10 WR - RE1
* pin 12 RD - RE0
* pin 14 CS - RE2
* pin 16 CD - RA5
* pin 18 RST - To system reset
* pin 20:34 D0:D7 - LCD_DATA connected to RD0:RD7
* pin 36 SHUT - n.c.
* pin 38 n.c.
* pin 40 n.c.
*
* Remarks: Pins at the odd number side is not used for 8-bit mode.
*
***********************************************************************************************
*/
/*
***********************************************************************************************
* Date : 10th May 2007
* Modification : cDispClr(RGB24(r,g,b)) added
* Project compiled with C18 version 2.40 & MPLAB version upgraded to V7.60
* Version : v1.0b
***********************************************************************************************
*/
/*
***********************************************************************************************
* Date : 13th JUNE 2007
* Modification : 16 bit color mode for string print and pattern print added
* Project compiled with C18 version 2.40 & MPLAB version upgraded to V7.60
* Version : v1.0c
***********************************************************************************************
*/
#include <p18cxxx.h>
#include "delay.h"
#include "SSD1289.h"
#include "sysfont.h"
/*
*********************************************************************************************************
* LOCAL DEFINITIONS
*********************************************************************************************************
*/
#define OUTPUT 0
#define INPUT 1
#define HIGH 1
#define LOW 0
/*
*********************************************************************************************************
* DISPLAY INITIALIZATION
*
* Description : This function initializes the LCD module
* Arguments : none
*
* Returns : none
* Note : This function should be called once before any of the other functions
*********************************************************************************************************
*/
void cDispInit(void)
{
unsigned int i, j;
cDispInitPort();
cDispWrCmd(0x00); //Start Oscillation
cDispWrDat(0x00);
cDispWrDat(0x01);
cDispWrCmd(0x01); //Driver Output Control
cDispWrDat(0x23);
cDispWrDat(0x3F);
cDispWrCmd(0x02); //LCD Drive AC Control
cDispWrDat(0x06);
cDispWrDat(0x00);
cDispWrCmd(0x03); //Power Control (1)
cDispWrDat(0xA8);
cDispWrDat(0xA6);
cDispWrCmd(0x07); //Display Control
cDispWrDat(0x00);
cDispWrDat(0x33);
cDispWrCmd(0x11); //Entry Mode (R11h): Set Display color mode for 65k/262k color
#ifdef _COLOR_24_BIT_
cDispWrDat(0x48); //DFM1:DFM0=1:0 for 262k color
#endif
#ifdef _COLOR_16_BIT_
cDispWrDat(0x68); //DFM1:DFM0=1:1 for 65k color (POR)
#endif
cDispWrDat(0x30);
cDispWrCmd(0x0C); //Power Control (2)
cDispWrDat(0x00);
cDispWrDat(0x05);
cDispWrCmd(0x0D); //Power Control (3)
cDispWrDat(0x30);
cDispWrDat(0x0B);
cDispWrCmd(0x0E); //Power Control (4)
cDispWrDat(0x20);
cDispWrDat(0x00);
cDispWrCmd(0x10); //Exit Sleep Mode
cDispWrDat(0x00);
cDispWrDat(0x00);
DelayMs(30); //delay 30ms
cDispWrCmd(0x1E); //Power Control (5)
cDispWrDat(0x00);
cDispWrDat(0xA8);
cDispWrCmd(0x44); //Horizontal RAM address position start/end setup
cDispWrDat(0xEF); //dec 239
cDispWrDat(0x00); //dec 0, i.e. horizontal ranges from 0 -> 239
//POR value is 0xEF00 anyway. This address must be set before RAM write
cDispWrCmd(0x45); //Vertical RAM address start position setting
cDispWrDat(0x00); //0x0000 = dec 0
cDispWrDat(0x00);
cDispWrCmd(0x46); //Vertical RAM address end position setting
cDispWrDat(0x01); //0x013F = dec 319
cDispWrDat(0x3F);
cDispWrCmd(0x22); //RAM write command
#ifdef _COLOR_24_BIT_
cDispClr(RGB24(63,63,63)); //initialize the LCD in white color for 24-bit color mode
#endif
#ifdef _COLOR_16_BIT_
cDispClr(RGB16(31,63,31));
#endif
}
/*
*********************************************************************************************************
* CLEAR DISPLAY BY WRITING PURE COLOR TO THE WHOLE SCREEN
*
* Description : This function writes a 24 bit integer to all pixels making use of the automatic
* address increment feature for X and Y address counters
*
* Arguments : 'color' is in 24-bit in form of RGB24(r,g,b)
* with color defined in red = [xxR5R4R3R2R1R0]
* in green = [xxG5G4G3G2G1G0]
* in blue = [xxB5B4B3B2B1B0]; x represents doesn't care bit
* Therefore (r,g,b) from (0,0,0) to (63,63,63)
* color=0x000000 eq. black
* color=0x3F0000 eq. red
* color=0x003F00 eq. green
* color=0x00003F eq. blue
* color=0x3F3F3F in white
* Returns : none
* Remarks :
*
*********************************************************************************************************
*/
#ifdef _COLOR_24_BIT_
void cDispClr(INT24U color)
{
INT8U i,rByte,gByte,bByte;
INT16U j;
rByte = color>>16; //red byte
gByte = color>>8; //green byte
bByte = (INT8U)color; //blue byte
for(j=0;j<320;j++)
{
for(i=0;i<240;i++)
{
cDispWrDat(rByte);cDispWrDat(gByte);cDispWrDat(bByte);
}
}
}
#endif
/*
*********************************************************************************************************
* CLEAR DISPLAY BY WRITING PURE COLOR TO THE WHOLE SCREEN
*
* Description : This function writes a 16 bit integer to all pixels making use of the automatic
* address increment feature for X and Y address counters
*
* Arguments : 'color' is in 16-bit in form of RGB16(r,g,b) for 65k color display mode
* 16-bit color in [R4R3R2R1R0G5G4G3][G2G1G0B4B3B2B1B0]
* Therefore (r,g,b) from (0,0,0) to (31,63,31)
* color=0x0000 eq. black
* color=0xF800 eq. red
* color=0x07E0 eq. green
* color=0x001F eq. blue
* color=0xFFFF in white
* Returns : none
* Remarks :
*
*********************************************************************************************************
*/
#ifdef _COLOR_16_BIT_
void cDispClr(INT16U color)
{
INT8U i,hiByte,lowByte;
INT16U j;
hiByte = color>>8;
lowByte = (INT8U)color;
for(j=0;j<320;j++)
{
for(i=0;i<240;i++)
{
cDispWrDat(hiByte);cDispWrDat(lowByte);
}
}
}
#endif
/*
*********************************************************************************************************
* SET PIXEL AT x, y POSITION
*
* Description : This function sets a pixel with (INT16U)color at a position defined by (x,y) following
* Cartesian coordinate system. Coordinates (0,0) at the top left corner,
* coordinates (239,319) at the lower right corner of the LCD screen, w/ module viewed from
* frontal up direction on FG020214_BO
*
* Arguments : 'x' 0....239 is the matrix position in x-axis (left ->right)
* 'y' 0....319 is the matrix position in y-axis (up -> down)
* 'color' sets 16-bit color
* Returns : none
* Notes :
*********************************************************************************************************
*/
#ifdef _COLOR_16_BIT_
void cDispSetPixel(INT8U x, INT16U y, INT16U color)
{
INT8U hiByte, lowByte;
cDispWrCmd(0x4E); //set address in the 240 pixel direction
cDispWrDat(0x00); //hiByte first fill all zero
cDispWrDat(x); //0<x<239
hiByte = y>>8;
lowByte = (INT8U)y;
cDispWrCmd(0x4F); //set address in the 320 pixel direction
cDispWrDat(hiByte);
cDispWrDat(lowByte);
hiByte = color>>8;
lowByte = (INT8U)color;
cDispWrCmd(0x22); //RAM write command
cDispWrDat(hiByte); //write color content here
cDispWrDat(lowByte);
}
#endif
/*
*********************************************************************************************************
* CONVERT A STRING FROM ROM TO PIXEL DATA AND DISPLAY AT x,y
*
* Description : This function outputs a string in graphic mode (pixel-by-pixel) at a position defined
* by (x,y) following Cartesian coordinate system with variable font spacing defined by
* fontSpace. Character wrapping is allowed. String from ROM so const rom keyword used
* *** REQUIRE AT LEAST ONE FONT SET (sysfont.h) included under this file ****
* Cartesian coordinates as (0,0) at the top left hand corner, (239,319) at the
* lower right hand corner, as seen from frontal up view of FG020214_BO
*
* Arguments : 'x' 0....239 is matrix position in horizontal direction (x-axis).
*
* 'y' 0....319 is matrix position in vertical direction (y-axis).
*
* '*pStr' pointer to an ASCII string in ROM (flash), null terminated
* 'fontSpace' font spacing from 1 to 127
* 'color' 16-bit color possible
* Returns : none
* Notes : Microchip C18 complier dependent as const rom keyword involved.
* Example : ....
* ....
* main()
* {
* cDispPixStrAt(0,20,"Hello!",1,RGB(31,0,0)); //Display the ASCII string "Hello!"
* //at (x,y)=(0,20), font space = 1
* //color in red
* }
*********************************************************************************************************
*/
#ifdef _COLOR_16_BIT_
void cDisprStrAt(INT8U x, INT16U y, const rom char *pStr, INT8U fontSpace, INT16U color)
{
INT8U pixelByte,bit_idx, i; //loop counters
INT8U c,fwidth, fheight; //character, font width & height store
while (*pStr)
{
c = *pStr++ - 32;
fwidth = SYS_FNT[c].fontWidth;
fheight = 8;
if((x+fwidth)>240) //character wrapping here
{
x=0;
y+=fheight;
}
if((y+fheight)>320) //check for y boundary
{
y=0;
}
for(i=0;i<fheight;i++)
{
pixelByte = SYS_FNT[c].fontBody[i];
for(bit_idx=0; bit_idx<fwidth; bit_idx++)
{
if((pixelByte)&(0x80>>bit_idx))
cDispSetPixel(x+bit_idx, y+i, color);
}
}
x = x+fwidth+fontSpace;
}
}
#endif
/*
*********************************************************************************************************
* WRITE A PATTERN AT X, Y COORDINATES
*
* Description : This function writes a particular pattern of size patWidth and patHeight at a position
* defined by (x,y) following Cartesian coordinate system.
* Pattern defined in ROM (flash)
* Cartesian coordinates as (0,0) at the top left hand corner, (239,319) at the
* lower right hand corner, as seen from frontal up view of FG020214_BO
* Arguments : 'x' 0....239 is matrix position in horizontal direction (x-axis)
* 'y' 0....319 is matrix position in vertical direction (y-axis)
* '*pPat' pointer to pattern structure in const rom (FLASH)
* 'color' color in 16-bit mode
* Returns : none
* Notes : Microchip C18 complier dependent as const rom keyword involved
*********************************************************************************************************
*/
#ifdef _COLOR_16_BIT_
void cDisprPatAt(INT8U x, INT16U y, const rom INT16U *pPat)
{
INT16U col, row, pWidth, pHeight, pixel;
pWidth = pPat[0];
pHeight = pPat[1];
for(row=0;row<pHeight;row++)
{
for(col=0;col<pWidth;col++)
{
pixel = pPat[col+row*pWidth+2];
cDispSetPixel(col+x,row+y,pixel);
}
}
}
#endif
/*
*********************************************************************************************************
* LOW LEVEL PORT INITIALIZATION
*
* Description : This function performs low level port initialization
* Arguments : none
* Returns : none
* Notes : Hardware specific
*********************************************************************************************************
*/
void cDispInitPort(void)
{
cDISP_CS = HIGH; //de-select the color LCD to start with
cDISP_CD = HIGH;
cDISP_WR = HIGH;
cDISP_RD = HIGH;
cDISP_DATA = 0x00;
TRIS_cDISP_CS = OUTPUT;
TRIS_cDISP_CD = OUTPUT;
TRIS_cDISP_WR = OUTPUT;
TRIS_cDISP_RD = OUTPUT;
TRIS_cDISP_DATA = OUTPUT;
}
/*
*********************************************************************************************************
* LOW LEVEL COMMAND WRITE TO LCD
*
* Description : This function performs low level command write to LCD
* Arguments : (INT8U) 'cmd' is the command written to the LCD module
* Returns : none
* Notes : Hardware specific.
*********************************************************************************************************
*/
void cDispWrCmd(INT8U cmd)
{
cDISP_DATA = cmd;
cDISP_CD = LOW; //CD LOW for command
cDISP_WR = LOW;
cDISP_RD = HIGH;
cDISP_CS = LOW;
cDISP_CS = HIGH;
}
/*
*********************************************************************************************************
* LOW LEVEL DATA WRITE TO LCD
*
* Description : This function performs low level display data write to LCD
* Arguments : (INT8U) 'dat' is the data written to the LCD module
* Returns : none
* Notes : Hardware specific.
*********************************************************************************************************
*/
void cDispWrDat(INT8U dat)
{
cDISP_DATA = dat;
cDISP_CD = HIGH; //CD HIGH for display data
cDISP_WR = LOW;
cDISP_RD = HIGH;
cDISP_CS = LOW;
cDISP_CS = HIGH;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -