IM920で受信したデータをそのまま返すプログラム

Dependencies:   mbed

main.cpp

Committer:
taquto
Date:
2021-07-30
Revision:
1:ad1d414d86fb
Parent:
0:337a66b6778a

File content as of revision 1:ad1d414d86fb:

//参考サイト:http://www.maroon.dti.ne.jp/koten-kairo/works/dsPIC/serial6.html
//mbedシリアル通信参考サイト:https://os.mbed.com/users/okini3939/notebook/Serial_jp/
//IM920とマイコンだけで通信を行うプログラム。
//'b0'(blast-off(0ff)の頭文字)を受信したとき、LEDが点滅し始める。

#include "mbed.h"
DigitalOut myled(LED1);

char temp;
char str[10];

int k=0;
int i=0;
//int n=0;

int main()
{
    Serial pc(USBTX, USBRX,38400);//ボーレートを落とすと,USB側からのデータが正確に出力されない.
    Serial im920(PA_9,PA_10,19200);//TX(IM920_RX), RX(IM920_TX)

    myled = 0;

    while(1) {
        //pc.printf("%d\n\r",k);

        if(im920.readable()) { //IM920からのデータがある場合
            temp = im920.getc();//一文字読み込む
            if(temp != '\r') { //読み込み文字が改行で無い場合
                str[i] = temp;
                i++;
            } else if(temp == '\r') { //読み込み文字が改行の場合
                if(str[i-2] == 'B') {
                    if(str[i-1] == '0') {
                        k = 1;
                    }
                }
            }
        }

        if(k == 1) {
            myled = 1;
            wait(0.2);
            myled = 0;
            wait(1.0);
        }
    }
}