You are on page 1of 3

#include <8052.

h> __sfr __at (0xA1) P4; #define #define #define #define #define #define #define RST LCD_RS LCD_CS LCD_SCL LCD_SDA PAGE_SEL COL_SEL P2_2 P2_1 P2_3 1 4 0xB0 0x10

#ifdef CONFIG_LARGE_MEMORY static unsigned char gfx_buf[8][128]; int _sdcc_external_startup() { __sfr __at (0x8E) AUXR; AUXR = 0x0; return 0; } #endif void delay(int x) { int n,j; for(n = 0; n < x; n++) for(j = 0; j <= 50; j++); } void glcd_write_data(unsigned char dat) { unsigned char maskdata = 0x80; LCD_CS = 0; LCD_RS = 1; while (maskdata) { P4 = P4 & ~LCD_SCL; if (dat & maskdata) P4 = P4 | LCD_SDA; else P4 = P4 & ~LCD_SDA; maskdata >>= 1; delay(200); P4 = P4 | LCD_SCL; } LCD_CS = 1; } void glcd_write_cmd(unsigned char cmd) { unsigned char maskdata = 0x80;

LCD_RS = 0; LCD_CS = 0; while (maskdata) { P4 = P4 & ~LCD_SCL; if (cmd & maskdata) P4 = P4 | LCD_SDA; else P4 = P4 & ~LCD_SDA; maskdata >>= 1; delay(2); P4 = P4 | LCD_SCL ; } LCD_CS = 1; } void glcd_init(void) { RST = 0; delay(1000); RST = 1; glcd_write_cmd(0xE2); glcd_write_cmd(0xA3); glcd_write_cmd(0xAF); glcd_write_cmd(0xA0); glcd_write_cmd(0xC8); glcd_write_cmd(0x22); glcd_write_cmd(0x81); glcd_write_cmd(0x2f); glcd_write_cmd(0x2f); glcd_write_cmd(0x40); glcd_write_cmd(0xB0); glcd_write_cmd(0x10); glcd_write_cmd(0x00); glcd_write_cmd(0xAF); glcd_write_cmd(0xA4); glcd_write_cmd(0xA6); } void glcd_set_pixel(int x, int y, int color) { int page,col; int row_in_page; page = y / 8; /* Selecting Page */ glcd_write_cmd(PAGE_SEL | page); /* Selecting Column */ col = ((x & 0xF0) >> 4) | 0x10; glcd_write_cmd(COL_SEL|col); // // // // // // // // // // // // // // // // S/W RESWT LCD bias Display ON segment direction. Common Direction. Regultion resistor select //25 EV Select. Select EV value. Power control Initial display line 40 Set page address Set coloumn addr MSB Set coloumn addr LSB Display ON A5 .Normal display, all pixels OFF. A7 .Normal display (Inverse Pixel)

glcd_write_cmd(x & 0xf); /* Pixel location */ row_in_page = y % 8; #ifdef CONFIG_LARGE_MEMORY if (color) gfx_buf[page][col] |= 1 << row_in_page; else gfx_buf[page][col] &= ~(1 << row_in_page); glcd_write_data(gfx_buf[page][col]); #else if (color) glcd_write_data(1 << row_in_page); #endif } int main() { int i = 0, j = 0; glcd_init(); for (i = 0; i < 128; i++) for (j = 0; j < 64; j++) glcd_set_pixel(i, j, 1); return 0; }

You might also like