#freeze
閲覧総計:&counter();  (本日:&counter(today);  昨日:&counter(yesterday);)~
*I2C通信LCD表示法(16F1827:XC8) [#b8c238ab]

信号線2本で接続できるI2C通信の液晶ディスプレイ(LCD:Liquid Crystal Display)
が2012年4月から秋月で販売を開始した。
ACM1602NI-FLW-FBW-M01 800円
http://akizukidenshi.com/catalog/g/gP-05693/
以前のLCDは7本の信号線を必要としていたので信号線が2本のみは、配線が非常に
シンプルになり、LCDがとても使い易いアイテムになりました。

今回↓このページを参考に
http://sky.geocities.jp/home_iwamoto/P16F145x/P16_L02a.htm
16F1827で、8MHzで、I2C通信プルアップをPICのウィークプルアップを利用し
I2C通信LCDの稼働を確認してみました。プログラム言語はXC8です。 2013/12/29

|&attachref(TS3V0003.JPG,zoom,200x300,button){新しい写真添付};|&attachref(16F1827ピン配置.JPG,zoom,200x250,button){新しい写真添付};|

 //  データをI2C LCDに表示する。
 //    秋月(ACM1602NI)I2C LCD表示器\800への書き込み
 //    http://akizukidenshi.com/catalog/g/gP-05693/
 //    「LCD Disp Test」と液晶表示する。
 //     1)Define I/O PORT
 //                   --PIC16F1827--
 //           SDA  :  SDA1:PORTB(1) pin7
 //           SCL  :  SCL1:PORTB(4) pin10
 //     2)OSC
 //         8MHz (内部クロック)
 //
 //    Language: MPLABX v1.90  XC8 v1.20
 //    Target: PIC16F11827 電源:3.3V
 // 参考ページ:http://sky.geocities.jp/home_iwamoto/P16F145x/P16_L02a.htm
 // Copyright (c) 2012 iwamoto All Rights Reserved
 //*********************************************************
 #include <xc.h>
 #define _XTAL_FREQ 8000000 //PICのクロックをHzで設定(8MHz)
 
 //************* Config  ***********************************
 #pragma config FOSC = INTOSC, WDTE = OFF, BOREN = OFF, IESO = OFF, FCMEN = OFF
 #pragma config PLLEN = OFF, STVREN = OFF, LVP = OFF
 
 //********************************************************
 void i2cByteWrite(char, char, char);    // i2c byte送信
 void i2cTxData(char);                   // i2c SSPBUF セット
 void LCD_dat(char);                     // 1文字表示
 void LCD_cmd(char);                     // コマンド出力
 void LCD_clr(void);                     // 全消去
 void LCD_int(void);                     // 初期化
 void LCD_str(char *);                   // 文字列表示
 void LCD_ROMstr(const char *);          // ROM文字列表示
 void LCD_posyx(char,char);              // カーソル位置指定
 void LCD_hex(char);                     // 16進文字変換表示
 
 //////////// Main //////////////////////////////////
 void main(void){
     char msgStart[] ="LCD Test";
     unsigned char num = 0;
     OSCCON = 0b01110000;           // PLL:OFF, 内部クロック8MHzで駆動
     ANSELB = 0b00000000;           // RB7(AN6)-RB1(AN11)は全て0:デジタルI/Oとする
     TRISB  = 0b11111111;           // PortBを全て1:入力I/Oにする
     OPTION_REGbits.nWPUEN = 0;     // 0:PORTB内部プルアップ利用に設定
     WPUBbits.WPUB1 = 1;            // RB1をI2C通信のウィークプルアップ
     WPUBbits.WPUB4 = 1;            // RB4をI2C通信のウィークプルアップ
     SSPCON1 = 0b00101000;          // I2Cマスターモード指定
     SSPSTAT = 0b00000000;          // I2C STATUSの設定
     SSPADD  = 19;                  // I2Cクロック周波数100KHz(=(19+1)*4/8MHz)
     LCD_int();                     // LCD初期化
     // ------------------------------------------------------
     LCD_str(msgStart);             // 1行目に表示
     LCD_dat(' ');
     LCD_dat('!');
     // ------------------------------------------------------
     LCD_posyx(1,0);                // 2行目に表示
     LCD_ROMstr("1234567890123456");
     while(1){
         LCD_posyx(0,14);           // 1行14文字目に表示
         LCD_hex(num++);            // 数値を表示し、+1する
         __delay_ms(1000);          // 1000msec
     }
 }
 
 //-------- i2cで1byteデータを送信する -----------------------
 //  以下の引数が必要
 //  addr : Slaveのアドレス
 //  cont : Slaveへ制御コード
 //  data : 送信するデータ
 //  NACKやBus衝突などの対応は行っていない
 // -----------------------------------------------------------
 void i2cByteWrite(char addr, char cont, char data){
     SSPCON2bits.SEN = 1;           // Start condition 開始
     while(SSPCON2bits.SEN);        // Start condition 確認
     i2cTxData(addr);               // アドレス送信
     i2cTxData(cont);               // 制御コード送信
     i2cTxData(data);               // データ送信
     SSP1IF = 0;                    // 終了フラグクリア
     SSPCON2bits.PEN = 1;           // Stop condition 開始
     while(SSPCON2bits.PEN);        // Stop condition 確認
 }
 
 //-------- SSPBUFに1文字保存し送信終了を待つ -----------------
 void i2cTxData(char data){
     SSP1IF = 0;                    // 終了フラグクリア
     SSPBUF = data;                 // データセット
     while(!SSP1IF);                // 送信終了待ち
 }
 
 //-------- 1文字表示 --------------------------------------
 void LCD_dat(char chr){
     i2cByteWrite(0xA0, 0x80, chr);
     __delay_us(60);                // 60μsec
 }
 //-------- コマンド出力 --------------------------------------
 void LCD_cmd(char cmd){
     i2cByteWrite(0xA0, 0x00, cmd);
     if(cmd & 0xFC)                 // 上位6ビットに1がある命令
         __delay_us(60);            // 60usec
     else
         __delay_ms(3);             // 3msec ClearおよびHomeコマンド
 }
 //-------- 全消去 ------------------------------------------------
 void LCD_clr(void){
     LCD_cmd(0x01);                 //Clearコマンド出力
 }
 //-------- カーソル位置指定 --------------------------------------
 void LCD_posyx(char ypos, char xpos){
     unsigned char pcode;
     switch(ypos & 0x03){           // 縦位置を取得
         case 0: pcode=0x80;break;  // 1行目
         case 1: pcode=0xC0;break;  // 2行目
         case 2: pcode=0x94;break;  // 3行目
         case 3: pcode=0xD4;break;  // 4行目
     }
     LCD_cmd(pcode += xpos);        // 横位置を加える
 }
 //-------- 文字列出力 -----------------------------------------
 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
 }
 //-------- 16進文字変換表示 --------------------------------
 void LCD_hex(char c){
     const char hexch[] ="0123456789ABCDEF";
     LCD_dat(hexch[c >> 4]);        //上位4bit表示
     LCD_dat(hexch[c & 0xF]);       //下位4bit表示
 }
 
 //-------- 初期化 --------------------------------------
 void LCD_int(void){
     __delay_ms(100);               // 電源安定するまでの時間
     LCD_cmd(0x38);                 // 8bit 2行 表示命令モード
     LCD_cmd(0x0C);                 // Display on Cursor=0 Blink=0
     LCD_cmd(0x06);                 // Entry Inc/Dec=1 Shift=0
     LCD_cmd(0x01);                 // Clear Display
 }


