// 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 // Date: 5/28/2003 void glcd_init(int1 mode) { // Initialze some pins output_HIGH(GLCD_RST); output_low(GLCD_E); output_low(GLCD_CS1); output_low(GLCD_CS2); output_low(GLCD_DI); // Set for instruction glcd_writeByte(GLCD_CS1, 0xC0); // Specify first RAM line at the top glcd_writeByte(GLCD_CS2, 0xC0); // of the screen glcd_writeByte(GLCD_CS1, 0x40); // Set the column address to 0 glcd_writeByte(GLCD_CS2, 0x40); glcd_writeByte(GLCD_CS1, 0xB8); // Set the page address to 0 glcd_writeByte(GLCD_CS2, 0xB8); if(mode == ON) { glcd_writeByte(GLCD_CS1, 0x3F); // Turn the display on glcd_writeByte(GLCD_CS2, 0x3F); } else { glcd_writeByte(GLCD_CS1, 0x3E); // Turn the display off glcd_writeByte(GLCD_CS2, 0x3E); } glcd_fillScreen(OFF); // Clear the display }
// Purpose: Turn a pixel on a graphic LCD on or off // Inputs: x - the x coordinate of the pixel // y - the y coordinate of the pixel // color - ON or OFF // Output: 1 if coordinate out of range, 0 if in range void glcd_pixel(int x, int y, int1 color) { BYTE data; BYTE chip = GLCD_CS1; // Stores which chip to use on the LCD if(x > 63) // Check for first or second display area { x -= 64; chip = GLCD_CS2; } output_low(GLCD_DI); // Set for instruction bit_clear(x,7); // Clear the MSB. Part of an instruction code bit_set(x,6); // Set bit 6. Also part of an instruction code glcd_writeByte(chip, x); // Set the horizontal address glcd_writeByte(chip, (y/8 & 0b10111111) | 0b10111000); // Set the vertical page address output_high(GLCD_DI); // 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_DI); // Set for instruction glcd_writeByte(chip, x); // Set the horizontal address output_high(GLCD_DI); // Set for data glcd_writeByte(chip, data); // Write the pixel data }
void glcd_showimage2() { int16 n=0; int i,j; int1 cs=0; // Loop through the vertical pages for(i = 0; i <8; ++i) { output_low(GLCD_DI); // Set for instruction glcd_writeByte(GLCD_LEFT, 0b01000000); // Set horizontal address to 0 glcd_writeByte(GLCD_RIGHT, 0b01000000); glcd_writeByte(GLCD_LEFT, i | 0b10111000);// Set page address glcd_writeByte(GLCD_RIGHT, i | 0b10111000); output_high(GLCD_DI); // Set for data // Loop through the horizontal sections for(j = 0; j < 128;++j) { if(j<64) cs=GLCD_LEFT;else cs=GLCD_RIGHT; glcd_writeByte(cs,sun[n]); // Turn pixels on or off //delay_us(5); n++; } } }
// Purpose: Initialize the LCD. // Call before using any other LCD function. // Inputs: OFF - Turns the LCD off // ON - Turns the LCD on void glcd_init(int mode) { low_Enable; low_CS1; low_CS2; low_DI; glcd_writeByte(GLCD_LEFT, 0xC0); // Specify first RAM line at the top glcd_writeByte(GLCD_RIGHT, 0xC0); // of the screen glcd_writeByte(GLCD_LEFT, 0x40); // Set the column address to 0 glcd_writeByte(GLCD_RIGHT, 0x40); glcd_writeByte(GLCD_LEFT, 0xB8); // Set the page address to 0 glcd_writeByte(GLCD_RIGHT, 0xB8); if(mode == ON) { glcd_writeByte(GLCD_LEFT, 0x3F); // Turn the display on glcd_writeByte(GLCD_RIGHT, 0x3F); } else { glcd_writeByte(GLCD_LEFT, 0x3E); // Turn the display off glcd_writeByte(GLCD_RIGHT, 0x3E); } glcd_fillScreen(OFF); // Clear the display glcd_update(); }
void glcd_image(long mempointer /*This is the image location in program memory*/) { int j, i; int page = 0xB8; char chipsel; char buffer[1]; output_low(GLCD_DI); // Set for instruction glcd_writeByte(GLCD_CS1, 0x40); // Set the column address to 0 glcd_writeByte(GLCD_CS2, 0x40); glcd_writeByte(GLCD_CS1, page); // Set the page address to 0 glcd_writeByte(GLCD_CS2, page); for (j = 0; j < 8; j++, page+=1) { output_low(GLCD_DI); glcd_writeByte(GLCD_CS1, page); glcd_writeByte(GLCD_CS2, page); for (i = 0; i < 128; i++) { if ( i < 64) { chipsel = GLCD_CS1; } else { chipsel = GLCD_CS2; } read_program_memory(mempointer, buffer, 1); mempointer++; output_high(GLCD_DI); glcd_writeByte(chipsel, *buffer); } } }
void glcd_update() { unsigned int8 i, j; unsigned int8 *p1, *p2; p1 = displayData.left; p2 = displayData.right; // Loop through the vertical pages for(i = 0; i < 8; ++i) { output_low(GLCD_DI); // Set for instruction glcd_writeByte(GLCD_LEFT, 0x40); // Set horizontal address to 0 glcd_writeByte(GLCD_RIGHT, 0x40); glcd_writeByte(GLCD_LEFT, i | 0xB8); // Set page address glcd_writeByte(GLCD_RIGHT, i | 0xB8); output_high(GLCD_DI); // Set for data // Loop through the horizontal sections for(j = 0; j < 64; ++j) { glcd_writeByte(GLCD_LEFT, *p1++); // Turn pixels on or off glcd_writeByte(GLCD_RIGHT, *p2++); // Turn pixels on or off } } }
// Purpose: Update the LCD with data from the display arrays void glcd_update() { int i, j; int *p1, *p2; p1 = displayData.left; p2 = displayData.right; // Loop through the vertical pages for(i = 0; i < 8; ++i) { low_DI; glcd_writeByte(GLCD_LEFT, 0x40); // Set horizontal address to 0 glcd_writeByte(GLCD_RIGHT, 0x40); glcd_writeByte(GLCD_LEFT, i | 0xB8); // Set page address glcd_writeByte(GLCD_RIGHT, i | 0xB8); high_DI; // Loop through the horizontal sections for(j = 0; j < 64; ++j) { glcd_writeByte(GLCD_LEFT, *p1++); // Turn pixels on or off glcd_writeByte(GLCD_RIGHT, *p2++); // Turn pixels on or off } } }
// Purpose: Fill the LCD screen with the passed in color. // Works much faster than drawing a rectangle to fill the screen. // Inputs: ON - turn all the pixels on // OFF - turn all the pixels off // Dependencies: glcd_writeByte() void glcd_fillScreen(int1 color) { int i, j; // Loop through the vertical pages for(i = 0; i < 8; ++i) { output_low(GLCD_DI); // Set for instruction glcd_writeByte(GLCD_CS1, 0b01000000); // Set horizontal address to 0 glcd_writeByte(GLCD_CS2, 0b01000000); glcd_writeByte(GLCD_CS1, i | 0b10111000); // Set page address glcd_writeByte(GLCD_CS2, i | 0b10111000); output_high(GLCD_DI); // Set for data // Loop through the horizontal sections for(j = 0; j < 64; ++j) { glcd_writeByte(GLCD_CS1, 0xFF*color); // Turn pixels on or off glcd_writeByte(GLCD_CS2, 0xFF*color); // Turn pixels on or off } } }