output8( 0b00111000 ); $this->output8( 0b00111001 ); // IS = 1 /************************************************** * Internal OSC frequency *************************************************/ // 上位4bitは 0001 固定 // 以降、 // BS: 1/5 bias(0) or 1/4 bias(1) // F2-0: adjust internal OSC frequency $this->output8( 0b00010100 ); /************************************************** * Contrast set *************************************************/ // 上位4bitは 0111 固定 // 以降、 // C3-0: Contrast set for internal follower mode $this->output8( 0b01111000 ); /************************************************** * Power/ICON/Contrast control *************************************************/ // 上位4bitは 0101 固定 // 以降、 // Ion: ICON display on/off // Bon: set booster circuit on/off // C5-4: Contrast set for internal follwer mode $this->output8( 0b01011110 ); //$this->output8( 0b01010110 ); /************************************************** * Follower control *************************************************/ // 上位4bitは 0110 固定 // 以降、 // Fon: set follower circui on/off // Rab2-0: select follower amplified ratio $this->output8( 0b01101100 ); // 200ms wait usleep(200 * 1000); /************************************************** * Display ON/OFF control *************************************************/ // 上位5bitは 00001 固定 // 以降、 // D : entire display on // C : cursor on // B : cursor position on $this->output8( 0b00001100 ); // Clear Display $this->output8( 0b00000001 ); usleep(1000); // Entry mode set // 上位6bitは 000001 固定 // 以降、 // I/D: Set cursor move direction. // S : Set specifies display shift. $this->output8( 0b00000110 ); usleep(1000); $this->output8( 0b00111000 ); // IS = 0 } /** * 終了(デストラクタ) */ public function __destruct() { // 画面クリア @$this->output8( 0b00000001 ); } /** * カーソル移動 * @param $line 行(0:1行目、1:2行目) * @param $pos 列(0:1文字目、1:2文字目、…) */ public function movePos($line, $pos){ $data = 0b10000000; // set DDRAM Address モード // 2行目なら、アドレスに 0x40 を足す。 if( $line != 0 ) $data |= 0x40; // 列位置指定 $data |= $pos; $this->output8($data); } /** * 文字出力 * @param $str 出力する文字 */ public function printData($str){ $this->str = TRUE; // 先頭から順に文字を出力 for($i = 0; $i < strlen($str); $i++){ $data = substr($str, $i, 1); $this->output8(ord($data)); // 1文字出力 } $this->str = FALSE; } /** * char出力 * @param $str 出力する1文字 */ public function printChar($data){ $this->str = TRUE; $this->output8($data); // 1文字出力 $this->str = FALSE; } /** * 文字出力(出力位置指定可能) * @param $str 出力する文字 * @param $line 行(0:1行目、1:2行目) * @param $pos 列(0:1文字目、1:2文字目、…) */ public function printPosData($str, $line, $pos){ $this->movePos($line, $pos); $this->printData($str); } /** * 画面クリア(ホームに戻る) */ public function clearDisplay(){ $this->output8( 0b00000001 ); $this->output8( 0b00000010 ); } /** * フォントテーブルの指定した文字を上書き * * LCDで出力する文字を作成します。作成できる文字数は最大8文字ま * で(0x00 - 0x07 )です。 * 作成できる文字は、 * * 例) □ を 0x01 に上書き * * * * @param $address 上書きする文字(0x00 - 0x07) * @param $data 文字を表す配列(要素数8固定) * @return 1:成功、0:失敗 */ public function setChar($address, $data){ // 範囲チェック if( $address < 0 || 7 < $address ){ return 0; } if( !is_array($data) || count($data) != 8 ){ return 0; } // Set CGRAM Address $pos = $address<<3; // DB5-DB3 にアドレスをセット $this->output8( 0b01000000 | $pos ); // 文字を返す foreach( $data as $line ) { $this->printChar($line); } // アドレスをホームに戻す $this->output8( 0b00000010 ); return 1; } /** * 8bit データ出力 * @param $data 出力するデータ */ private function output8($data){ $cmd = "i2cset -y ".$this->port_num." ".$this->adr; if( $this->str == TRUE ){ $cmd .= " 0x40 "; } else { $cmd .= " 0 "; } $cmd .= $data." i"; exec($cmd); } } ?>