Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 12:5e4cba1182ab
- Parent:
- 11:0e42dd431fb5
- Child:
- 13:8d9c273b607d
--- a/main.cpp Sun Jul 14 21:18:39 2013 +0000 +++ b/main.cpp Sun Jul 14 22:38:44 2013 +0000 @@ -1,3 +1,14 @@ +//This main funtion mainly implements a mode transfer. +//When mcu resets, it's in MODE_IDLE. Then depends on the keyboard input, the +//mode switches to transition modes such as +//MODE_CHAxPHA, which is for phase input of channel x, or +//MODE_CHAxAMP, which is for attenuation input of channel x, or +//MODE_DISPLAY, which is for displaying the current parameters, or +//MODE_HELP, which is for displaying the help infomation, or +//MODE_SEND, which is for sending the bit stream through the SPI bus. +//After each transition mode completes, mcu returns to MODE_IDLE to wait for another user input. + + #include "mbed.h" #include "menu.h" #include "parameters.h" @@ -16,14 +27,14 @@ unsigned short spi_stream; -char line_buf[4]; //line_buf[3] is used to indicate if it's empty 0 empty 1 not +char line_buf[4]; //line_buf[3] is used to indicate if it's empty 0 empty 1 not, other bytes for char data int line_pt; //line buffer pointer points to next buffer location it's going to write int line_length; //store the current line length int i; int main() { - pc.baud(19200); //config buad rate + pc.baud(19200); //config buad rate. Note: 115200 seems too high for the current board state = MODE_IDLE; line_buf[3] = 0; line_buf[2] = 255; @@ -65,7 +76,7 @@ line_pt = 0; line_length = 0; - while(1) //input into line buffer, terminated by enter key + while(1) //Character input into line buffer, terminated by enter key { recv = pc.getc(); if(recv == 13) //enter is pressed, break @@ -110,7 +121,7 @@ } } //input over, now checking - //check phase input + //check phase shift input if(state == MODE_CHA1PHA || state == MODE_CHA2PHA) { if(state == MODE_CHA1PHA) @@ -202,7 +213,7 @@ state = MODE_IDLE; //back to idle state after input break; - // in display mode + // In display mode, show current parameters case MODE_DISPLAY: pc.printf("Phase shift value for channel 1 is %d degrees\n", cha1_pha*-7); @@ -213,7 +224,7 @@ pc.getc(); state = MODE_IDLE; break; - + //Help mode, displays help info case MODE_HELP: pc.printf("%s", msg_help); @@ -222,7 +233,7 @@ state = MODE_IDLE; break; - case MODE_SEND: + case MODE_SEND: //In sending mode, display and send through SPI pc.printf("Phase shift value for channel 1 is %d degrees\n", cha1_pha*-7); pc.printf("Phase shift value for channel 2 is %d degrees\n", cha2_pha*-7);