UART to Labview
Dependencies: mbed
Revision 0:bb5e43ae643e, committed 2016-03-16
- Comitter:
- hoting
- Date:
- Wed Mar 16 13:28:07 2016 +0000
- Commit message:
- UART to Labview
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r bb5e43ae643e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 16 13:28:07 2016 +0000 @@ -0,0 +1,71 @@ +#include "mbed.h" + +Ticker timer1; +Serial pc(USBTX, USBRX); +//Serial pc(D10, D2); + +union splitter { + short j; + char C[2]; + // C[0]就會等於j的lowbyte, C[1]就會等於j的hibyte +}; +char T[4] = {255,255,0,0}; +int i = 0; +int k = 0; + +//函式宣告 +void init_TIMER(); +void timer1_ITR(); +void init_UART(); +void UART_TX(); + +int main() +{ + init_TIMER(); + init_UART(); + while(1) { + } +} + +void init_TIMER() +{ + timer1.attach_us(&timer1_ITR, 1000); // 1ms進一次timer1中斷 +} + +void timer1_ITR() +{ + UART_TX(); +} + +void init_UART() +{ + pc.baud(115200); // baud rate設為115200 +} + +void UART_TX() +{ + splitter splitter1; + + //數值範圍:-32768~32768 + splitter1.j = -30000; + + T[2] = splitter1.C[0]; + T[3] = splitter1.C[1]; + + while (1) { + if (pc.writeable() == 1) { + pc.putc(T[i]); + i++; + k++; + } + if (k>1) { + k = 0; + break; + } + if (i>3) { + i = 0; + k = 0; + break; + } + } +} \ No newline at end of file
diff -r 000000000000 -r bb5e43ae643e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 16 13:28:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3 \ No newline at end of file