📄 s1d15g00.c
字号:
// **************************************************************************************************************
// lcd.c
//
// Nokia 6610 LCD Display Driver (Epson S1D15G00 Controller)
//
// Controller used for LCD Display is a Epson S1D15G00 driver
// Note: For Olimex SAM7-EX256 boards with the G8 decal or the Sparkfun Color LCD 128x128 Nokia Knock-Off
//
//
// We will use a 132 x 132 pixel matrix - each pixel has 12 bits of color information.
//
// _____
// | |
// ___________________|___|___
// | ====================== |
// ^ (131,0) |------------------------- |(131,131)
// | | |
// | | |
// | | |
// | | |
// | | |
// | Rows| Nokia 6610 Display | Note: In general, you can't view column 130 or column 131
// | | |
// X | |
// | | |
// | | |
// | | |
// | | |
// | | |
// | |--------------------------|
// (0,0) Columns (0,131)
//
// ------------Y-------------->
//
//
// 132 x 132 pixel matrix has two methods to specify the color info
//
// 1. 12 bits per pixel
// requires command and 1.5 data bytes to specify a single pixel
// (3 data bytes can specify 2 pixels)
//
// 2. 8 bits per pixel
// requires one command and one data byte to specify the single pixel\//
// note: pixel data byte converted by RGB table to 12-bit format above
//
// THIS IMPLEMENTATION USES THE 12 BITS PER PIXEL METHOD!
// -------------------------
//
//
//
//
// HARDWARE INTERFACE
// ------------------
//
// The Nokia 6610 display uses a SPI serial interface (9 bits)
//
// PA2 = LCD Reset (set to low to reset)
// PA12 = LCD chip select (set to low to select the LCD chip)
// PA16 = SPI0_MISO Master In - Slave Out (not used in Olimex SAM7-EX256 LCD interface)
// PA17 = SPI0_MOSI Master Out - Slave In pin (Serial Data to LCD slave)
// PA18 = SPI0_SPCK Serial Clock (to LCD slave)
//
// SPI baud rate set to MCK/2 = 48054841/3 = 16018280 baud
// (period = 62 nsec, OK since 50 nsec period is min for S1D15G00)
//
// The important thing to note is that you CANNOT read from the LCD!
//
//
// Author: James P Lynch August 30, 2007
// ***************************************************************************************************************
// **************************************
// Include Files
// **************************************
//#include "LPC23xx.H" // LPC2368 MPU Register
#include "s1d15g00.h" // LCD-NOKIA6610 Epson:S1D1G00 Controller
// **************************************
// forward references
// **************************************
const unsigned char FONT6x8[97][8];
const unsigned char FONT8x8[97][8];
const unsigned char FONT8x16[97][16];
void WriteSpiCommand(unsigned int data);
void WriteSpiData(unsigned int data);
void Backlight(unsigned char state);
void InitLcd(void);
void LCDWrite130x130bmp( unsigned char * image );
void LCDClearScreen(void);
void LCDSetPixel(int x, int y, int color);
void LCDSetLine(int x1, int y1, int x2, int y2, int color);
void LCDSetRect(int x0, int y0, int x1, int y1, unsigned char fill, int color);
void LCDSetCircle(int x0, int y0, int radius, int color);
void LCDPutChar(char c, int x, int y, int size, int fcolor, int bcolor);
void LCDPutStr(char *pString, int x, int y, int Size, int fColor, int bColor);
extern void Delay(vu32 nCount);
// *****************************************************************************
// WriteSpiCommand.c
//
// Writes 9-bit command to LCD display via SPI interface
//
// Inputs: data - Epson S1D15G00 controller/driver command
//
//
// Note: clears bit 8 to indicate command transfer
//
// Author: Olimex, James P Lynch August 30, 2007
// *****************************************************************************
void WriteSpiCommand(volatile unsigned int command)
{
unsigned char Bit = 0; // Bit Counter
LCD_CS_HI(); // Makesure CS = Disable
LCD_SCLK_LO(); // Prepared SCLK
LCD_CS_LO(); // Start CS = Enable
LCD_SDATA_LO(); // D/C# = 0(Command)
LCD_SCLK_HI(); // Strobe Signal Bit(SDATA)
LCD_SCLK_LO(); // Standby SCLK
for (Bit = 0; Bit < 8; Bit++) // 8 Bit Write
{
LCD_SCLK_LO(); // Standby SCLK
if((command&0x80)>>7)
{
LCD_SDATA_HI();
}
else
{
LCD_SDATA_LO();
}
LCD_SCLK_HI(); // Strobe Signal Bit(SDATA)
command <<= 1; // Next Bit Data
}
LCD_SCLK_LO(); // Standby SCLK
LCD_CS_HI(); // Stop CS = Disable
}
// *****************************************************************************
// WriteSpiData.c
//
// Writes 9-bit command to LCD display via SPI interface
//
// Inputs: data - Epson S1D15G00 controller/driver command
//
//
// Note: Sets bit 8 to indicate data transfer
//
// Author: Olimex, James P Lynch August 30, 2007
// *****************************************************************************
void WriteSpiData(volatile unsigned int data)
{
unsigned char Bit = 0; // Bit Counter
LCD_CS_HI(); // Makesure CS = Disable
LCD_SCLK_LO(); // Standby SCLK
LCD_CS_LO(); // Start CS = Enable
LCD_SDATA_HI(); // D/C# = 1(Data)
LCD_SCLK_HI(); // Strobe Signal Bit(SDATA)
LCD_SCLK_LO(); // Standby SCLK
for (Bit = 0; Bit < 8; Bit++) // 8 Bit Write
{
LCD_SCLK_LO(); // Standby SCLK
if((data&0x80)>>7)
{
LCD_SDATA_HI();
}
else
{
LCD_SDATA_LO();
}
LCD_SCLK_HI(); // Strobe Signal Bit(SDATA)
data <<= 1; // Next Bit Data
}
LCD_SCLK_LO(); // Standby SCLK
LCD_CS_HI(); // Stop CS = Disable
}
// *****************************************************************************
// Backlight.c
//
// Turns the backlight on and off
//
// Inputs: state - 1 = backlight on
// 2 = backlight off
//
//
// Author: Olimex, James P Lynch August 30, 2007
// *****************************************************************************
void Backlight(unsigned char state)
{
if (state == 1)
{
LCD_BL_HI(); // Black Light ON
}
else
{
LCD_BL_LO(); // Black Light OFF
}
}
// *****************************************************************************
// InitLcd.c
//
// Initializes the Epson S1D15G00 LCD Controller
//
// Inputs: none
//
// Author: James P Lynch August 30, 2007
// *****************************************************************************
void InitLcd(void)
{
// Hardware reset
LCD_RESET_LO(); // Start Reset
Delay(20000); // Reset Pulse Time
LCD_RESET_HI(); // Release Reset
Delay(20000);
// Display control
WriteSpiCommand(DISCTL);
WriteSpiData(0x00); // P1: 0x00 = 2 divisions, switching period=8 (default)
WriteSpiData(0x20); // P2: 0x20 = nlines/4 - 1 = 132/4 - 1 = 32)
WriteSpiData(0x00); // P3: 0x00 = no inversely highlighted lines
// COM scan
WriteSpiCommand(COMSCN);
WriteSpiData(1); // P1: 0x01 = Scan 1->80, 160<-81
// Internal oscilator ON
WriteSpiCommand(OSCON);
// Sleep out
WriteSpiCommand(SLPOUT);
// Power control
WriteSpiCommand(PWRCTR);
WriteSpiData(0x0f); // reference voltage regulator on, circuit voltage follower on, BOOST ON
// Inverse display
WriteSpiCommand(DISINV);
// Data control
WriteSpiCommand(DATCTL);
WriteSpiData(0x01); // P1: 0x01 = page address inverted, column address normal, address scan in column direction
WriteSpiData(0x00); // P2: 0x00 = RGB sequence (default value)
WriteSpiData(0x02); // P3: 0x02 = Grayscale -> 16 (selects 12-bit color, type A)
// Voltage control (contrast setting)
WriteSpiCommand(VOLCTR);
WriteSpiData(38); // P1 = 32 volume value (experiment with this value to get the best contrast)
WriteSpiData(3); // P2 = 3 resistance ratio (only value that works)
// allow power supply to stabilize
Delay(100000);
// turn on the display
WriteSpiCommand(DISON);
}
// *****************************************************************************
// LCDWrite130x130bmp.c
//
// Writes the entire screen from a bmp file
// Uses Olimex BmpToArray.exe utility
//
// Inputs: picture in bmp.h
//
// Author: Olimex, James P Lynch August 30, 2007
// *****************************************************************************
void LCDWrite130x130bmp( unsigned char * image)
{
long j; // loop counter
// Data control (need to set "normal" page address for Olimex photograph)
WriteSpiCommand(DATCTL);
WriteSpiData(0x00); // P1: 0x00 = page address normal, column address normal, address scan in column direction
WriteSpiData(0x00); // P2: 0x00 = RGB sequence (default value)
WriteSpiData(0x02); // P3: 0x02 = Grayscale -> 16
// Display OFF
WriteSpiCommand(DISOFF);
// Column address set (command 0x2A)
WriteSpiCommand(CASET);
WriteSpiData(0);
WriteSpiData(131);
// Page address set (command 0x2B)
WriteSpiCommand(PASET);
WriteSpiData(0);
WriteSpiData(131);
// WRITE MEMORY
WriteSpiCommand(RAMWR);
for(j = 0; j < 25740; j++)
{
WriteSpiData(image[j]);
}
// Data control (return to "inverted" page address)
WriteSpiCommand(DATCTL);
WriteSpiData(0x01); // P1: 0x01 = page address inverted, column address normal, address scan in column direction
WriteSpiData(0x00); // P2: 0x00 = RGB sequence (default value)
WriteSpiData(0x02); // P3: 0x02 = Grayscale -> 16
// Display On
WriteSpiCommand(DISON);
}
// *****************************************************************************
// LCDClearScreen.c
//
// Clears the LCD screen to single color (BLACK)
//
// Inputs: none
//
// Author: James P Lynch August 30, 2007
// *****************************************************************************
void LCDClearScreen(void)
{
long i; // loop counter
// Row address set (command 0x2B)
WriteSpiCommand(PASET);
WriteSpiData(0);
WriteSpiData(131);
// Column address set (command 0x2A)
WriteSpiCommand(CASET);
WriteSpiData(0);
WriteSpiData(131);
// set the display memory to BLACK
WriteSpiCommand(RAMWR);
for(i = 0; i < ((131 * 131) / 2); i++)
{
WriteSpiData((BLACK >> 4) & 0xFF);
WriteSpiData(((BLACK & 0xF) << 4) | ((BLACK >> 8) & 0xF));
WriteSpiData(BLACK & 0xFF);
}
}
// *************************************************************************************
// LCDSetPixel.c
//
// Lights a single pixel in the specified color at the specified x and y addresses
//
// Inputs: x = row address (0 .. 131)
// y = column address (0 .. 131)
// color = 12-bit color value rrrrggggbbbb
// rrrr = 1111 full red
// :
// 0000 red is off
//
// gggg = 1111 full green
// :
// 0000 green is off
//
// bbbb = 1111 full blue
// :
// 0000 blue is off
//
// Returns: nothing
//
// Note: see lcd.h for some sample color settings
//
// Author: James P Lynch August 30, 2007
// *************************************************************************************
void LCDSetPixel(int x, int y, int color)
{
// Row address set (command 0x2B)
WriteSpiCommand(PASET);
WriteSpiData(x);
WriteSpiData(x);
// Column address set (command 0x2A)
WriteSpiCommand(CASET);
WriteSpiData(y);
WriteSpiData(y);
// Now illuminate the pixel (2nd pixel will be ignored)
WriteSpiCommand(RAMWR);
WriteSpiData((color >> 4) & 0xFF);
WriteSpiData(((color & 0xF) << 4) | ((color >> 8) & 0xF));
WriteSpiData(color & 0xFF);
}
// *************************************************************************************************
// LCDSetLine.c
//
// Draws a line in the specified color from (x0,y0) to (x1,y1)
//
// Inputs: x = row address (0 .. 131)
// y = column address (0 .. 131)
// color = 12-bit color value rrrrggggbbbb
// rrrr = 1111 full red
// :
// 0000 red is off
//
// gggg = 1111 full green
// :
// 0000 green is off
//
// bbbb = 1111 full blue
// :
// 0000 blue is off
//
// Returns: nothing
//
// Note: good write-up on this algorithm in Wikipedia (search for Bresenham's line algorithm)
// see lcd.h for some sample color settings
//
// Authors: Dr. Leonard McMillan, Associate Professor UNC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -