050216
Dependencies: MODSERIAL mon-050216 mbed timer0-050216
Fork of mbed_blinky by
main.cpp@10:cfd15bd4762a, 2016-02-05 (annotated)
- Committer:
- rs27
- Date:
- Fri Feb 05 16:52:41 2016 +0000
- Revision:
- 10:cfd15bd4762a
- Parent:
- 4:81cea7a352b0
- Child:
- 11:be852b7b7692
050216
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rs27 | 10:cfd15bd4762a | 1 | // RS485 Link für modeserial |
rs27 | 10:cfd15bd4762a | 2 | // https://developer.mbed.org/cookbook/MODSERIAL |
rs27 | 10:cfd15bd4762a | 3 | |
dan | 0:7dec7e9ac085 | 4 | #include "mbed.h" |
rs27 | 10:cfd15bd4762a | 5 | #include "main.h" |
rs27 | 10:cfd15bd4762a | 6 | #include "timer0.h" |
rs27 | 10:cfd15bd4762a | 7 | #include "mon.h" |
rs27 | 10:cfd15bd4762a | 8 | #include "rs_485.h" |
rs27 | 10:cfd15bd4762a | 9 | |
rs27 | 10:cfd15bd4762a | 10 | DigitalOut led1(LED1,1); |
rs27 | 10:cfd15bd4762a | 11 | DigitalOut led2(LED2,1); |
rs27 | 10:cfd15bd4762a | 12 | DigitalOut led3(LED3,1); |
rs27 | 10:cfd15bd4762a | 13 | DigitalOut led4(LED4,1); |
rs27 | 10:cfd15bd4762a | 14 | DigitalOut led5(LED5,1); |
rs27 | 10:cfd15bd4762a | 15 | DigitalOut led6(LED6,1); |
rs27 | 10:cfd15bd4762a | 16 | DigitalOut led7(LED7,1); |
rs27 | 10:cfd15bd4762a | 17 | |
rs27 | 10:cfd15bd4762a | 18 | DigitalOut out1(OUT1,0); // max 500mA schaltet gegen GND |
rs27 | 10:cfd15bd4762a | 19 | DigitalOut out2(OUT2,0); |
rs27 | 10:cfd15bd4762a | 20 | DigitalOut out3(OUT3,0); |
rs27 | 10:cfd15bd4762a | 21 | DigitalOut out4(OUT4,0); |
dan | 0:7dec7e9ac085 | 22 | |
rs27 | 10:cfd15bd4762a | 23 | DigitalIn in1(IN1); // 0 oder 24V |
rs27 | 10:cfd15bd4762a | 24 | DigitalIn in2(IN2); |
rs27 | 10:cfd15bd4762a | 25 | DigitalIn in3(IN3); |
rs27 | 10:cfd15bd4762a | 26 | DigitalIn in4(IN4); |
rs27 | 10:cfd15bd4762a | 27 | |
rs27 | 10:cfd15bd4762a | 28 | MODSERIAL pc(TXD, RXD); // tx, rx |
rs27 | 10:cfd15bd4762a | 29 | timer0 down_timer; // Timer für Zeitsteuerung |
rs27 | 10:cfd15bd4762a | 30 | rs_485 RS485_BUS; // RS485 BUS |
rs27 | 10:cfd15bd4762a | 31 | |
rs27 | 10:cfd15bd4762a | 32 | monitor mon; |
rs27 | 10:cfd15bd4762a | 33 | |
rs27 | 10:cfd15bd4762a | 34 | void led_aus(void) |
rs27 | 10:cfd15bd4762a | 35 | { |
rs27 | 10:cfd15bd4762a | 36 | led1 = 1; |
rs27 | 10:cfd15bd4762a | 37 | led2 = 1; |
rs27 | 10:cfd15bd4762a | 38 | led3 = 1; |
rs27 | 10:cfd15bd4762a | 39 | led4 = 1; |
rs27 | 10:cfd15bd4762a | 40 | led5 = 1; |
rs27 | 10:cfd15bd4762a | 41 | led6 = 1; |
rs27 | 10:cfd15bd4762a | 42 | led7 = 1; |
rs27 | 10:cfd15bd4762a | 43 | out2 = 0; |
rs27 | 10:cfd15bd4762a | 44 | out3 = 0; |
rs27 | 10:cfd15bd4762a | 45 | out4 = 0; |
rs27 | 10:cfd15bd4762a | 46 | } |
rs27 | 10:cfd15bd4762a | 47 | |
rs27 | 10:cfd15bd4762a | 48 | |
rs27 | 10:cfd15bd4762a | 49 | uint8_t i = 1; |
dan | 0:7dec7e9ac085 | 50 | |
dan | 0:7dec7e9ac085 | 51 | int main() { |
rs27 | 10:cfd15bd4762a | 52 | |
rs27 | 10:cfd15bd4762a | 53 | pc.baud(115200); |
rs27 | 10:cfd15bd4762a | 54 | pc.printf("\nHello IOX.mini\n"); |
rs27 | 10:cfd15bd4762a | 55 | |
rs27 | 10:cfd15bd4762a | 56 | down_timer.SetCountdownTimer(1,1,500); // Timer für LED |
rs27 | 10:cfd15bd4762a | 57 | |
dan | 0:7dec7e9ac085 | 58 | while(1) { |
rs27 | 10:cfd15bd4762a | 59 | |
rs27 | 10:cfd15bd4762a | 60 | mon.monPC(); // Eingaben abfragen und auswerten |
rs27 | 10:cfd15bd4762a | 61 | //RS485_BUS.execute(); // RS485 Bus |
rs27 | 10:cfd15bd4762a | 62 | |
rs27 | 10:cfd15bd4762a | 63 | //-------------------------------------------------------------------------- |
rs27 | 10:cfd15bd4762a | 64 | // LED für Statusanzeige |
rs27 | 10:cfd15bd4762a | 65 | |
rs27 | 10:cfd15bd4762a | 66 | if (down_timer.GetTimerStatus(1) == 0) |
rs27 | 10:cfd15bd4762a | 67 | { |
rs27 | 10:cfd15bd4762a | 68 | // RS485.printf("\n %02x",i); |
rs27 | 10:cfd15bd4762a | 69 | |
rs27 | 10:cfd15bd4762a | 70 | down_timer.SetCountdownTimer(1,1,50); // alle 500ms |
rs27 | 10:cfd15bd4762a | 71 | // pc.printf("\nLED #%d",i); |
rs27 | 10:cfd15bd4762a | 72 | switch (i) |
rs27 | 10:cfd15bd4762a | 73 | { |
rs27 | 10:cfd15bd4762a | 74 | |
rs27 | 10:cfd15bd4762a | 75 | case 1: |
rs27 | 10:cfd15bd4762a | 76 | i = 2; |
rs27 | 10:cfd15bd4762a | 77 | led_aus(); |
rs27 | 10:cfd15bd4762a | 78 | led1 = 0; |
rs27 | 10:cfd15bd4762a | 79 | break; |
rs27 | 10:cfd15bd4762a | 80 | case 2: |
rs27 | 10:cfd15bd4762a | 81 | i = 3; |
rs27 | 10:cfd15bd4762a | 82 | led_aus(); |
rs27 | 10:cfd15bd4762a | 83 | led2 = 0; |
rs27 | 10:cfd15bd4762a | 84 | break; |
rs27 | 10:cfd15bd4762a | 85 | case 3: |
rs27 | 10:cfd15bd4762a | 86 | i = 4; |
rs27 | 10:cfd15bd4762a | 87 | led_aus(); |
rs27 | 10:cfd15bd4762a | 88 | led3 = 0; |
rs27 | 10:cfd15bd4762a | 89 | break; |
rs27 | 10:cfd15bd4762a | 90 | case 4: |
rs27 | 10:cfd15bd4762a | 91 | i = 5; |
rs27 | 10:cfd15bd4762a | 92 | led_aus(); |
rs27 | 10:cfd15bd4762a | 93 | led4 = 0; |
rs27 | 10:cfd15bd4762a | 94 | break; |
rs27 | 10:cfd15bd4762a | 95 | case 5: |
rs27 | 10:cfd15bd4762a | 96 | i = 6; |
rs27 | 10:cfd15bd4762a | 97 | led_aus(); |
rs27 | 10:cfd15bd4762a | 98 | led5 = 0; |
rs27 | 10:cfd15bd4762a | 99 | break; |
rs27 | 10:cfd15bd4762a | 100 | case 6: |
rs27 | 10:cfd15bd4762a | 101 | i = 7; |
rs27 | 10:cfd15bd4762a | 102 | led_aus(); |
rs27 | 10:cfd15bd4762a | 103 | led6 = 0; |
rs27 | 10:cfd15bd4762a | 104 | break; |
rs27 | 10:cfd15bd4762a | 105 | case 7: |
rs27 | 10:cfd15bd4762a | 106 | i = 8; |
rs27 | 10:cfd15bd4762a | 107 | led_aus(); |
rs27 | 10:cfd15bd4762a | 108 | led7 = 0; |
rs27 | 10:cfd15bd4762a | 109 | break; |
rs27 | 10:cfd15bd4762a | 110 | case 8: // Die LED's sind mit den Ausgängen verbunden und werden mit 1 geschaltet |
rs27 | 10:cfd15bd4762a | 111 | i = 9; |
rs27 | 10:cfd15bd4762a | 112 | led_aus(); |
rs27 | 10:cfd15bd4762a | 113 | out2 = 1; |
rs27 | 10:cfd15bd4762a | 114 | break; |
rs27 | 10:cfd15bd4762a | 115 | case 9: |
rs27 | 10:cfd15bd4762a | 116 | i = 10; |
rs27 | 10:cfd15bd4762a | 117 | led_aus(); |
rs27 | 10:cfd15bd4762a | 118 | out3 = 1; |
rs27 | 10:cfd15bd4762a | 119 | break; |
rs27 | 10:cfd15bd4762a | 120 | case 10: |
rs27 | 10:cfd15bd4762a | 121 | i = 1; |
rs27 | 10:cfd15bd4762a | 122 | led_aus(); |
rs27 | 10:cfd15bd4762a | 123 | out4 = 1; |
rs27 | 10:cfd15bd4762a | 124 | break; |
rs27 | 10:cfd15bd4762a | 125 | } // end switch |
rs27 | 10:cfd15bd4762a | 126 | } // end if(down_timer |
rs27 | 10:cfd15bd4762a | 127 | } // end while(1) |
dan | 0:7dec7e9ac085 | 128 | } |