文書の表示以前のリビジョンバックリンクPDF の出力全て展開する/折り畳むODT 出力文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== CGRAM活用(キャラクタ表示LCD) ====== ===== 概要 ===== LCD(Liquid Crystal Display:液晶ディスプレイ)には、CGRAM(Character Generator RAM)が用意されており、これを使うことによって、独自のキャラクタを表示させることが出来ます。 今回は、7チャンネル分のアナログデータを、LCDにバー表示させてみました。 ===== 動作原理 ===== <キャラクタコードとキャラクタパターンの関係> 独自のキャラクタは、キャラクタコード(0x00~0x07)に8個分割り当てられています。 {{:imgpaste:202004:htmikan-20200430-090241.png?500}} <キャラクタコード(0x00~0x07)とCGRAMアドレスとCGRAMデータの関係> キャラクタデータは、8バイト×5個で一組となります。 次の例では、キャラクタコード(0x00)に、“R"という文字、キャラクタコード(0x01)に、“\"という文字を登録した場合の内容です。 {{:imgpaste:202004:htmikan-20200430-090328.png}} <制御コマンド> セットCGRAMアドレスコマンドで、CGRAMのアドレスを指定して、以降は順次キャラクタデータを書き込んでいきます。 {{:imgpaste:202004:htmikan-20200430-090335.png}} <実際の表示> 通常の文字表示と同じです。 * 標準キャラクタの表示\\ LCD_Chr(1, 1, 'A');\\ LCD_Chr(1, 2, 0x30'); * 独自キャラクタの表示\\ LCD_Chr(2, 1, 0x00);\\ LCD_Chr(2, 2, 0x07); <mikroC付属のキャラクタデータ生成ツール> 手計算でキャラクタデータを設定しても良いのですが、結構面倒くさい作業になります。 このツールを使うことにより、視覚的にキャラクタデータを設定することが出来るので便利です。 {{:imgpaste:202004:htmikan-20200430-090354.png}} GENERATE(生成)ボタンを押すとキャラクタデータの登録&表示関数を自動的に生成します。 これをプログラムにコピーして使います。 {{:imgpaste:202004:htmikan-20200430-090404.png}} ===== 回路図 ===== {{:imgpaste:202004:htmikan-20200430-090420.png}} ===== ソースコード ===== <code c cgramTest.c> //********************************************************************** /* 『CGRAM活用(キャラクタ表示LCD)』 */ //********************************************************************** const char character1[] = {0,0,0,0,0,0,0,31}; const char character2[] = {0,0,0,0,0,0,31,31}; const char character3[] = {0,0,0,0,0,31,31,31}; const char character4[] = {0,0,0,0,31,31,31,31}; const char character5[] = {0,0,0,31,31,31,31,31}; const char character6[] = {0,0,31,31,31,31,31,31}; const char character7[] = {0,31,31,31,31,31,31,31}; const char character8[] = {31,31,31,31,31,31,31,31}; void RegistCustomChar() { char i; // LCD_Cmd(64); for (i = 0; i<=7; i++) { LCD_Chr_Cp(character1[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character2[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character3[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character4[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character5[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character6[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character7[i]); } for (i = 0; i<=7; i++) { LCD_Chr_Cp(character8[i]); } LCD_Cmd(LCD_RETURN_HOME); } //********************************************************************** void BarDisp(char index, int dat) { switch (dat / 64) { case 0: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 0); break; case 1: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 1); break; case 2: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 2); break; case 3: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 3); break; case 4: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 4); break; case 5: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 5); break; case 6: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 6); break; case 7: Lcd_Chr(1, index, ' '); Lcd_Chr(2, index, 7); break; case 8: Lcd_Chr(1, index, 0); Lcd_Chr(2, index, 7); break; case 9: Lcd_Chr(1, index, 1); Lcd_Chr(2, index, 7); break; case 10: Lcd_Chr(1, index, 2); Lcd_Chr(2, index, 7); break; case 11: Lcd_Chr(1, index, 3); Lcd_Chr(2, index, 7); break; case 12: Lcd_Chr(1, index, 4); Lcd_Chr(2, index, 7); break; case 13: Lcd_Chr(1, index, 5); Lcd_Chr(2, index, 7); break; case 14: Lcd_Chr(1, index, 6); Lcd_Chr(2, index, 7); break; case 15: Lcd_Chr(1, index, 7); Lcd_Chr(2, index, 7); break; } } //********************************************************************** void main() { int dat0, dat1, dat2, dat3, dat4, dat5, dat6; char buf[6]; // OSCCON = 0b01110000; // クロックは8Mhz CMCON = 0b00000111; // コンパレータは使用しない。 ANSEL = 0b01111111; // A/D変換を使用する。 TRISA = 0b11111111; TRISB = 0b11000000; //LCDの初期化 Lcd_Config(&PORTB, 3, 1, 2, 0, 2, 5, 4); RegistCustomChar(); Lcd_Cmd(LCD_CURSOR_OFF); Lcd_Cmd(LCD_CLEAR); // while (1) { BarDisp(1, dat0 = Adc_Read(0)); BarDisp(2, dat1 = Adc_Read(1)); BarDisp(3, dat2 = Adc_Read(2)); BarDisp(4, dat3 = Adc_Read(3)); BarDisp(5, dat4 = Adc_Read(4)); BarDisp(6, dat5 = Adc_Read(5)); BarDisp(7, dat6 = Adc_Read(6)); Lcd_Out(1, 9, "1:"); WordToStr(dat0 * 4.8828125, buf); Lcd_Out(1, 11, &buf[1]); Lcd_Out(1, 15, "mV"); Lcd_Out(2, 9, "2:"); WordToStr(dat1 * 4.8828125, buf); Lcd_Out(2, 11, &buf[1]); Lcd_Out(2, 15, "mV"); Delay_ms(500); // BarDisp(1, dat0 = Adc_Read(0)); BarDisp(2, dat1 = Adc_Read(1)); BarDisp(3, dat2 = Adc_Read(2)); BarDisp(4, dat3 = Adc_Read(3)); BarDisp(5, dat4 = Adc_Read(4)); BarDisp(6, dat5 = Adc_Read(5)); BarDisp(7, dat6 = Adc_Read(6)); Lcd_Out(1, 9, "3:"); WordToStr(dat2 * 4.8828125, buf); Lcd_Out(1, 11, &buf[1]); Lcd_Out(1, 15, "mV"); Lcd_Out(2, 9, "4:"); WordToStr(dat3 * 4.8828125, buf); Lcd_Out(2, 11, &buf[1]); Lcd_Out(2, 15, "mV"); Delay_ms(500); // BarDisp(1, dat0 = Adc_Read(0)); BarDisp(2, dat1 = Adc_Read(1)); BarDisp(3, dat2 = Adc_Read(2)); BarDisp(4, dat3 = Adc_Read(3)); BarDisp(5, dat4 = Adc_Read(4)); BarDisp(6, dat5 = Adc_Read(5)); BarDisp(7, dat6 = Adc_Read(6)); Lcd_Out(1, 9, "5:"); WordToStr(dat4 * 4.8828125, buf); Lcd_Out(1, 11, &buf[1]); Lcd_Out(1, 15, "mV"); Lcd_Out(2, 9, "6:"); WordToStr(dat5 * 4.8828125, buf); Lcd_Out(2, 11, &buf[1]); Lcd_Out(2, 15, "mV"); Delay_ms(500); // BarDisp(1, dat0 = Adc_Read(0)); BarDisp(2, dat1 = Adc_Read(1)); BarDisp(3, dat2 = Adc_Read(2)); BarDisp(4, dat3 = Adc_Read(3)); BarDisp(5, dat4 = Adc_Read(4)); BarDisp(6, dat5 = Adc_Read(5)); BarDisp(7, dat6 = Adc_Read(6)); Lcd_Out(1, 9, "7:"); WordToStr(dat6 * 4.8828125, buf); Lcd_Out(1, 11, &buf[1]); Lcd_Out(1, 15, "mV"); Lcd_Out(2, 9, " "); Delay_ms(500); // } }//~! //********************************************************************** </code> ===== 動作確認 ===== {{:imgpaste:202004:htmikan-20200430-090528.png?500}} 左側:アナログデータのバー表示(CH-1~CH-7) 右側:アナログデータの数値表示(CH-1とCH-2) {{:imgpaste:202004:htmikan-20200430-090540.png?500}} 左側:アナログデータのバー表示(CH-1~CH-7) 右側:アナログデータの数値表示(CH-3とCH-4) {{:imgpaste:202004:htmikan-20200430-090558.png?500}} 左側:アナログデータのバー表示(CH-1~CH-7) 右側:アナログデータの数値表示(CH-5とCH-6) {{:imgpaste:202004:htmikan-20200430-090612.png?500}} 左側:アナログデータのバー表示(CH-1~CH-7) 右側:アナログデータの数値表示(CH-7) {{:imgpaste:202004:htmikan-20200430-090625.png?500}} <callout type="warning" title="著作権表示 copyright notice"> このページは稲崎様の閉鎖したHPのコピーで、著作権は稲崎様にあります。[[elechobby:picdic:picdic|詳細]] This page is a copy of Mr. Inasaki's closed website, and the copyright is held by him.[[elechobby:picdic:picdic|Details]] </callout> elechobby/picdic/pic16f88/103.txt 最終更新: 2025/10/17 14:29by 127.0.0.1