/*********************************************** * GLCD(128 x 64dot) Library * * lcd_Write(); * lcd_Read(); * lcd_Init(); * lcd_Clear(); * lcd_Pixel(); * lcd_Char(); * lcd_Char1(); * lcd_Str(); * lcd_Line(); * lcd_Image(); * Delay200n(); * Delay1u(); * Delay1m(); * * CPU: PIC24HJ64GP206 * Original Program: Mr.Gokan (CPU;PIC24HJ12GP202) * Mod. N.Ishii 2012.3.7 ************************************************/ //#include //#include "glcd_lib.h" #include #include "glcd_lib_pic24hj64.h" #include "font.h" /*************************** Data Out ***************************/ void lcd_Write(char cs, char code, char DIflag){ int data; LCD_RW = 0; // write mode if(cs==1) LCD_CS1 = 0; else LCD_CS2 = 0; data = (int)code; LCD_DB = (LCD_DB & 0x00FF) | ((data << 8) & 0xFF00); if (DIflag == 0) LCD_DI = 1; // Case Draw Data else LCD_DI = 0; // Case Command Data Delay1u(1); // 1usec LCD_E = 1; // strobe out Delay1u(1); // pulse width 1usec LCD_E = 0; // reset strobe LCD_CS1 = 1; LCD_CS2 = 1; LCD_RW = 1; Delay1u(5); } /***************************** * Read Data *****************************/ char lcd_Read(char cs){ int data; LCD_TRIS = 0xFFFF; // chane to input mode LCD_RW = 1; // set read mode if(cs==1) // CS1 or CS2? LCD_CS1 = 0; else LCD_CS2 = 0; LCD_DI = 1; // set data mode Delay1u(1); // 1usec delay LCD_E = 1; // strobe out Delay1u(1); // pulse width 1usec LCD_E = 0; // reset strobe Delay1u(3); // wait 3usec data = (LCD_DB >> 8)&0x00FF; // input data Delay1u(1); // wait 1usec LCD_CS1 = 1; // reset CS LCD_CS2 = 1; LCD_TRIS = 0x00FF; // back to output mode return((char)data); // return cuurrent status } /*************************** * Clear Screen ****************************/ void lcd_Clear(char data){ char page, colum; for(page=0; page<8; page++){ // repeat 8 page lcd_Write(1, 0xB8+page, 1); // page set lcd_Write(1, 0x40, 1); // colum reset lcd_Write(2, 0xB8+page, 1); // page set lcd_Write(2, 0x40, 1); // colum reset for(colum=0; colum<64; colum++){ // repeat 64 colum lcd_Write(1, data, 0); // fill data lcd_Write(2, data, 0); // fill data } } lcd_Write(1, 0xC0, 1); // reset start line lcd_Write(2, 0xC0, 1); } /**************************** * Inittalize GLCD *****************************/ void lcd_Init(void){ Delay1m(10); lcd_Write(1, 0x3F, 1); // Display on lcd_Write(2, 0x3F, 1); // Display on lcd_Clear(0); } /**************************** * Draw Piccel Function * (0,0)-(127,63) *****************************/ void lcd_Pixel(int Xpos, int Ypos, char On){ char cs, data, page, pos, count, i; /* if colum >127 then do nothing */ if(Xpos<128){ if(Xpos>63){ // 64=0) ? (a) : -(a)) void lcd_Line(int x0, int y0, int x1, int y1) { int steep, t; int deltax, deltay, error; int x, y; int ystep; /// Find Larger Delta steep = (abs(y1 - y0) > abs(x1 - x0)); /// Swap x, y if(steep){ t = x0; x0 = y0; y0 = t; t = x1; x1 = y1; y1 = t; } if(x0 > x1) { t = x0; x0 = x1; x1 = t; t = y0; y0 = y1; y1 = t; } deltax = x1 - x0; // Calculatean inclination deltay = abs(y1 - y0); error = 0; y = y0; /// Switching Polar at delta if(y0 < y1) ystep = 1; else ystep = -1; /// Drawing Sstraight Line for(x=x0; x= deltax) { y += ystep; error -= deltax; } } } /************************* * Indicate Character * (0, 0) - (7, 15) **************************/ void lcd_Char(char line, char colum, int letter){ char cs, i; int pos; if(colum < 16){ if(colum > 7){ pos = (colum- 8) * 8; cs = 1; } else{ pos = colum * 8; cs = 2; } lcd_Write(cs, 0xB8+line, 1); // set page lcd_Write(cs, 0x40+pos, 1); // set colum for(i=0; i<5; i++) lcd_Write(cs, Font[letter-0x20][i], 0); lcd_Write(cs, 0, 0); lcd_Write(cs, 0, 0); lcd_Write(cs, 0, 0); } } /************************* * Indicate Character2 7x8 * (0, 0) - (7, 17) **************************/ void lcd_Char1(char line, char colum, int letter){ char cs, i; int pos; if(colum < 18){ if(colum > 8){ pos = (colum- 9) * 7; cs = 1; } else{ pos = colum * 7; cs = 2; } lcd_Write(cs, 0xB8+line, 1); // set page lcd_Write(cs, 0x40+pos, 1); // set colum for(i=0; i<5; i++) lcd_Write(cs, Font[letter-0x20][i], 0); lcd_Write(cs, 0, 0); lcd_Write(cs, 0, 0); } } /****************************** * Indicate Strings Character ******************************/ void lcd_Str(char line, char colum, char *s) { while (*s) lcd_Char1(line, colum++, *s++); } /***************************** * Drawing Image *****************************/ void lcd_Image(char *ptr) { char cs, Xpos; int page, colum; for(page=0; page<8; page++){ for(colum=0; colum<128; colum++){ if(colum > 63){ Xpos=colum-64; cs = 1; } else{ Xpos = colum; cs = 2; } lcd_Write(cs, 0xB8+page, 1); lcd_Write(cs, 0x40+Xpos, 1); lcd_Write(cs, *ptr++, 0); } } } /********************************* * Scroll ***********************************/ void lcd_Scroll(int delay){ int i; for(i=0; i<64; i++){ lcd_Write(1, 0xC0+i,1); lcd_Write(2, 0xC0+i,1); Delay1m(delay); } } /****************************************** * Delay ******************************************/ /** 1msec Delay SubFunction at 40MIPS ***/ void Delay1m(int time){ while(time > 0){ Delay1u(1000); time--; } } /** 1usec Delay SubFunction at 40MIPS ****/ void Delay1u(int time){ while(time > 0){ time--; Delay200n(); Delay200n(); Delay200n(); Delay200n(); Nop(); Nop(); Nop(); Nop(); } } /****** 200nsec delay sub function ***/ void Delay200n(void){ }