0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

STM32L010のMbedでの時計,DS1307で時刻表示( AQM0802A i2c)

Last updated at Posted at 2021-02-23

x時間合わせは、なし
x5Vをds1307に接続

xもうどうゃつても入らないので一旦、時間合わせのプログラムをローディング
して再度、表示のプログラムを書き込む。考え中 リコンパイルまで含めるか
x時間合わせは、とりあえず対応済

注意
mbedのリビジョンは、125

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

忙しい人よう
https://os.mbed.com/users/caa45040/code/i2c_lcd_ds1307_010_1/


#include "mbed.h"

#define ADDR        (0xD0)   //  address
#define ADDR_LCD    (0x7C)      //  address

//I2C i2c(I2C_SDA, I2C_SCL); //767
//I2C i2c(dp5, dp27); //1114
I2C i2c(PA_10, PA_9); //010

char    data_read[8];   //i2cバッファー

char INIT_com[]={0x0,0x38,
0x0,0x39,
0x0,0x4,
0x0,0x14,
0x0,0x70,
0x0,0x56,
0x0,0x6C,
0x0,0x38,
0x0,0xC,
0x0,0x1,
0x40,0x41,0x99,0x99};

char INIT_cls[]={0x0,0x1};

char ch_hex_a_b[5];
char *ch_hex_a(int l_num)
{
    ch_hex_a_b[0] = '@';
    ch_hex_a_b[1] = '0' + (l_num >> 4);
    ch_hex_a_b[2] = '0' + (l_num & 0xf);
    ch_hex_a_b[3] = ':';
    ch_hex_a_b[4] = 0;
    return(ch_hex_a_b);
}

int ii;     //ループカウンタ

int main()
{
    //液晶の初期化
    for(ii=0;ii<11;ii++){
        i2c.write(ADDR_LCD, &INIT_com[ii*2], 2);wait_ms(2);
    } //for
 
    while (1) {
        //液晶のクリア
        i2c.write(ADDR_LCD,INIT_cls,2);wait_ms(2);
        
        //時間の読み込み
        i2c.write(ADDR, "\000", 1);
        i2c.read(ADDR | 1, data_read, 7);
       
        i2c.write(ADDR_LCD, ch_hex_a(data_read[2]) ,4); wait_ms(1);
        i2c.write(ADDR_LCD, ch_hex_a(data_read[1]) ,4); wait_ms(1);
        i2c.write(ADDR_LCD, ch_hex_a(data_read[0]) ,4);

        wait_ms(1000);
    }//while
 
}//main



時間合わせプログラム


#include "mbed.h"
#include <stdio.h>
 
//Serial pc(USBTX, USBRX); // tx, rx
//Serial pc(SERIAL_TX, SERIAL_RX);

#define ADDR        (0xD0)  //  address
#define ADDR_LCD    (0x7C)  //  address

//I2C i2c(I2C_SDA, I2C_SCL); //767
//I2C i2c(dp5, dp27); //1114
I2C i2c(PA_10, PA_9); //010

char data_read[8];  //i2cバッファー

#define HH  12
#define MM  34

int main() {
    
///*INIT start *********  

    data_read[0]=0;
    data_read[1]=0;
    data_read[2]= ( MM /10)*16+( MM %10);
    data_read[3]= ( HH /10)*16+( HH %10);
    data_read[4]=3;    
    data_read[5]=1;
    data_read[6]=1;
    data_read[7]=0x20;
    
    i2c.write(ADDR, data_read, 8);

//*/  //INIT end *********

    while(1){} //無限ループ

} // main

i2c_ds1307_010_m.jpg

010_ds1307_ff_1.jpg

i2c_lcd_ds1307_010_a_1.jpg

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?