/*********************************************** * グラフィックLCD(128x64ドット)用ライブラリ * lcd_Write(); * lcd_Read(); * lcd_Init(); * lcd_Clear(); * lcd_Pixel(); * lcd_Char(); * lcd_Char1(); * lcd_Str(); * lcd_Line(); * lcd_Kanji(); * KanjiCode(); * Kanji_Str(); * lcd_Image(); * delay_us(); * delay_ms(); * * デバッグ年月日: 2013/4/2 N.Ishii ************************************************/ #include /* PIC32 peripheral library */ #include "glcd_lib32k.h" #include "font.h" #include "KanjiFont12.h" /*************************** データ出力関数 ***************************/ void lcd_Write(char cs, char code, char DIflag){ short data; LCD_RW = 0; // write mode if(cs==1) LCD_CS1 = 0; else LCD_CS2 = 0; data = (unsigned short)code; LCD_DB = (LCD_DB & 0xFF00) | (data & 0x00FF); if (DIflag == 0) LCD_DI = 1; // 表示データの場合 else LCD_DI = 0; // コマンドデータの場合 delay_us(1); // 1usec LCD_E = 1; // strobe out delay_us(1); // pulse width 1usec LCD_E = 0; // reset strobe LCD_CS1 = 1; LCD_CS2 = 1; LCD_RW = 1; delay_us(5); } /***************************** * データ読み出し関数  *****************************/ char lcd_Read(char cs){ short data; LCD_TRIS = 0xFFFFF; // 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 delay_us(1); // 1usec delay LCD_E = 1; // strobe out delay_us(1); // pulse width 1usec LCD_E = 0; // reset strobe delay_us(3); // wait 3usec // data = LCD_DB & 0x00FF; // input data data = PORTE & 0x00FF; // PIC32MXの場合、データリードする時は、PORTとしないと。入力ピンの状態を読めない。 // LATとしてリードすると、LATレジスタに書込んだデータそのものが読出されるので注意を要する。 // 130402 修正 delay_us(1); // wait 1usec LCD_CS1 = 1; // reset CS LCD_CS2 = 1; LCD_TRIS = 0x0000; // back to output mode return((char)data); // return cuurrent status } /*************************** * 画面消去関数 ****************************/ 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); } /**************************** * 初期化関数 *****************************/ void lcd_Init(void){ delay_ms(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(short Xpos, short 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(short x0, short y0, short x1, short y1) { short steep, t; short deltax, deltay, error; short x, y; short ystep; /// 差分の大きいほうを求める steep = (abs(y1 - y0) > abs(x1 - x0)); /// 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; // 傾き計算 deltay = abs(y1 - y0); error = 0; y = y0; /// 傾きでステップの正負を切り替え if(y0 < y1) ystep = 1; else ystep = -1; /// 直線を点で描画 for(x=x0; x= deltax) { y += ystep; error -= deltax; } } } /************************* * 漢字文字表示関数 **************************/ short lcd_Kanji(char line, char colum, char *ptr) { unsigned char low, high; high = *ptr++; low = *ptr; // 漢字範囲チェックと表示 if(((high > 0x80) && (high < 0xA0)) || ((high > 0xDF) && (high < 0xEB))) { if((low > 0x3F) && (low < 0xFD) && (low != 0x7F)) { KanjiCode(line, colum, high, low); return(0); } else return(-1); } else return(-1); } /************************** * 漢字表示 コード指定 **************************/ void KanjiCode(char line, char colum, unsigned char upcode, unsigned char lowcode) { char cs; short upper, lower, i, j, pos; if((line < 8) && (colum < 10)){ // 画面内か? if(colum > 4){ // 5カラム以降か? pos = (colum- 5) * 13; // 1文字13ドット幅とする cs = 1; // 右側表示部 } else{ pos = colum * 13; // 1文字13ドット幅 cs = 2; // 左側表示部 } // 漢字コードから配列インデックス計算 upper = (short)(upcode -0x81)*188; // xxFC-xx40+1-1(7F分) if(lowcode < 0x7F) // コード7Fはスキップ lower = (short)(lowcode - 0x40); else lower = (short)(lowcode - 0x41); // 7Fコードの1文字分を引く // 漢字表示出力 lcd_Write(cs, 0xB8+line, 1); // ページのセット lcd_Write(cs, 0x40+pos, 1); // カラムのセット // 上側8ドット分出力 for(i=0; i<12; i++) // 上側12ドット表示 lcd_Write(cs, KanjiFont12[upper + lower][i], 0); // 下側4ドット分出力(その下に4ドットスペース) lcd_Write(cs, 0xB8+line+1, 1); // 次の行を指定 lcd_Write(cs, 0x40+pos, 1); // カラムのセット for(i=12; i<23; i++) // 下側12ドット表示 lcd_Write(cs, KanjiFont12[upper + lower][i], 0); } } /********************************************************* * 漢字文字列表示 * 10文字×4行で指定 * * 130320 追加 N.Ishii *********************************************************/ void Kanji_Str(char line, char colum, const short* ptr) { while(*ptr){ if((line < 8) && (colum < 10)){ // 画面内か? KanjiCode(line, colum++, (short)*ptr++, (short)*ptr++); if(colum > 9){ line= line + 2; colum = 0; if(line > 7) line = 0; } } } } /************************* * 文字表示関数 * (0, 0) - (7, 15) **************************/ void lcd_Char(char line, char colum, short letter){ char cs, i; short 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); } } /************************* * 文字表示関数2 7x8 * (0, 0) - (7, 17) **************************/ void lcd_Char1(char line, char colum, short letter){ char cs, i; short 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); } } /****************************** * 文字列描画関数 ******************************/ void lcd_Str(char line, char colum, char *s) { while (*s) lcd_Char1(line, colum++, *s++); } /***************************** * イメージ表示関数 *****************************/ void lcd_Image(char *ptr) { char cs, Xpos; short 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); } } } /********************************* * スクロール関数 ***********************************/ void lcd_Scroll(unsigned short delay){ short i; for(i=0; i<64; i++){ lcd_Write(1, 0xC0+i,1); lcd_Write(2, 0xC0+i,1); delay_ms(delay); } } /********************************** * ループ遅延関数 usec単位 **********************************/ void delay_us(unsigned short usec) { unsigned short i, Max; Max = usec * 640/Fosc; for(i=0; i