![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
flipflop test
main.cpp
- Committer:
- mikevd1
- Date:
- 2018-06-06
- Revision:
- 0:db474e15b188
- Child:
- 1:b82afb355b62
File content as of revision 0:db474e15b188:
/* mbed software with debugger * * author : Mike van Doorn * */ #include "mbed.h" #define slaveAdress 0xFF #define functioncode 0x03 Serial pc(USBTX, USBRX); Serial bus(PA_9,PA_10); DigitalOut led1(LED1); DigitalOut activateSN65(PA_8); int Read(void); int main() { int count = 0 ; int data = 0 ; int buffer = 0 ; int value = 0 ; activateSN65 = 0 ; pc.baud(115200); wait(1); while(1) { if ( count == 10 ) { count = 0 ; } activateSN65 = 0 ; if(bus.readable()) { data = bus.getc(); pc.putc(data); if ( data == 0x07 && buffer == 0) { buffer = 1; } else if ( data == 0x02 && buffer == 1) { buffer = 2; } else if ( buffer == 2 || buffer == 3 ) { if ( buffer == 2 ) { value = data ; value = value << 8 ; buffer = 3 ; } else { value = value + data ; //if ( value > 0 && value < 0xFFFF ) //{ buffer = 5 ; //} } } else if ( buffer == 5 ) { // crc check buffer = 6 ; } else if ( buffer == 6 ) { // crc check buffer = 7 ; } else { buffer = 0 ; } } if ( buffer == 7 ) { if ( count < 5 ) { led1 = !led1; wait_ms(3); activateSN65 = 1 ; //adress bus.putc(0x07); wait_us(900); //send function code bus.putc(0x02); wait_us(900); // Byte count bus.putc(0x01); wait_us(900); //data bus.putc(0x01); wait_us(900); // crc check bus.putc(0x60); wait_us(900); bus.putc(0xC0); buffer = 0 ; wait_ms(2) ; activateSN65 = 0 ; count++; } else { led1 = !led1; wait_ms(3); activateSN65 = 1 ; //adress bus.putc(0x07); wait_us(900); //send function code bus.putc(0x02); wait_us(900); // Byte count bus.putc(0x02); wait_us(900); //data bus.putc(0x02); wait_us(900); bus.putc(0x02); wait_us(900); // crc check bus.putc(0xB1); wait_us(900); bus.putc(0x19); buffer = 0 ; wait_ms(2) ; activateSN65 = 0 ; count++; } } } }