///////////////////////////////////////////////////////////////////////// //// GLCD_12232.C //// //// //// //// This file contains drivers for using a SantechDisplay SD-G12232.//// //// The Epson Contoroller SED1520 is mounted on this LCM //// //// The SD-G12232 is 122 pixles across and 32 pixels down. //// //// The driver treats the upper left pixel as (0,0). //// //// //// //// LCD Pin connections: //// //// (These can be changed as needed in the following defines). //// //// * 1: VSS is connected to GND //// //// * 2: VDD is connected to +5V //// //// * 3: V0 - LCD operating voltage is connected from a 20k Ohm POT//// //// * 4: RS(A0) - Register Select (Data or Instruction) //// //// is connected to RC3 //// //// * 5: E1 - Read/Write Enable of Chip1 connected to RC6 //// //// * 6: E2 - Read/Write Enable of Chip1 connected to RC7 //// //// *7-14: Data Bus 0 to 7 is connected to port d //// //// *15: Positive voltage for LED backlight is connected to Vf //// //// *16: Negavtive voltage for LED backlight is connected to GND //// //// *17: R/W - Read or Write is connected to RC4 //// //// *18: Reset is connected to RC2 //// //// //// //// glcd_init(mode) //// //// * Must be called before any other function. //// //// - mode can be ON or OFF to turn the LCD on or off //// //// //// //// glcd_pixel(x,y,color) //// //// * Sets the pixel to the given color. //// //// - color can be ON or OFF //// //// //// //// glcd_line(x1,y1,x2,y2,color) //// //// * Draws a line from the first point to the second point //// //// with the given color. //// //// - color can be ON or OFF //// //// //// //// glcd_rect(x1,y1,x2,y2,fill,color) //// //// * Draws a rectangle with upper left point (x1,y1) and lower //// //// right point (x2,y2). //// //// - fill can be YES or NO //// //// - color can be ON or OFF //// //// //// //// glcd_bar(x1,y1,x2,y2,width,color) //// //// * Draws a bar (wide line) from the first point to the //// //// second point. //// //// - width is the number of pixels wide //// //// - color is ON or OFF //// //// //// //// glcd_circle(x,y,radius,fill,color) //// //// * Draws a circle with center at (x,y) //// //// - fill can be YES or NO //// //// - color can be ON or OFF //// //// //// //// glcd_text57(x,y,textptr,size,color) //// //// * Write the null terminated text pointed to by textptr with //// //// the upper left coordinate of the first character at (x,y).//// //// Characters are 5 pixels wide and 7 pixels tall. //// //// - size is an integer that scales the size of the text //// //// - color is ON or OFF //// //// * Note - The given text is character wrapped. If this //// //// function is used on a different size display, then change //// //// the GLCD_WIDTH define appropriately. //// //// //// //// glcd_fillScreen(color) //// //// * Fills the entire LCD with the given color. //// //// - color can be ON or OFF //// //// //// //// bitmap_write() //// //// * Wite Black & White bitmap file(128*64dots) on LCD //// //// This bitmap data table is made by the freeware //// //// Basic Edition V1.5b of Bitmap2LCD //// //// //// ///////////////////////////////////////////////////////////////////////// #ifndef GLCD_12232 #define GLCD_12232 #ifndef GLCD_WIDTH #define GLCD_WIDTH 122 // Used for text wrapping by glcd_text57 function #endif #define ON 1 #define OFF 0 #define YES 1 #define NO 0 #ifndef GLCD_E1 #define GLCD_E1 PIN_C6 // Chip 1 Enable #endif #ifndef GLCD_E2 #define GLCD_E2 PIN_C7 // Chip 2 Enable #endif #ifndef GLCD_RS #define GLCD_RS PIN_C3 // Data or Instruction input #endif #ifndef GLCD_RW #define GLCD_RW PIN_C4 // Read/Write #endif #ifndef GLCD_RST #define GLCD_RST PIN_C2 // Reset #endif BYTE glcd_readByte(BYTE chip); void glcd_writeByte(BYTE chip, BYTE data); void glcd_fillScreen(int1 color); void glcd_pixel(int x, int y, int1 color); //////////// ASCII Letter Table /////////////////////////////////// const BYTE TEXT[51][5] ={0x00, 0x00, 0x00, 0x00, 0x00, // SPACE 0x00, 0x00, 0x5F, 0x00, 0x00, // ! 0x00, 0x03, 0x00, 0x03, 0x00, // " 0x14, 0x3E, 0x14, 0x3E, 0x14, // # 0x24, 0x2A, 0x7F, 0x2A, 0x12, // $ 0x43, 0x33, 0x08, 0x66, 0x61, // % 0x36, 0x49, 0x55, 0x22, 0x50, // & 0x00, 0x05, 0x03, 0x00, 0x00, // ' 0x00, 0x1C, 0x22, 0x41, 0x00, // ( 0x00, 0x41, 0x22, 0x1C, 0x00, // ) 0x14, 0x08, 0x3E, 0x08, 0x14, // * 0x08, 0x08, 0x3E, 0x08, 0x08, // + 0x00, 0x50, 0x30, 0x00, 0x00, // , 0x08, 0x08, 0x08, 0x08, 0x08, // - 0x00, 0x60, 0x60, 0x00, 0x00, // . 0x20, 0x10, 0x08, 0x04, 0x02, // / 0x3E, 0x51, 0x49, 0x45, 0x3E, // 0 0x04, 0x02, 0x7F, 0x00, 0x00, // 1 0x42, 0x61, 0x51, 0x49, 0x46, // 2 0x22, 0x41, 0x49, 0x49, 0x36, // 3 0x18, 0x14, 0x12, 0x7F, 0x10, // 4 0x27, 0x45, 0x45, 0x45, 0x39, // 5 0x3E, 0x49, 0x49, 0x49, 0x32, // 6 0x01, 0x01, 0x71, 0x09, 0x07, // 7 0x36, 0x49, 0x49, 0x49, 0x36, // 8 0x26, 0x49, 0x49, 0x49, 0x3E, // 9 0x00, 0x36, 0x36, 0x00, 0x00, // : 0x00, 0x56, 0x36, 0x00, 0x00, // ; 0x08, 0x14, 0x22, 0x41, 0x00, // < 0x14, 0x14, 0x14, 0x14, 0x14, // = 0x00, 0x41, 0x22, 0x14, 0x08, // > 0x02, 0x01, 0x51, 0x09, 0x06, // ? 0x3E, 0x41, 0x59, 0x55, 0x5E, // @ 0x7E, 0x09, 0x09, 0x09, 0x7E, // A 0x7F, 0x49, 0x49, 0x49, 0x36, // B 0x3E, 0x41, 0x41, 0x41, 0x22, // C 0x7F, 0x41, 0x41, 0x41, 0x3E, // D 0x7F, 0x49, 0x49, 0x49, 0x41, // E 0x7F, 0x09, 0x09, 0x09, 0x01, // F 0x3E, 0x41, 0x41, 0x49, 0x3A, // G 0x7F, 0x08, 0x08, 0x08, 0x7F, // H 0x00, 0x41, 0x7F, 0x41, 0x00, // I 0x30, 0x40, 0x40, 0x40, 0x3F, // J 0x7F, 0x08, 0x14, 0x22, 0x41, // K 0x7F, 0x40, 0x40, 0x40, 0x40, // L 0x7F, 0x02, 0x0C, 0x02, 0x7F, // M 0x7F, 0x02, 0x04, 0x08, 0x7F, // N 0x3E, 0x41, 0x41, 0x41, 0x3E, // O 0x7F, 0x09, 0x09, 0x09, 0x06, // P 0x1E, 0x21, 0x21, 0x21, 0x5E, // Q 0x7F, 0x09, 0x09, 0x09, 0x76};// R const BYTE TEXT2[44][5]={0x26, 0x49, 0x49, 0x49, 0x32, // S 0x01, 0x01, 0x7F, 0x01, 0x01, // T 0x3F, 0x40, 0x40, 0x40, 0x3F, // U 0x1F, 0x20, 0x40, 0x20, 0x1F, // V 0x7F, 0x20, 0x10, 0x20, 0x7F, // W 0x41, 0x22, 0x1C, 0x22, 0x41, // X 0x07, 0x08, 0x70, 0x08, 0x07, // Y 0x61, 0x51, 0x49, 0x45, 0x43, // Z 0x00, 0x7F, 0x41, 0x00, 0x00, // [ 0x02, 0x04, 0x08, 0x10, 0x20, // \ 0x00, 0x00, 0x41, 0x7F, 0x00, // ] 0x04, 0x02, 0x01, 0x02, 0x04, // ^ 0x40, 0x40, 0x40, 0x40, 0x40, // _ 0x00, 0x01, 0x02, 0x04, 0x00, // ` 0x20, 0x54, 0x54, 0x54, 0x78, // a 0x7F, 0x44, 0x44, 0x44, 0x38, // b 0x38, 0x44, 0x44, 0x44, 0x44, // c 0x38, 0x44, 0x44, 0x44, 0x7F, // d 0x38, 0x54, 0x54, 0x54, 0x18, // e 0x04, 0x04, 0x7E, 0x05, 0x05, // f 0x08, 0x54, 0x54, 0x54, 0x3C, // g 0x7F, 0x08, 0x04, 0x04, 0x78, // h 0x00, 0x44, 0x7D, 0x40, 0x00, // i 0x20, 0x40, 0x44, 0x3D, 0x00, // j 0x7F, 0x10, 0x28, 0x44, 0x00, // k 0x00, 0x41, 0x7F, 0x40, 0x00, // l 0x7C, 0x04, 0x78, 0x04, 0x78, // m 0x7C, 0x08, 0x04, 0x04, 0x78, // n 0x38, 0x44, 0x44, 0x44, 0x38, // o 0x7C, 0x14, 0x14, 0x14, 0x08, // p 0x08, 0x14, 0x14, 0x14, 0x7C, // q 0x00, 0x7C, 0x08, 0x04, 0x04, // r 0x48, 0x54, 0x54, 0x54, 0x20, // s 0x04, 0x04, 0x3F, 0x44, 0x44, // t 0x3C, 0x40, 0x40, 0x20, 0x7C, // u 0x1C, 0x20, 0x40, 0x20, 0x1C, // v 0x3C, 0x40, 0x30, 0x40, 0x3C, // w 0x44, 0x28, 0x10, 0x28, 0x44, // x 0x0C, 0x50, 0x50, 0x50, 0x3C, // y 0x44, 0x64, 0x54, 0x4C, 0x44, // z 0x00, 0x08, 0x36, 0x41, 0x41, // { 0x00, 0x00, 0x7F, 0x00, 0x00, // | 0x41, 0x41, 0x36, 0x08, 0x00, // } 0x02, 0x01, 0x02, 0x04, 0x02};// ~ /////////////////////////////////////////////////////////////////End Table /////////////// Bitmap image Table/////////////////////////////// //This Table is made by the freeware Basic Edition V1.5b of Bitmap2LCD const int8 bitmap1[GLCD_WIDTH]={//Dot Data of Page=0(IC1+IC2) 0x00 , 0x10 , 0x12 , 0x8C , 0xB8 , 0x98 , 0x68 , 0x88, 0xDC , 0x48 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0xDC , 0xA8 , 0x57 , 0x56 , 0xDC , 0xC4 , 0xC0 , 0x80, 0x00 , 0x00 , 0x00 , 0xFC , 0x00 , 0x00 , 0x00 , 0x20, 0x10 , 0xFC , 0x10 , 0x00 , 0x00 , 0x00 , 0x70 , 0x80, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x60 , 0x80, 0x00 , 0x00 , 0x10 , 0x10 , 0xD0 , 0x30 , 0xFE , 0x0C, 0x08 , 0x0A , 0x0E , 0x02 , 0x00 , 0x00 , 0x00 , 0x08, 0x08 , 0x08 , 0x08 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x40 , 0xC8 , 0x68 , 0x58 , 0x48 , 0xC4 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x84 , 0x7C, 0x54 , 0x54 , 0x52 , 0xFE , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0xE0 , 0x10 , 0x90 , 0x68 , 0x18 , 0x08 , 0x08, 0x08 , 0xF0 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 }; const int8 bitmap2[GLCD_WIDTH]={//Dot Data of Page=1(IC1+IC2) 0x00 , 0x00 , 0x04 , 0x04 , 0x07 , 0x04, 0x04 , 0x03, 0x04 , 0x04 , 0x04 , 0x04 , 0x00 , 0x00, 0x00 , 0x06, 0x05 , 0x04 , 0x03 , 0x03 , 0x07 , 0x08, 0x04 , 0x03, 0x00 , 0x00 , 0x00 , 0x07 , 0x02 , 0x02, 0x05 , 0x02, 0x02 , 0x03 , 0x02 , 0x04 , 0x00 , 0x00, 0x00 , 0x01, 0x02 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x05, 0x03 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x01 , 0x02, 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x00, 0x00 , 0x04, 0x04 , 0x02 , 0x05 , 0x04 , 0x02 , 0x02, 0x03 , 0x02, 0xC2 , 0x04 , 0x00 , 0xE0 , 0x80 , 0x84, 0x83 , 0x80, 0x00 , 0x00 , 0x04 , 0x07 , 0x00 , 0x00, 0xC0 , 0x20, 0x00 , 0x01 , 0x42 , 0x81 , 0x00 , 0x00, 0x02 , 0x02, 0xF2 , 0x81 , 0x00 , 0x20 , 0xC0 , 0x00, 0x00 , 0x00, 0x20 , 0x20 , 0x50 , 0xA0 , 0x60 , 0xC0, 0xF0 , 0x50, 0x40 , 0x00 }; const int8 bitmap3[GLCD_WIDTH]={//Dot Data of Page=2(IC1+IC2) 0x00 , 0x40 , 0x80 , 0x80, 0x60 , 0xC0 , 0xC0 , 0x40, 0xC0 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0x80 , 0x80 , 0x80 , 0x80, 0x80 , 0x00 , 0x00 , 0x00, 0x00 , 0xC0 , 0x20 , 0xC0, 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0xA0 , 0x40 , 0xC0 , 0x80, 0xE0 , 0xA0 , 0x80 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0x40 , 0x80 , 0x00 , 0x00, 0xC0 , 0x00 , 0x80 , 0x00, 0x00 , 0x00 , 0x00 , 0x00, 0x80 , 0x80 , 0xC0 , 0x80, 0x80 , 0x80 , 0xC0 , 0x9C, 0x93 , 0x0F , 0x13 , 0x00, 0x08 , 0x08 , 0x08 , 0x0D, 0x12 , 0x12 , 0x00 , 0x00, 0x19 , 0x07 , 0x11 , 0x31, 0x0F , 0x00 , 0x00 , 0x00, 0x01 , 0x06 , 0x00 , 0x00, 0x03 , 0x00 , 0x60 , 0x18, 0x07 , 0x00 , 0x00 , 0x12, 0x1A , 0x15 , 0x20 , 0x1D, 0x2B , 0x36 , 0x36 , 0x5F, 0x40 , 0x40 }; const int8 bitmap4[GLCD_WIDTH]={//Dot Data of Page=3(IC1+IC2) 0x90 , 0x90 , 0x5F , 0x35 , 0x1F , 0x12 , 0x35 , 0x48, 0x8F , 0x90 , 0x10 , 0x00 , 0x00 , 0x1E , 0x21 , 0x19, 0x06 , 0x01 , 0x20 , 0x20 , 0x20 , 0x1F , 0x00 , 0x00, 0x24 , 0x1B , 0x7D , 0x0A , 0x36 , 0x3D , 0x29 , 0x3F, 0x25 , 0x3F , 0x00 , 0x00 , 0x00 , 0x20 , 0x30 , 0x28, 0x40 , 0x3B , 0x56 , 0x6D , 0x6D , 0xBE , 0x80 , 0x80, 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x69 , 0x95 , 0x97 , 0x9D , 0x95, 0x95 , 0x8D , 0xC0 , 0x81 , 0x00 , 0x00 , 0x00 , 0x00, 0xC8 , 0x04 , 0x7F , 0xB4 , 0x1D , 0x6A , 0x96 , 0x22, 0xC0 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, 0x00 , 0x00 }; /////////////////////////////////////////////////////////////////End Table // Purpose: Initialize a graphic LCD. This must be called before any // other glcd function is used. // Inputs: The initialization mode // OFF - Turns the LCD off // ON - Turns the LCD on void glcd_init(int1 mode) { // Initialze some pins output_low(GLCD_RST); delay_us(2); output_high(GLCD_RST); //68Type mode delay_us(2); output_low(GLCD_E1); output_low(GLCD_E2); output_low(GLCD_RS); // Set for instruction glcd_writeByte(GLCD_E1, 0b11100010); // software Reset glcd_writeByte(GLCD_E2, 0b11100010); glcd_writeByte(GLCD_E1, 0b10100000); // ADC:右回り出力(正転) glcd_writeByte(GLCD_E2, 0b10100000); glcd_writeByte(GLCD_E1, 0b10100100); // スタティックドライブOFF glcd_writeByte(GLCD_E2, 0b10100100); glcd_writeByte(GLCD_E1, 0b10101001); // 1/32 Duty glcd_writeByte(GLCD_E2, 0b10101001); if(mode == ON) { glcd_writeByte(GLCD_E1, 0b10101111); // Turn the display on glcd_writeByte(GLCD_E2, 0b10101111); } else { glcd_writeByte(GLCD_E1, 0b10101110); // Turn the display off glcd_writeByte(GLCD_E2, 0b10101110); } glcd_fillScreen(OFF); // Clear the display } // Purpose: Draw a line on a graphic LCD using Bresenham's // line drawing algorithm // Inputs: (x1, y1) - the start coordinate // (x2, y2) - the end coordinate // color - ON or OFF // Dependencies: glcd_pixel() void glcd_line(int x1, int y1, int x2, int y2, int1 color) { signed int x, y, addx, addy, dx, dy; signed long P; int i; dx = abs((signed int)(x2 - x1)); dy = abs((signed int)(y2 - y1)); x = x1; y = y1; if(x1 > x2) addx = -1; else addx = 1; if(y1 > y2) addy = -1; else addy = 1; if(dx >= dy) { P = 2*dy - dx; for(i=0; i<=dx; ++i) { glcd_pixel(x, y, color); if(P < 0) { P += 2*dy; x += addx; } else { P += 2*dy - 2*dx; x += addx; y += addy; } } } else { P = 2*dx - dy; for(i=0; i<=dy; ++i) { glcd_pixel(x, y, color); if(P < 0) { P += 2*dx; y += addy; } else { P += 2*dx - 2*dy; x += addx; y += addy; } } } } // Purpose: Draw a rectangle on a graphic LCD // Inputs: (x1, y1) - the start coordinate // (x2, y2) - the end coordinate // fill - YES or NO // color - ON or OFF // Dependencies: glcd_pixel(), glcd_line() void glcd_rect(int x1, int y1, int x2, int y2, int fill, int1 color) { if(fill) { int y, ymax; // Find the y min and max if(y1 < y2) { y = y1; ymax = y2; } else { y = y2; ymax = y1; } for(; y<=ymax; ++y) // Draw lines to fill the rectangle glcd_line(x1, y, x2, y, color); } else { glcd_line(x1, y1, x2, y1, color); // Draw the 4 sides glcd_line(x1, y2, x2, y2, color); glcd_line(x1, y1, x1, y2, color); glcd_line(x2, y1, x2, y2, color); } } // Purpose: Draw a bar (wide line) on a graphic LCD // Inputs: (x1, y1) - the start coordinate // (x2, y2) - the end coordinate // width - The number of pixels wide // color - ON or OFF void glcd_bar(int x1, int y1, int x2, int y2, int width, int1 color) { signed int x, y, addx, addy, j; signed long P, dx, dy, c1, c2; int i; dx = abs((signed int)(x2 - x1)); dy = abs((signed int)(y2 - y1)); x = x1; y = y1; c1 = -dx*x1 - dy*y1; c2 = -dx*x2 - dy*y2; if(x1 > x2) { addx = -1; c1 = -dx*x2 - dy*y2; c2 = -dx*x1 - dy*y1; } else addx = 1; if(y1 > y2) { addy = -1; c1 = -dx*x2 - dy*y2; c2 = -dx*x1 - dy*y1; } else addy = 1; if(dx >= dy) { P = 2*dy - dx; for(i=0; i<=dx; ++i) { for(j=-(width/2); j= 0 && dx*x+dy*(y+j)+c2 <=0) glcd_pixel(x, y+j, color); } if(P < 0) { P += 2*dy; x += addx; } else { P += 2*dy - 2*dx; x += addx; y += addy; } } } else { P = 2*dx - dy; for(i=0; i<=dy; ++i) { if(P < 0) { P += 2*dx; y += addy; } else { P += 2*dx - 2*dy; x += addx; y += addy; } for(j=-(width/2); j= 0 && dx*x+dy*(y+j)+c2 <=0) glcd_pixel(x+j, y, color); } } } } // Purpose: Draw a circle on a graphic LCD // Inputs: (x,y) - the center of the circle // radius - the radius of the circle // fill - YES or NO // color - ON or OFF void glcd_circle(int x, int y, int radius, int1 fill, int1 color) { signed int a, b, P; a = 0; b = radius; P = 1 - radius; do { if(fill) { glcd_line(x-a, y+b, x+a, y+b, color); glcd_line(x-a, y-b, x+a, y-b, color); glcd_line(x-b, y+a, x+b, y+a, color); glcd_line(x-b, y-a, x+b, y-a, color); } else { glcd_pixel(a+x, b+y, color); glcd_pixel(b+x, a+y, color); glcd_pixel(x-a, b+y, color); glcd_pixel(x-b, a+y, color); glcd_pixel(b+x, y-a, color); glcd_pixel(a+x, y-b, color); glcd_pixel(x-a, y-b, color); glcd_pixel(x-b, y-a, color); } if(P < 0) P+= 3 + 2*a++; else P+= 5 + 2*(a++ - b--); } while(a <= b); } // Purpose: Write text on a graphic LCD // Inputs: (x,y) - The upper left coordinate of the first letter // textptr - A pointer to an array of text to display // size - The size of the text: 1 = 5x7, 2 = 10x14, ... // color - ON or OFF void glcd_text57(int x, int y, char* textptr, int size, int1 color) { int i, j, k, l, m; // Loop counters BYTE pixelData[5]; // Stores character data for(i=0; textptr[i] != '\0'; ++i, ++x) // Loop through the passed string { if(textptr[i] < 'S') // Checks if the letter is in the first text array memcpy(pixelData, TEXT[textptr[i]-' '], 5); else if(textptr[i] <= '~') // Check if the letter is in the second array memcpy(pixelData, TEXT2[textptr[i]-'S'], 5); else memcpy(pixelData, TEXT[0], 5); // Default to space if(x+5*size >= GLCD_WIDTH) // Performs character wrapping { x = 0; // Set x at far left position y += 7*size + 1; // Set y at next position down } for(j=0; j<5; ++j, x+=size) // Loop through character byte data { for(k=0; k<7*size; ++k) // Loop through the vertical pixels { if(bit_test(pixelData[j], k)) // Check if the pixel should be set { for(l=0; l 60) // Check for first or second display area { x -= 61; chip = GLCD_E2; } bit_clear(x,7); // Clear the MSB. Part of an instruction code glcd_writeByte(chip, x); // Set the horizontal address glcd_writeByte(chip, (y/8 & 0b10111011) | 0b10111000); // Set the vertical page address output_high(GLCD_RS); // Set for data data = glcd_readByte(chip); if(color == ON) bit_set(data, y%8); // Turn the pixel on else // or bit_clear(data, y%8); // turn the pixel off output_low(GLCD_RS); // Set for instruction glcd_writeByte(chip, x); // Set the horizontal address output_high(GLCD_RS); // Set for data glcd_writeByte(chip, data); // Write the pixel data } // Purpose: Reads a byte of data from the specified chip // Ouputs: A byte of data read from the chip BYTE glcd_readByte(BYTE chip) // Read Data from LCD { int8 Data; if(chip == GLCD_E1) output_high(GLCD_E1); if(chip == GLCD_E2) output_high(GLCD_E2); output_high(GLCD_RW); // Read Data if(chip == GLCD_E1) output_low(GLCD_E1); if(chip == GLCD_E2) output_low(GLCD_E2); delay_cycles(2); set_tris_d(0xff); // Allow LCD to drive the data lines if(chip == GLCD_E1) output_high(GLCD_E1); if(chip == GLCD_E2) output_high(GLCD_E2); delay_cycles(50); Data=input_d(); // Get the data if(chip == GLCD_E1) output_low(GLCD_E1); if(chip == GLCD_E2) output_low(GLCD_E2); delay_cycles(2); set_tris_d(0x00); return(Data); } // Purpose: Write a byte of data to the specified chip // Inputs: chipSelect - which chip to write the data to // data - the byte of data to write void glcd_writeByte(BYTE chip, BYTE data) { output_d(data); // Put the data on the port output_low(GLCD_RW); // Set for writing if(chip == GLCD_E1) // Choose which chip to write to { output_high(GLCD_E1); output_low(GLCD_E1); } else { output_high(GLCD_E2); output_low(GLCD_E2); } output_low(GLCD_E1); // Reset the chip select lines output_low(GLCD_E2); } void set_0_page(int p) //Set horizontal address to 0 P:page 0x00~0x08 { output_low(GLCD_RS); // Set for instruction glcd_writeByte(GLCD_E1, 0b00000000); // Set column address to 0 glcd_writeByte(GLCD_E2, 0b00000000); glcd_writeByte(GLCD_E1, P | 0b10111000); // Set page address glcd_writeByte(GLCD_E2, P | 0b10111000); output_high(GLCD_RS); // Set for data } void bitmap_write() //write bitmap file(122*32dots) { int i; set_0_page(0x00); for(i = 0; i < 61; ++i) // Loop through the horizontal sections glcd_writeByte(GLCD_E1, bitmap1[i]); //Write left side display for(i = 61; i < 122; ++i) glcd_writeByte(GLCD_E2, bitmap1[i]); //Write right side display set_0_page(0x01); for(i = 0; i < 61; ++i) glcd_writeByte(GLCD_E1, bitmap2[i]); for(i = 61; i < 122; ++i) glcd_writeByte(GLCD_E2, bitmap2[i]); set_0_page(0x02); for(i = 0; i < 61; ++i) glcd_writeByte(GLCD_E1, bitmap3[i]); for(i = 61; i < 122; ++i) glcd_writeByte(GLCD_E2, bitmap3[i]); set_0_page(0x03); for(i = 0; i < 61; ++i) glcd_writeByte(GLCD_E1, bitmap4[i]); for(i = 61; i < 122; ++i) glcd_writeByte(GLCD_E2, bitmap4[i]); } #endif