Takeru Wako
/
RS485_Receive
Using LTC1485 simple transmit program
Revision 1:f532eb8802bf, committed 2017-02-26
- Comitter:
- WakoTakeru
- Date:
- Sun Feb 26 06:10:35 2017 +0000
- Parent:
- 0:78b29bf54637
- Commit message:
- ID check
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 78b29bf54637 -r f532eb8802bf main.cpp --- a/main.cpp Sat Feb 25 07:32:28 2017 +0000 +++ b/main.cpp Sun Feb 26 06:10:35 2017 +0000 @@ -1,4 +1,4 @@ -/*--- 受信側 ---*/ +//*--- 受信側 ---*/ #include "mbed.h" #include "Serial.h" DigitalOut led(PA_15); @@ -7,8 +7,8 @@ DigitalIn address1(PA_6); DigitalIn address2(PA_7); -DigitalIn address8(PB_0); -DigitalIn address4(PB_1); +DigitalIn address4(PB_0); +DigitalIn address8(PB_1); Serial myserial(PA_9,PA_10); @@ -16,39 +16,38 @@ int index = 0; int buffer[5] = {0}; +int address; int main() { rede=0; - int address = address1<<0 | address2<<1 | address4<<2 | address8<<3; + address = address1<<0 | address2<<1 | address4<<2 | address8<<3; myserial.attach(&onInterrupt,Serial::RxIrq); while(1){ + if(address == buffer[1]){ led=1; wait(0.05); led=0; wait(0.05); + } } } void onInterrupt(){ buffer[0] = myserial.getc(); - buffer[1] = myserial.getc(); - buffer[2] = myserial.getc(); - buffer[3] = myserial.getc(); - buffer[4] = myserial.getc(); + if(buffer[0] == '#'){ + buffer[1] = myserial.getc(); + buffer[2] = myserial.getc(); + buffer[3] = myserial.getc(); + buffer[4] = myserial.getc(); + }else{ + myserial.getc();myserial.getc(); + myserial.getc();myserial.getc(); + buffer[1] = 0; + buffer[2] = 0; + buffer[3] = 0; + buffer[4] = 0; + } myled=1; wait(0.01); myled=0; wait(0.01); - /* - if(data == '#'){ - index = 1; - - } - if(index != 0){ - buffer[index-1] = data; - if(index == 5){ - index = 0; - } - index ++; - - }*/ } \ No newline at end of file