ちびでぃーの2でばんとさんRT8564ライブラリー機能を確かめるため環境構築してます。
今回はデジットで買ったDTMFキーボードを使用してキー入力i2cスレーブとして作ったPIC16F1827をアドレス修正しつなぎます。アドレスは0x70にしました。
これで、更に信号線上でRTCとLCDとキーが「いもづる」関係になりました。
とりあえずはつながりましたかというテストでキー入力があると該当のASCIIをHEXで表示します。0キーを押しているので、0x30のコードが出ています。
// i2c RTC-8564NB -> i2c Lcd // Using BANT's library by nobcha 05/06/2013 // RTC8564 http://memo.tank.jp/archives/7734 // Using MITSUNAGA's library by nobcha 05/06/2013 // i2c_lcd http://n.mtng.org/ele/arduino/i2c.html // nobcha #include <I2CLiquidCrystal.h> #include <Wire.h> #include <RTC8564.h> RTC8564 RTC; RTC_TIME rtc_time; const char* dayofweek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; char key; // initialize the library I2CLiquidCrystal lcd(20, true); // | +--- set true if the power suply is 5V, false if it is 3.3V // +-------- contrast (0-63) void setup(){ Wire.begin(); lcd.begin(16,2); // set lib for display size (16x2) lcd.clear(); // clear the screen RTC.begin(); /* 2013年5月6日 0時0分0秒に時刻合わせ */ rtc_time.year = 2013; rtc_time.month = 5; rtc_time.day = 6; rtc_time.hour = 12; rtc_time.min = 0; rtc_time.sec = 0; RTC.adjust( rtc_time ); // これでもOK // RTC.adjust( 2013, 5, 6, 12, 0, 0 ); Wire.beginTransmission(0x38); // キースキャン開始 Wire.write(0x0); Wire.write(0x11); Wire.endTransmission(); } void loop(void) { char buf[32]; if(RTC.now(&rtc_time)) { snprintf(buf,16,"%04u-%02u-%02u(%s)", rtc_time.year, rtc_time.month, rtc_time.day, dayofweek[rtc_time.wday]); lcd.setCursor(0,0); delay(100); lcd.print(buf); delay(100); snprintf(buf,16," %02u:%02u:%02u", rtc_time.hour, rtc_time.min, rtc_time.sec ); lcd.setCursor(0,1); delay(100); lcd.print(buf); } Wire.requestFrom(0x38,1); // ten key:0x70 key=Wire.read(); // key read Wire.endTransmission(); snprintf(buf,6," k=%02X", // key data display key ); lcd.print(buf); delay(200); }