/*************************************************************** * SPI制御モノクロ・グラフィック液晶用ライブラリ: AQM1248A_Lib.c * (WAV Player V2用) * MPU:dsPIC33FJ64GP802 * * ※「はじめてのPIC」サイトの、岩本さんが作成されたライブラリを元に、モディファイしました。 * 修正過程のコメント等は、出来るだけ削除整理した形でまとめました。 *   尚、オリジナルの、MPUは、PIC18F14K50で、MSSP SPI機能を使っています。 * それを単純ポートアクセスでの、SPI記述に変更しました。 * * 2015/11/4 N.Ishii *****************************************************************/ #include "p33FJ64GP802.h" #include "AQM1248A_Lib.h" #include "ASCII_font.h" /********************************************************* * 遅延関数 1msec 1usec @40MMHz **********************************************************/ void Delay_ms( unsigned int t){ T2CON = 0x8000; // enable tmr2, Tcy, 1:1 while (t--) { TMR2 = 0; while (TMR2<40000); } } void Delayus(unsigned int t) { T2CON = 0x8000; while(t--){ TMR2 = 0; while(TMR2 < 40); } } /***************************** * G-LCDを初期化する ******************************/ void LCD_int (void){ LCD_cmd (0xAE); // Display = OFF LCD_cmd (0xA0); // ADC = normal LCD_cmd (0xC8); // Common output = revers LCD_cmd (0xA3); // bias = 1/7 //--内部レギュレータを順番にON LCD_cmd (0x2C); // power control 1 Delay_ms(2); LCD_cmd (0x2E); // power control 2 Delay_ms(2); LCD_cmd (0x2F); // power control 3 //--コントラスト設定 LCD_cmd (0x23); // Vo voltage resistor ratio set LCD_cmd (0x81); // Electronic volume mode set LCD_cmd (0x1C); // Electronic volume value set //--表示設定 LCD_cmd (0xA4); // display all point normal(全点灯しない) LCD_cmd (0x40); // display start line = 0 LCD_cmd (0xA6); // Display normal(白黒反転しない) LCD_cmd (0xAF); // Display = ON LCD_clr (); // データRAMを全消去 } /************************************ * G-LCDにコマンドを一文字送信する *************************************/ void LCD_cmd (char cmd){ unsigned char i, Mask; SPI_CS = 0; // チップセレクト有効 SPI_RS = 0; // コマンドデータ指定 Mask = 0x80; // 上位ビットより for(i=0; i<8; i++){ SPI_SCK = 0; if((cmd & Mask) != 0) SPI_SDI = 1; else SPI_SDI = 0; SPI_SCK = 1; Mask = Mask >> 1; } SPI_CS = 1; // チップセレクト無効 } /************************************ * G-LCD RAMに一バイト送信する *************************************/ void LCD_ram (char dat){ unsigned char i, Mask; SPI_CS = 0; // チップセレクト有効 SPI_RS = 1; // 表示データ指定 Mask = 0x80; // 上位ビットより for(i=0; i<8; i++){ SPI_SCK = 0; if((dat & Mask) != 0) SPI_SDI = 1; else SPI_SDI = 0; SPI_SCK = 1; Mask = Mask >> 1; } SPI_CS = 1; // チップセレクト無効 } /********************************* * G-LCDに一文字表示する **********************************/ void LCD_dat (unsigned char dat){ unsigned char i,chptn; dat -= 0x20; //配列アドレスを計算 for(i=0; i<5; i++) { //コラムデータを順に取得 chptn = chrom[dat][i]; LCD_ram(chptn); //コラムデータを転送 } LCD_ram(0); //文字間隔を空ける } //=========================================================================== /********************************* * G-LCDのデータを全消去する **********************************/ void LCD_clr (void){ unsigned char i,j; for(j=0; j<8; j++) { //ページを更新 LCD_posyx (j,0); //ページを指定 for(i=0; i<128; i++) { //ページ内RAMデータを順に LCD_ram (0); // クリア } } } /******************************** * カーソル位置指定 *********************************/ void LCD_posyx(char ypos, unsigned char xpos){ LCD_cmd(0xB0 | ypos); //ページを指定 LCD_cmd(0x10 | (xpos >> 4)); //ページ内RAMアドレスを LCD_cmd(xpos & 0xF); // 分割し指定 } /************************** * 文字列出力 ***************************/ void LCD_str(char *str){ while(*str) //文字列終端(00)まで継続 LCD_dat(*str++); //文字出力しポインタ+1 } /**************************** * Rom 文字列出力 *****************************/ void LCD_ROMstr(const char *str){ while(*str) //文字列終端(00)まで継続 LCD_dat(*str++); //文字出力しポインタ+1 } /****************************************************** * 文字表示 * 文字コード、表示位置(ypos, xpos)を指定する。 * 文字を表示後、次の表示開始位置 xpos を返す *******************************************************/ unsigned char LCD_chr1x(unsigned char dat, char ypos, unsigned char xpos){ unsigned char i,chptn; dat -= 0x20; //配列アドレスを計算 LCD_posyx( ypos, xpos); //上半分の表示位置を指定 for(i=0; i<5; i++) { //コラムデータを順に取得 chptn = chrom[dat][i]; LCD_ram(chptn); //コラムデータを転送 } LCD_ram(0); //文字間隔を空ける return i + 1 + xpos; //次の表示開始位置 xpos を返す } /******************************************************** * 文字列表示 * 文字列アドレス、表示位置(ypos, xpos)を指定する。 * 文字を表示後、次の表示開始位置 xpos を返す *********************************************************/ unsigned char LCD_str1x(char *str, char ypos, unsigned char xpos){ while(*str) //文字列終端(00)まで継続 xpos = LCD_chr1x(*str++, ypos, xpos); //文字出力し return xpos; //次表示位置を返す } /******************************************************** * 文字列表示 ROMエリア * 文字列アドレス、表示位置(ypos, xpos)を指定する。 * 文字を表示後、次の表示開始位置 xpos を返す *********************************************************/ unsigned char LCD_ROMstr1x(const char *str, char ypos, unsigned char xpos){ while(*str) //文字列終端(00)まで継続 xpos = LCD_chr1x(*str++, ypos, xpos); //文字出力しポインタ+1 return xpos; //次表示位置を返す } /********************************************************* * 拡大文字表示 * 文字コード、表示位置(ypos, xpos)を指定する。 * x2 サイズで文字を表示後、次の表示開始位置 xpos を返す **********************************************************/ unsigned char LCD_chr2x(unsigned char dat, char ypos, unsigned char xpos){ unsigned char wch,fnt,i; dat -= 0x20; //配列アドレスを計算 LCD_posyx( ypos, xpos); //上半分の表示位置を指定 for(i=0;i<5;i++){ // wch = chrom[dat][i]; //キャラクタデータのLSB 4bit if(wch == 0xFF)break; //情報を拡大してLCD RAMに転送 fnt = 0; if(wch & 0b00000001)fnt = 0b00000011; if(wch & 0b00000010)fnt |= 0b00001100; if(wch & 0b00000100)fnt |= 0b00110000; if(wch & 0b00001000)fnt |= 0b11000000; LCD_ram(fnt); LCD_ram(fnt); } LCD_ram(0); LCD_ram(0); LCD_posyx( ypos + 1, xpos); //下半分の表示位置を指定 for(i=0;i<5;i++){ // wch = chrom[dat][i]; //キャラクタデータのMSB 4bit if(wch == 0xFF)break; //情報を拡大してLCD RAMに転送 fnt = 0; if(wch & 0b00010000)fnt = 0b00000011; if(wch & 0b00100000)fnt |= 0b00001100; if(wch & 0b01000000)fnt |= 0b00110000; if(wch & 0b10000000)fnt |= 0b11000000; LCD_ram(fnt); LCD_ram(fnt); } LCD_ram(0); LCD_ram(0); return (i + 1) * 2 + xpos; //次の表示開始位置 xpos を返す } /*************************************************************** * 拡大文字列表示 * 文字列アドレス、表示位置(ypos, xpos)を指定する。 * x2 サイズで文字を表示後、次の表示開始位置 xpos を返す ****************************************************************/ unsigned char LCD_str2x(char *str, char ypos, unsigned char xpos){ while(*str) //文字列終端(00)まで継続 xpos = LCD_chr2x(*str++, ypos, xpos); //文字出力し return xpos; //次表示位置を返す } /*************************************************************** * 拡大文字列表示 ROMエリア * 文字列アドレス、表示位置(ypos, xpos)を指定する。 * x2 サイズで文字を表示後、次の表示開始位置 xpos を返す ****************************************************************/ unsigned char LCD_ROMstr2x(const char *str, char ypos, unsigned char xpos){ while(*str) //文字列終端(00)まで継続 xpos = LCD_chr2x(*str++, ypos, xpos); //文字出力しポインタ+1 return xpos; //次表示位置を返す } /**************************************************************** * 3倍拡大文字表示 Tri Font * 文字コード、表示位置(ypos, xpos)を指定する。 * x3 サイズで文字を表示後、次の表示開始位置 xpos を返す *****************************************************************/ unsigned char LCD_chr3x(unsigned char dat, char ypos, unsigned char xpos){ unsigned char wch,fnt,i; dat -= 0x20; //配列アドレスを計算 LCD_posyx( ypos, xpos); //上半分の表示位置を指定 for(i=0;i<5;i++){ // wch = chrom[dat][i]; //キャラクタデータのLSB 4bit if(wch == 0xFF)break; //情報を拡大してLCD RAMに転送 fnt = 0; if(wch & 0b00000001)fnt = 0b00000111; if(wch & 0b00000010)fnt |= 0b00111000; if(wch & 0b00000100)fnt |= 0b11000000; LCD_ram(fnt); LCD_ram(fnt); LCD_ram(fnt); } LCD_posyx( ypos + 1, xpos); //下半分の表示位置を指定 for(i=0;i<5;i++){ // wch = chrom[dat][i]; //キャラクタデータのMSB 4bit if(wch == 0xFF)break; //情報を拡大してLCD RAMに転送 fnt = 0; if(wch & 0b00000100)fnt |= 0b00000001; if(wch & 0b00001000)fnt |= 0b00001110; if(wch & 0b00010000)fnt |= 0b01110000; if(wch & 0b00100000)fnt |= 0b10000000; LCD_ram(fnt); LCD_ram(fnt); LCD_ram(fnt); } LCD_posyx( ypos + 2, xpos); //下半分の表示位置を指定 for(i=0;i<5;i++){ // wch = chrom[dat][i]; //キャラクタデータのMSB 4bit if(wch == 0xFF)break; //情報を拡大してLCD RAMに転送 fnt = 0; if(wch & 0b00100000)fnt |= 0b00000011; if(wch & 0b01000000)fnt |= 0b00011100; if(wch & 0b10000000)fnt |= 0b11100000; LCD_ram(fnt); LCD_ram(fnt); LCD_ram(fnt); } LCD_ram(0); LCD_ram(0); LCD_ram(0); return (i + 1) * 3 + xpos; //次の表示開始位置 xpos を返す } /***************************************************************** * 3倍拡大文字列表示 * 文字列アドレス、表示位置(ypos, xpos)を指定する。 * x3 サイズで文字を表示後、次の表示開始位置 xpos を返す ******************************************************************/ unsigned char LCD_str3x(char *str, char ypos, unsigned char xpos){ while(*str) //文字列終端(00)まで継続 xpos = LCD_chr3x(*str++, ypos, xpos); //文字出力し return xpos; //次表示位置を返す } /*************************************************************** * 3倍拡大文字列表示 ROMエリア * 文字列アドレス、表示位置(ypos, xpos)を指定する。 * x3 サイズで文字を表示後、次の表示開始位置 xpos を返す ****************************************************************/ unsigned char LCD_ROMstr3x(const char *str, char ypos, unsigned char xpos){ while(*str) //文字列終端(00)まで継続 xpos = LCD_chr3x(*str++, ypos, xpos); //文字出力しポインタ+1 return xpos; //次表示位置を返す }