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と秋月シリアル7セグで3分タイマー SPI

Last updated at Posted at 2021-05-18

x Mbedのリビジョンは、125
x Mbedでのボード設定は、NUCLEO-L011K4
x 赤色7セグメントLEDシリアルドライバモジュール 完成品
x OSL10564-74HC595-R M-12642

動機
本当に出来るとは、思いませんでした。

説明
文字を文字パターン
ch_chvc() x廃止6/22
文字を文字パターンに変換する
64は、@の開始位置です。
7セグメントの文字パターンに変換
変換範囲は、32文字で5ビット分

メイン関数
main()
いろいろ初期化

メインループ
while{}
1から3までを1分毎に7セグに表示して
無限ループで停止する

x軽量コンパクト化6/22

参考
https://os.mbed.com/users/okini3939/notebook/SPI_jp/

忙しい人よう

いろいろ
SPIにかんしては、容量不足で動かなかった
erro()で3kバイト空いた為に動く様になった。
SPIただ、7セグにデータを送る為に使っている
SPIでSTM32L010の周辺装置の使い方は、おわり
ここ最近で難しかったのは、
「STM32L010と内部タイマーを使って3分タイマー」
タイマーではまりまくった、桁がでかすぎる
32ビットがすぐに埋まる。
ソフトウェアシリアルでタイマーを仕込んでウエートのタイミングを
測定していた、ほかの人のは、オシロを使ったり、論理的にクロック数から
計算して、ウェートを求めていた。ソフトウェアシリアルは、簡単そうに見えて
難しい。

軽量コンパクト化



# include "mbed.h"

//*          *****  *****  
//*         *       *    * 
//*         ******  *    *
//*         *       *    *
//*         *       *    *
//********   *****  *****

# define swclk1  PA_5    //A4
# define test01  PA_6
# define swdio1  PA_7    //A6
# define en1     PA_4    //A3

//SPI spi( D11 , D12 , D13); // mosi, miso, sclk //767
//DigitalOut en( D10 ); //767

SPI spi( swdio1 , test01, swclk1); // mosi, miso, sclk //010
DigitalOut en(en1); //010

char seg[32] = {
   0x00 , //0 @ -> ' '
   0x77 , //1 A  o
   0x7c , //2 B      combined use "6"
   0x39 , //3 C
   0x5e , //4 D
   0x79 , //5 E  o
   0x71 , //6 F
   0x3d , //7 G
             
   0x76 , //8 H  o
   0x06 , //9 I     combined use "1"
   0x1e , //10 J
   0x75 , //11 K 
   0x38 , //12 L  o
   0x15 , //13 M
   0x37 , //14 N  o
   0x3f , //15 O  o combined use "0"
              
   0x73  , //16 P
   0x67  , //17 Q combined use "9"
   0x50  , //18 R
   0x6d  , //19 S combined use "5"
   0x78  , //20 T
   0x3e  , //21 U
   0x1c  , //22 V
   0x2a  , //23 W  o
   0x64  , //24 X
               
   0x6e  , //25 Y
   0x5b  , //26 Z combined use "2"
   0x4f  , //27 [  --> "3"
   0x66  , //28 \  --> "4"
   0x27  , //29 ]  --> "7"
   0x7f  , //26 ^  --> "8"
   0x08    //31 _
};


# define s60()   for(ii=0;ii<60;ii++)wait_ms(1000);

int main() {

    spi.format(8,0);
    spi.frequency(1000000);

    en=0;

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

    //0分
    spi.write(seg['O'-64]);en=1;en=0;
    s60();

    //1分
    spi.write(seg['I'-64]);en=1;en=0;
    s60();

    //2分
    spi.write(seg['Z'-64]);en=1;en=0;
    s60();

    //3分
    spi.write(seg['['-64]);en=1;en=0;

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

}//main

//容量削減
void error(const char* format, ...){}



変更前


# include "mbed.h"

//*          *****  *****  
//*         *       *    * 
//*         ******  *    *
//*         *       *    *
//*         *       *    *
//********   *****  *****

# define swclk1  PA_5    //A4
# define test01  PA_6
# define swdio1  PA_7    //A6
# define en1     PA_4    //A3

//DigitalOut test1(test01);

//DigitalOut swdclk(swclk1);
//DigitalOut swdio(swdio1);
DigitalOut en(en1);

SPI spi( swdio1 , test01, swclk1); // mosi, miso, sclk

