![](/media/cache/profiles/5d1c46732f4869197e9aae4d1f0bc888.jpg.50x50_q85.jpg)
Using LTC1485 simple transmit program
main.cpp@1:f532eb8802bf, 2017-02-26 (annotated)
- Committer:
- WakoTakeru
- Date:
- Sun Feb 26 06:10:35 2017 +0000
- Revision:
- 1:f532eb8802bf
- Parent:
- 0:78b29bf54637
ID check
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WakoTakeru | 1:f532eb8802bf | 1 | //*--- 受信側 ---*/ |
WakoTakeru | 0:78b29bf54637 | 2 | #include "mbed.h" |
WakoTakeru | 0:78b29bf54637 | 3 | #include "Serial.h" |
WakoTakeru | 0:78b29bf54637 | 4 | DigitalOut led(PA_15); |
WakoTakeru | 0:78b29bf54637 | 5 | DigitalOut myled(LED1); |
WakoTakeru | 0:78b29bf54637 | 6 | DigitalOut rede(PA_8); |
WakoTakeru | 0:78b29bf54637 | 7 | |
WakoTakeru | 0:78b29bf54637 | 8 | DigitalIn address1(PA_6); |
WakoTakeru | 0:78b29bf54637 | 9 | DigitalIn address2(PA_7); |
WakoTakeru | 1:f532eb8802bf | 10 | DigitalIn address4(PB_0); |
WakoTakeru | 1:f532eb8802bf | 11 | DigitalIn address8(PB_1); |
WakoTakeru | 0:78b29bf54637 | 12 | |
WakoTakeru | 0:78b29bf54637 | 13 | Serial myserial(PA_9,PA_10); |
WakoTakeru | 0:78b29bf54637 | 14 | |
WakoTakeru | 0:78b29bf54637 | 15 | void onInterrupt(); |
WakoTakeru | 0:78b29bf54637 | 16 | |
WakoTakeru | 0:78b29bf54637 | 17 | int index = 0; |
WakoTakeru | 0:78b29bf54637 | 18 | int buffer[5] = {0}; |
WakoTakeru | 1:f532eb8802bf | 19 | int address; |
WakoTakeru | 0:78b29bf54637 | 20 | int main() { |
WakoTakeru | 0:78b29bf54637 | 21 | rede=0; |
WakoTakeru | 1:f532eb8802bf | 22 | address = address1<<0 | address2<<1 | address4<<2 | address8<<3; |
WakoTakeru | 0:78b29bf54637 | 23 | myserial.attach(&onInterrupt,Serial::RxIrq); |
WakoTakeru | 0:78b29bf54637 | 24 | while(1){ |
WakoTakeru | 1:f532eb8802bf | 25 | if(address == buffer[1]){ |
WakoTakeru | 0:78b29bf54637 | 26 | led=1; |
WakoTakeru | 0:78b29bf54637 | 27 | wait(0.05); |
WakoTakeru | 0:78b29bf54637 | 28 | led=0; |
WakoTakeru | 0:78b29bf54637 | 29 | wait(0.05); |
WakoTakeru | 1:f532eb8802bf | 30 | } |
WakoTakeru | 0:78b29bf54637 | 31 | } |
WakoTakeru | 0:78b29bf54637 | 32 | } |
WakoTakeru | 0:78b29bf54637 | 33 | |
WakoTakeru | 0:78b29bf54637 | 34 | void onInterrupt(){ |
WakoTakeru | 0:78b29bf54637 | 35 | buffer[0] = myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 36 | if(buffer[0] == '#'){ |
WakoTakeru | 1:f532eb8802bf | 37 | buffer[1] = myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 38 | buffer[2] = myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 39 | buffer[3] = myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 40 | buffer[4] = myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 41 | }else{ |
WakoTakeru | 1:f532eb8802bf | 42 | myserial.getc();myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 43 | myserial.getc();myserial.getc(); |
WakoTakeru | 1:f532eb8802bf | 44 | buffer[1] = 0; |
WakoTakeru | 1:f532eb8802bf | 45 | buffer[2] = 0; |
WakoTakeru | 1:f532eb8802bf | 46 | buffer[3] = 0; |
WakoTakeru | 1:f532eb8802bf | 47 | buffer[4] = 0; |
WakoTakeru | 1:f532eb8802bf | 48 | } |
WakoTakeru | 0:78b29bf54637 | 49 | myled=1; |
WakoTakeru | 0:78b29bf54637 | 50 | wait(0.01); |
WakoTakeru | 0:78b29bf54637 | 51 | myled=0; |
WakoTakeru | 0:78b29bf54637 | 52 | wait(0.01); |
WakoTakeru | 0:78b29bf54637 | 53 | } |