LoginSignup
0
0

More than 1 year has passed since last update.

STM32L010のPortAで遊ぶ(IN)

Last updated at Posted at 2021-12-29

目的
GPIOのテスト

o_con181.jpg



//I2C_EXPANDER_IN_1

#include "mbed.h"

DigitalOut TX(PC_14);

//仮想シリアルへの一文字出力 1200bps
int pc_putc(char ch)
{

    TX=1;
    TX=0;//Start
    wait_us(832);

    for(int ii=0; ii<8; ii++) { //Data x 8
        TX=(ch>>ii)&1;
        wait_us(832);
    }; //for

    TX=1;//Stop
    wait_us(832);

    return(0);

} //pc_putc


PortIn     p(PortA, 0x000000FF);   // PA0-PA7

char HEX_C[] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' } ;

//メインルーチン
int main()
{

    char buf[10];

    TX=1; //ポートの初期化

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

        int pins = p.read();

        //buf[0] = 0x12;
        buf[0] = pins;


        //HEX出力
        char cc = buf[0];
        pc_putc(HEX_C[ cc >> 4    ]);
        pc_putc(HEX_C[ cc &  0x0f ]);
        pc_putc('\r');
        pc_putc('\n');

        //1秒の待ち
        wait_ms(1000);

    }//while

}//main

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





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