char seg[32][8] = {
 { 1,1,1,1,1,1,1,1 }, //0 @ -> ' '
 { 0,0,0,0,0,1,0,1 }, //1 A  o
 { 1,1,0,0,0,0,0,1 }, //2 B      combined use "6"
 { 0,1,0,1,0,0,1,1 }, //3 C
 { 1,0,1,0,0,0,0,1 }, //4 D
 { 0,1,0,0,0,0,1,1 }, //5 E  o
 { 0,1,0,0,0,1,1,1 }, //6 F
 { 0,1,0,1,0,0,0,1 }, //7 G

 { 1,0,0,0,0,1,0,1 }, //8 H  o
 { 1,0,1,1,1,1,0,1 }, //9 I     combined use "1"
 { 1,0,1,1,0,0,0,1 }, //10 J
 { 0,1,0,0,0,1,0,1 }, //11 K 
 { 1,1,0,1,0,0,1,1 }, //12 L  o
 { 0,1,1,1,0,1,0,1 }, //13 M
 { 0,0,0,1,0,1,0,1 }, //14 N  o
 { 0,0,0,1,0,0,0,1 }, //15 O  o combined use "0"

 { 0,0,0,0,0,1,1,1 }, //16 P
 { 0,0,0,0,1,1,0,1 }, //17 Q combined use "9"
 { 1,1,1,0,0,1,1,1 }, //18 R
 { 0,1,0,0,1,0,0,1 }, //19 S combined use "5"
 { 1,1,0,0,0,0,1,1 }, //20 T
 { 1,0,0,1,0,0,0,1 }, //21 U
 { 1,1,1,1,0,0,0,1 }, //22 V
 { 1,0,0,1,1,0,1,1 }, //23 W  o
 { 1,1,0,0,1,1,0,1 }, //24 X

 { 1,0,0,0,1,0,0,1 }, //25 Y
 { 0,0,1,0,0,0,1,1 }, //26 Z combined use "2"
 { 0,0,1,0,1,0,0,1 }, //27 [  --> "3"
 { 1,0,0,0,1,1,0,1 }, //28 \  --> "4"
 { 0,0,0,1,1,1,0,1 }, //29 ]  --> "7"
 { 0,0,0,0,0,0,0,1 }, //26 ^  --> "8"
 { 1,1,1,1,1,0,1,1 }  //31 _
};

int vc;
int ch_chvc(int s)
{
    s = s - 64;
    
    vc =0;
    vc = vc | ((!(seg[s][7])) << 7);
    vc = vc | ((!(seg[s][3])) << 6);
    vc = vc | ((!(seg[s][2])) << 5);
    vc = vc | ((!(seg[s][4])) << 4);
    vc = vc | ((!(seg[s][5])) << 3);
    vc = vc | ((!(seg[s][6])) << 2);
    vc = vc | ((!(seg[s][1])) << 1);
    vc = vc | ((!(seg[s][0])) << 0);
    
    return(vc);
}//ch_chvc

//d int v;
//d int rs;
//d void seg1()
//d {
//d     swdio=((v>>7)&1);   swdclk=1;swdclk=0; //7
//d     swdio=((v>>6)&1);   swdclk=1;swdclk=0; //6
//d     swdio=((v>>5)&1);   swdclk=1;swdclk=0; //5
//d     swdio=((v>>4)&1);   swdclk=1;swdclk=0; //4
//d     swdio=((v>>3)&1);   swdclk=1;swdclk=0; //3
//d     swdio=((v>>2)&1);   swdclk=1;swdclk=0; //2
//d     swdio=((v>>1)&1);   swdclk=1;swdclk=0; //1
//d     swdio=((v>>0)&1);   swdclk=1;swdclk=0; //0
//d     swdio=rs;   
//d     en=1; 
//d     wait_ms(1);      
//d     en=0;       
//d }//seg1

int main() {

//d    en=1;          //debug
//d    wait_ms(1000); //debug
//d    
//d    swdio=1;       //debug
//d    wait_ms(1000); //debug
    
//d     en=0;
//d     swdio=0;
//d     for(int i=0;i<16;i++){
//d         swdclk=1;
//d         wait_ms(15);
//d         swdclk=0;
//d         wait_ms(15);
//d     }//for

    spi.format(8,0);
    spi.frequency(1000000);
    
    en=0;
    
    int v;  //バリュー 表示のパターン
    
    //v=ch_chvc('Y');
    //spi.write(v);en=1;en=0;  //debug
    //wait_ms(1000);
 
    v=ch_chvc('@');
    spi.write(v);en=1;en=0;  //debug
    wait_ms(1000);
 
    //en=1;          //debug
    //wait_ms(1000); //debug
      
//d    en=0; 
//d    for(int i=0;i<16;i++){
//d        en=1;
//d        wait_ms(15);
//d        en=0;
//d        wait_ms(15);
//d    }//for

//d    v=0x55;seg1(); //debug
//d    wait_ms(1000); //debug
//d    v=0xaa;seg1(); //debug
//d    wait_ms(1000); //debug

    int ii; //ループカウンター
    //int v;  //バリュー 表示のパターン

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

        //0分
        v=ch_chvc('O');spi.write(v);en=1;en=0;
    
        for(ii = 0;ii < 60;ii++){
            wait_ms(1000);
        }//for

        //1分
        v=ch_chvc('I');spi.write(v);en=1;en=0;
        
        for(ii = 0;ii < 60;ii++){
            wait_ms(1000);
        }//for

        //2分
        v=ch_chvc('Z');spi.write(v);en=1;en=0;

        for(ii = 0;ii < 60;ii++){
            wait_ms(1000);
        }//for

        //3分
        v=ch_chvc('[');spi.write(v);en=1;en=0;

        
        while(1){} //無限ループ
//d        while(1){           //debug
//d            swdclk=1;       //debug
//d            wait_ms(1000);  //debug
//d            swdclk=0;       //debug
//d            wait_ms(1000);  //debug
//d        }//while            //debug
        

//d        while(1){           //debug
//d            en=1;       //debug
//d            wait_ms(1000);  //debug
//d            en=0;       //debug
//d            wait_ms(1000);  //debug
//d        }//while            //debug

    }//while //無限ループ
}//main

//容量削減
void error(const char* format, ...){}



serial_raw_temp_010_r1_3.jpg

spi_7seg_010_2_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?