![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for operation of relay switch
main.cpp@0:845fb927f526, 2015-11-02 (annotated)
- Committer:
- shekhar
- Date:
- Mon Nov 02 07:34:11 2015 +0000
- Revision:
- 0:845fb927f526
- Child:
- 1:e7eb16963bcb
Final code for relay switching mechanism
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shekhar | 0:845fb927f526 | 1 | //checked for pulse duration of 1ms,3ms, 5ms, 100ms, 300ms - working for all! |
shekhar | 0:845fb927f526 | 2 | |
shekhar | 0:845fb927f526 | 3 | #include "mbed.h" |
shekhar | 0:845fb927f526 | 4 | void writereg(uint8_t ,uint8_t ); |
shekhar | 0:845fb927f526 | 5 | uint8_t readreg(uint8_t); |
shekhar | 0:845fb927f526 | 6 | Serial pc(USBTX, USBRX); |
shekhar | 0:845fb927f526 | 7 | DigitalOut BCN(D10); //slave select or chip select |
shekhar | 0:845fb927f526 | 8 | DigitalOut TX(D9); //slave select or chip select |
shekhar | 0:845fb927f526 | 9 | |
shekhar | 0:845fb927f526 | 10 | main() |
shekhar | 0:845fb927f526 | 11 | { |
shekhar | 0:845fb927f526 | 12 | char ch; |
shekhar | 0:845fb927f526 | 13 | while(1){ |
shekhar | 0:845fb927f526 | 14 | printf("press any char\n"); |
shekhar | 0:845fb927f526 | 15 | ch = pc.getc(); |
shekhar | 0:845fb927f526 | 16 | //putchar(ch); |
shekhar | 0:845fb927f526 | 17 | if(ch == 'A') |
shekhar | 0:845fb927f526 | 18 | { |
shekhar | 0:845fb927f526 | 19 | //cs2 = 0; |
shekhar | 0:845fb927f526 | 20 | putchar(ch); |
shekhar | 0:845fb927f526 | 21 | BCN = 1; |
shekhar | 0:845fb927f526 | 22 | wait_ms(5);//min 1 ms |
shekhar | 0:845fb927f526 | 23 | BCN = 0; |
shekhar | 0:845fb927f526 | 24 | } |
shekhar | 0:845fb927f526 | 25 | if(ch == 'B') |
shekhar | 0:845fb927f526 | 26 | { |
shekhar | 0:845fb927f526 | 27 | //cs1 = 0; |
shekhar | 0:845fb927f526 | 28 | putchar(ch); |
shekhar | 0:845fb927f526 | 29 | TX = 1; |
shekhar | 0:845fb927f526 | 30 | wait_ms(5);//min 1 ms |
shekhar | 0:845fb927f526 | 31 | TX = 0; |
shekhar | 0:845fb927f526 | 32 | }} |
shekhar | 0:845fb927f526 | 33 | } |