★この情報は役に立ちましたか?
#vote(はい[26],普通[0],いいえ[0])
- このプログラムを動かしてからG先生の本を読むと理解が進みます GOOD! -- [[あっこちゃん]] &new{2015-05-10 (日) 17:51:08};
- http://www.outletonline-michaelkors.com/ http://www.michaelkors-handbags.in.net/ http://www.michael-korsoutlet.in.net/ http://www.michaelkorsoutlet-store.in.net/ http://www.truereligionoutlets.in.net/ http://www.oakleysunglassesoutlet.us.org/ http://www.oakley-sunglasses.ar.com/ http://www.oakley-sunglasses.ar.com/ http://www.oakleysunglassesdeals.in.net/ http://www.oakleysunglassesdeals.in.net/ http://www.oakleysunglasses.qc.com/ http://www.oakleysunglasses.qc.com/ http://www.rayban-sunglasses.net.co/ http://www.rayban-sunglasses.net.co/ http://www.raybansunglasses.gr.com/ http://www.raybansunglasses.gr.com/ http://www.raybanglasses.in.net/ http://www.raybanglasses.in.net/ http://www.polo--ralphlauren.net/ http://www.polo--ralphlauren.net/ http://www.ralphlauren-outlet.in.net/ http://www.ralphlauren-outlet.in.net/ http://www.burberry-outlet-online.us/ http://www.burberry-outlet-online.us/ http://www.burberry-sale.in.net/ http://www.burberry-sale.in.net/ http://www.toms-shoes.us.org/ http://www.toms-shoes.us.org/ http://www.tomsoutlet.com.co/ http://www.tomsoutlet.com.co/ http://www.michael--korsoutlet.net/ http://www.michael--korsoutlet.net/ http://www.michaelkors-outlet-online.net/ http://www.michaelkors-outlet-online.net/ http://www.christian--louboutin.net/ http://www.christian--louboutin.net/ http://www.tory--burch.org/ http://www.tory--burch.org/ http://www.toryburch-outlet.net/ http://www.toryburch-outlet.net/ http://www.gucci--outlet.net/ http://www.gucci--outlet.net/ http://www.gucci--handbags.com/ http://www.gucci--handbags.com/ http://www.jordan--shoes.us/ http://www.jordan--shoes.us/ http://www.air-jordan.in.net/ http://www.air-jordan.in.net/ http://www.cheap-jordans.in.net/ http://www.cheap-jordans.in.net/ http://www.jordansretro.in.net/ http://www.jordansretro.in.net/ http://www.nikeshoesinc.net/ http://www.nikeshoesinc.net/ http://www.nike-shoes.in.net/ http://www.nike-shoes.in.net/ http://www.air-max-2015.net/ http://www.air-max-2015.net/ http://www.air-max-2015.net/ http://www.airmax-90.in.net/ http://www.airmax-90.in.net/ http://www.airmax-95.in.net/ http://www.airmax-95.in.net/ http://www.nike-free-run.net/ http://www.nike-free-run.net/ http://www.nikefree-5.com/ http://www.nikefree-5.com/ http://www.chanel--handbags.net/ http://www.chanel--handbags.net/ http://www.chanel-bags.in.net/ http://www.chanel-bags.in.net/ http://www.true-religion.cc/ http://www.true-religion.cc/ http://www.north-faceoutlet.in.net/ http://www.north-faceoutlet.in.net/ http://www.coachoutlet-store.in.net/ http://www.coachoutlet-store.in.net/ http://www.abercrombie.ar.com/ http://www.abercrombie.ar.com/ http://www.hollister.cn.com/ http://www.hollister.cn.com/ http://www.hermes.us.org/ http://www.hermes.us.org/ http://www.new-balanceoutlet.net/ http://www.new-balanceoutlet.net/ http://www.reebok-shoes.net/ http://www.reebok-shoes.net/ http://www.lululemon.com.co/ http://www.lululemon.com.co/ http://www.yoga-pants.in.net/ http://www.yoga-pants.in.net/ http://www.rolex--replica.us/ http://www.rolex--replica.us/ http://www.omega-watches.in.net/ http://www.omega-watches.in.net/ http://www.wedding--dresses.net/ http://www.wedding--dresses.net/ http://www.montblancpens.net.co/ http://www.montblancpens.net.co/ http://www.insanityworkout.us.org/ http://www.insanityworkout.us.org/ http://www.nike-mercurial.org/ http://www.jimmy--choo.us/ http://www.jimmy--choo.us/ http://www.ugg-boots.org/ http://www.ugg-boots.org/ http://www.uggs--outlet.net/ http://www.uggs--outlet.net/ http://www.nike-rosherun.net/ http://www.roshe--run.com/ http://www.nikeroshe.net/ http://www.tiffany-andco.net/ http://www.tiffany-andco.net/ http://www.vans--shoes.com/ http://www.vans--shoes.com/ http://www.timberland--boots.com/ http://www.timberland--boots.com/ http://www.beats-bydre.in.net/ http://www.beats-bydre.in.net/ http://www.salvatoreferragamoshoes.net/ http://www.salvatoreferragamoshoes.net/ http://www.cheap-jerseys.in.net/ http://www.cheap-jerseys.in.net/ http://www.cheap-nfljerseys.in.net/ http://www.cheap-nfljerseys.in.net/ http://www.jerseys-fromchina.in.net/ http://www.jerseys-fromchina.in.net/ http://www.mizunowave.net/ http://www.mizunowave.net/ http://www.mizunorunning-shoes.com/ http://www.designerhandbags.com.co/ http://www.designerhandbags.com.co/ http://www.bootsonsale.com.co/ http://www.bootsonsale.com.co/ http://www.basketball--shoes.net/ http://www.basketball--shoes.net/ http://www.cheapeyeglasses.us.com/ http://www.cheapeyeglasses.us.com/ http://www.tommy-hilfiger.us.com/ http://www.tommy-hilfiger.us.com/ http://www.tommyhilfigeroutlet.net/ http://www.tommyhilfigeroutlet.net/ http://www.ed-hardy.in.net/ http://www.ed-hardy.in.net/ http://www.levisjeans.in.net/ http://www.levisjeans.in.net/ http://www.bcbgmax.in.net/ http://www.bcbgmax.in.net/ http://www.bebedresses.in.net/ http://www.bebedresses.in.net/ http://www.balenciaga.in.net/ http://www.balenciaga.in.net/ http://www.marcjacobs.in.net/ http://www.marcjacobs.in.net/ http://www.harrodslondon.org.uk/ http://www.harrodslondon.org.uk/ http://www.chaussureslouboutin-soldes.fr/ http://www.chaussureslouboutin-soldes.fr/ http://www.sac-michael-kors.fr/ http://www.sac-michael-kors.fr/ http://www.nikeblazer1.fr/ http://www.nikeblazer1.fr/ http://www.nikeairforce-1.fr/ http://www.nikeairforce-1.fr/ http://www.michaelkors-outlet.org.uk/ http://www.michaelkors-outlet.org.uk/ http://www.michael-kors-canada.ca/ http://www.michael-kors-canada.ca/ http://www.burberry--uk.me.uk/ http://www.burberry--uk.me.uk/ http://www.timberlandboot.org.uk/ http://www.timberlandboot.org.uk/ http://www.oakley--sunglasses.co.uk/ http://www.louboutinshoes.org.uk/ http://www.air-jordans.co.uk/ http://www.coco-chanelhandbags.co.uk/ http://www.katespadeuk.co.uk/ http://www.truereligion-jeans.co.uk/ http://www.newbalance-trainers.co.uk/ http://www.converse-sale.co.uk/ http://www.lululemon.org.uk/ http://www.beats-bydre.co.uk/ http://www.macmakeupuk.co.uk/ http://www.maccosmetics-uk.co.uk/ http://www.adidas-trainersuk.co.uk/ http://www.gucci-uk.co.uk/ http://www.fitflop.me.uk/ http://www.adidasoriginals.org.uk/ http://www.adidasoriginals.org.uk/ http://www.hermes.org.uk/ http://www.hermes.org.uk/ http://www.pandorauk.co.uk/ http://www.pandorauk.co.uk/ http://www.pandorauk.co.uk/ http://www.rolex--watches.co.uk/ http://www.rolex--watches.co.uk/ http://www.omegawatches.org.uk/ http://www.omegawatches.org.uk/ http://www.michael-jordan.co.uk/ http://www.michael-jordan.co.uk/ http://www.michael-jordan.co.uk/ http://www.michael--kors.org.uk/ http://www.michael--kors.org.uk/ http://www.michael--kors.org.uk/ http://www.weddingdresses.me.uk/ http://www.weddingdresses.me.uk/ http://www.weddingdresses.me.uk/ http://www.converse.org.uk/ http://www.converse.org.uk/ http://www.converse.org.uk/ http://www.hollister-uk.me.uk/ http://www.hollister-uk.me.uk/ http://www.hollister-uk.me.uk/ http://www.tiffany-and-co.org.uk/ http://www.tiffany-and-co.org.uk/ http://www.tiffany-and-co.org.uk/ http://www.airmax-90.co.uk/ http://www.airmax-90.co.uk/ http://www.airmax-90.co.uk/ http://www.louis--vuitton.me.uk/ http://www.louis--vuitton.me.uk/ http://www.louis--vuitton.me.uk/ http://www.mulberryoutlet.me.uk/ http://www.mulberryoutlet.me.uk/ http://www.mulberryoutlet.me.uk/ http://www.north-face.org.uk/ http://www.north-face.org.uk/ http://www.north-face.org.uk/ http://www.timberland.org.uk/ http://www.timberland.org.uk/ http://www.timberland.org.uk/ http://www.rayban--sunglasses.org.uk/ http://www.rayban--sunglasses.org.uk/ http://www.rayban--sunglasses.org.uk/ http://www.asicstrainers.org.uk/ http://www.asicstrainers.org.uk/ http://www.asicstrainers.org.uk/ http://www.prada.me.uk/ http://www.prada.me.uk/ http://www.prada.me.uk/ http://www.toms-shoes.org.uk/ http://www.toms-shoes.org.uk/ http://www.tommy-hilfiger.org.uk/ http://www.tommy-hilfiger.org.uk/ http://www.tommy-hilfiger.org.uk/ http://www.marcjacobs.org.uk/ http://www.marcjacobs.org.uk/ http://www.uggs.org.uk/ http://www.uggs.org.uk/ http://www.ugg--boots.org.uk/ http://www.ugg--boots.org.uk/ http://www.ugg-australia.co.uk/ http://www.ugg-australia.co.uk/ http://www.uggs.org.uk/ http://www.ugg--boots.org.uk/ http://www.ugg-australia.co.uk/ http://www.insanityworkout.co.uk/ http://www.insanityworkout.co.uk/ http://www.nike-free-run.co.uk/ http://www.nike-free-run.co.uk/ http://www.ferragamo.org.uk/ http://www.ferragamo.org.uk/ http://www.fitflops.me.uk/ http://www.fitflops.me.uk/ http://www.fitflops.me.uk/ http://www.nike-mercurial-superfly.co.uk/ http://www.nike-mercurial-superfly.co.uk/ http://www.nike-mercurial-superfly.co.uk/ http://www.nikestoreuk.co.uk/ http://www.nikestoreuk.co.uk/ http://www.nikestoreuk.co.uk/ http://www.guessfactorycanada.ca/ http://www.guessfactorycanada.ca/ http://www.guessfactorycanada.ca/ http://www.nike--store.fr/ http://www.chaussure-nike-pas-cher.fr/ http://www.adidas--superstar.fr/ http://www.adidas-zxflux.fr/ http://www.montre-femme-homme.fr/ http://www.michaeljordan.fr/ http://www.air-max-90.fr/ http://www.bracelet-pandora-bijoux.fr/ http://www.bracelet-swarovski-bijoux.fr/ http://www.sac--chanel.fr/ http://www.ralph--lauren.fr/ http://www.new-balance-femme-574.fr/ http://www.michael--kors.fr/ http://www.lunetterayban.fr/ http://www.tommy--hilfiger.fr/ http://www.lunette-oakley.fr/ http://www.ugg-australia.fr/ http://www.nike--huarache.fr/ http://www.asics-gellyte.fr/ http://www.asics-gellyte.fr/ http://www.asics-gellyte.fr/ http://www.scarpe-nike-store.it/ http://www.scarpe-adidas-superstar.it/ http://www.pandora-bracciali.it/ http://www.orologi-rolex.it/ http://www.tiffany--gioielli.it/ http://www.michael-jordan.it/ http://www.hogan-outlet-online.it/ http://www.swarovski-gioielli.it/ http://www.coco-chanel.it/ http://www.michael-kors-borse.it/ http://www.burberry-outlet-online.it/ http://www.hollister-co.it/ http://www.mac-makeup.com/ http://www.guess-factory.com/ http://www.adidasoutlet.net/ http://www.adidasshoesoutlet.com/ http://www.todsshoes.org/ http://www.fendi.in.net/ http://www.guccibelts.us.org/ http://www.fitflopsale.net/ http://www.kobe9shoes.net/ http://www.kobebryantshoes10.com/ http://www.lebronshoes12.net/ http://www.lebron-11.net/ http://www.lebronjames-shoes.com/ http://www.kevindurant-shoes.net/ http://www.fivefingersshoes.org/ http://www.puma-shoes.net/ http://www.salomon-shoes.net/ http://www.cartier-love-bracelet.us.com/ http://www.dolce-and-gabbana.org/ http://www.dansko-shoes.org/ http://www.stuart-weitzman.net/ -- [[SDF]] &new{2015-09-15 (火) 14:04:04};

#comment_nospam