Код: //**************************************************************** // TITLE: SED1520LCD.C // DATE: 04 DEC 05 // BY: JV // DESCRIPTION: SED1520 code for CCS graphics // driver //---------------------------------------------------------------- // Revision: V1.0 (first release) //****************************************************************
// PICCore Pin definitions----------// #define LCD_CS1 PIN_C2 // Enable Left Side of LCD #define LCD_CS2 PIN_C3 // Enable Right Side of LCD #define LCD_RW PIN_C1 // Read/Write #define LCD_A0 PIN_C0 // Control or Data #define D0 PIN_D0 // Databus 0 #define D1 PIN_D1 // Databus 1 #define D2 PIN_D2 // Databus 2 #define D3 PIN_D3 // Databus 3 #define D4 PIN_D4 // Databus 4 #define D5 PIN_D5 // Databus 5 #define D6 PIN_D6 // Databus 6 #define D7 PIN_D7 // Databus 7
// Tell CCS Graphics.c how big the display is #define GLCD_WIDTH 100 // Number of Horizontal pixels #define GLCD_HEIGHT 32 // Number of Vertical Pixels
#define LEFT 1 #define RIGHT 0
// Global Variables for this application (LCD) int SIDE; // Left or Right side of LCD
// Function Prototype for CCS Graphics.c driver void glcd_pixel(int8, int8, int1); // Required for CCS GRAPHICS.C
//=============================================================== // command_write (Cdata) // Write command data to the LCD // See SED1520 datasheet for more info //=============================================================== void LCDCWrite(int8 CData) // Write Instruction to LCD { if (SIDE==LEFT) { OUTPUT_LOW(LCD_A0); // Instruction (not display data) OUTPUT_LOW(LCD_RW); // We are going to WRITE Data OUTPUT_LOW(LCD_CS1); // CS Low on the LEFT side of the display delay_cycles(10);
OUTPUT_HIGH(LCD_CS1); // CS High (starts cycle) OUTPUT_D(CData); // Put the data on the bus delay_cycles(2);
OUTPUT_LOW(LCD_CS1); // Latch the data into the LCD delay_cycles(2); } else // The RIGHT hand side { OUTPUT_LOW(LCD_A0); // Instruction (not display data) OUTPUT_LOW(LCD_RW); // We are going to WRITE Data OUTPUT_LOW(LCD_CS2); // CS Low on the RIGHT side of the display delay_cycles(10);
OUTPUT_HIGH(LCD_CS2); // CS High (starts cycle) OUTPUT_D(CData); // Put the data on the bus delay_cycles(2);
OUTPUT_LOW(LCD_CS2); // Latch the data into the LCD delay_cycles(2); } }
//=============================================================== // Data write (DData) // Writes display data to the LCD //=============================================================== void LCDWrite(int8 DData) // Write Data to LCD { OUTPUT_HIGH(LCD_A0); // Data (not instruction) OUTPUT_LOW(LCD_RW); // We are going to WRITE Data if(SIDE==LEFT)OUTPUT_LOW(LCD_CS1); // If Left side then use CS1 if(SIDE==RIGHT)OUTPUT_LOW(LCD_CS2); // If Right side then use CS2 delay_cycles(2);
if(SIDE==LEFT) OUTPUT_HIGH(LCD_CS1); if(SIDE==RIGHT) OUTPUT_HIGH(LCD_CS2); OUTPUT_D(DData); // Put the data onto the bus delay_cycles(10);
if(SIDE==LEFT) OUTPUT_LOW(LCD_CS1); // and latch the data into if(SIDE==RIGHT) OUTPUT_LOW(LCD_CS2); // the LCD display delay_cycles(2); }
//=============================================================== // Display data read // Reads the display data pointed to by the page, column and // chip select. Returns the data. //=============================================================== int8 LCDRead() // Read Data from LCD { int8 DData;
if(SIDE==LEFT) OUTPUT_HIGH(LCD_CS1); if(SIDE==RIGHT) OUTPUT_HIGH(LCD_CS2);
OUTPUT_HIGH(LCD_A0); // Data OUTPUT_HIGH(LCD_RW); // Read Data if(SIDE==LEFT)OUTPUT_LOW(LCD_CS1); if(SIDE==RIGHT)OUTPUT_LOW(LCD_CS2); delay_cycles(2);
set_tris_d(0xff); // Allow LCD to drive the data lines
if(SIDE==LEFT) OUTPUT_HIGH(LCD_CS1); if(SIDE==RIGHT) OUTPUT_HIGH(LCD_CS2);
delay_cycles(50); DData=INPUT_D(); // Get the data if(SIDE==LEFT) OUTPUT_LOW(LCD_CS1); if(SIDE==RIGHT) OUTPUT_LOW(LCD_CS2); delay_cycles(2);
return(DData); }
//=============================================================== // Draw a single pixel // This is required by the Graphics.c driver file provided by // CCS. It tells the driver how to draw a single pixel anywhere // on the LCD display // x=1 to 122 y=1 to 32 color=1=ON color=0=OFF //=============================================================== void glcd_pixel(int8 x, int8 y, int1 color) { int8 ucMask; int8 i; int8 Data; x-=1; // Which side of the display (which SED1520 controller) if (x<(GLCD_WIDTH/2)) SIDE = LEFT; else SIDE = RIGHT;
// Which vertical page needs selecting Data=184+((y-1)/8); // Control data to write is LCDCWrite(Data); // 184 + the page number (0-3) if (y>8)y-=((Data-184)*8); // y should always be 1-8
// Horizontal position (column) if (x>=(GLCD_WIDTH/2)) // x should always be 0-61 x-=(GLCD_WIDTH/2); // for each half of the LCD
LCDCWrite(x); // Go to column 'x'
LCDCWrite(0xe0); // Start R-M-Write operation LCDRead(); // Dummy Read Data = LCDRead(); // Read LCD dissplay data
ucMask = 1; // Create a bit mask of the for (i=1;i<y;i++) // pixel to change ucMask<<=1; //
if (color) Data|=ucMask; // Set or clear the pixel as else Data&=~ucMask; // requested LCDWrite(Data); LCDCWrite(0xee); // End R-M-Write operation }
//=================================================================== // Initialise the SED11520 controllers // for the display type we are using //=================================================================== void InitSED1520() { int8 i;
// Setup both SED1520 ccontrollers for (i=0;i<2;i++) { SIDE=i; LCDCWrite(0xaf); // Turn on the display LCDCWrite(0xa4); // Static drive is off LCDCWrite(0xa9); // Duty cycle is set to 1/32 LCDCWrite(0xe2); // Reset the chip LCDCWrite(0xa0); // Set ADC LCDCWrite(0xee); // Read modify write disabled LCDCWrite(0xc0); // Set the start position to LCDCWrite(0xb8); // the top left of the display LCDCWrite(0x00); // in column 0 } OUTPUT_LOW(LCD_CS1); // De-select each side to start OUTPUT_LOW(LCD_CS2); // delay_ms(60); }
void ClearScreen(){ int8 i,j,k; for(k=0;k<2;k++){ // Clear both controlers data SIDE=k; for(j=0;j<4;j++){ // Now go through all pages and clear the LCD RAM LCDCWrite(184+j); // so that the display is cleared LCDCWrite(0); for(i=0;i<=(GLCD_WIDTH/2);i++) LCDWrite(0x00); } } }
|