LoginSignup
0
0

More than 1 year has passed since last update.

LPC812MAXで時計。(DS1307)(シリアル出力)(LPC812)

Last updated at Posted at 2022-09-25

x 時間あわせは、別

x mbed2リビジョン144
x リビジョンの変更ができる人むけ

x 無意味に軽量高速化 しかも わかりやすくした。

目的
DS1307のテスト

1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり

o_con802.jpg

-625-

o_con625.jpg




//i2c_ds1307_SER_812_1

#include "mbed.h"

//         TX    RX
Serial pc(P0_4, P0_0); //812

//       SDA    SCL
I2C i2c(P0_10, P0_11); //812

//メイン関数
int main()
{
    //無限ループ
    while(1) {

        //時間の読み込み
        i2c.write( (0xD0), "\000", 1);
        char read_data[7]; //リードデータ
        i2c.read(  (0xD0) | 1, read_data, 7);

        //時間の表示
        pc.putc( '0'+(read_data[2] >> 4)   );
        pc.putc( '0'+(read_data[2] & 0xf)  );
        pc.putc( '.' );
        pc.putc( '0'+(read_data[1] >> 4)   );
        pc.putc( '0'+(read_data[1] & 0xf)  );
        pc.putc( '.' );
        pc.putc( '0'+(read_data[0] >> 4)   );
        pc.putc( '0'+(read_data[0] & 0xf)  );
        pc.putc( '\r');
        pc.putc( '\n' );

        //1秒待つ
        wait_ms(1000);

    }//while
}//main





o_con833.jpg

-32-

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0