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:
- 10:ff8c2470f019
- Parent:
- 9:3eaacc1ad758
- Child:
- 11:0e42dd431fb5
--- a/main.cpp Sat Jul 13 23:49:04 2013 +0000 +++ b/main.cpp Sun Jul 14 06:00:56 2013 +0000 @@ -12,10 +12,13 @@ char cha1_amp, cha2_amp; int ret; -short spi_data; +short spi_stream; +short j; + char line_buf[4]; //line_buf[3] is used to indicate if it's empty 0 empty 1 not 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() { @@ -25,12 +28,17 @@ line_buf[2] = 255; line_buf[1] = 255; line_buf[0] = 255; + cha1_pha = 0; + cha2_pha = 0; + cha1_amp = 0; + cha2_amp = 0; while(1) { switch(state) { case MODE_IDLE: + wait(0.1); pc.printf("%s", main_menu); recv = pc.getc(); mode_idle_handler(&state, recv); @@ -40,6 +48,7 @@ case MODE_CHA1AMP: case MODE_CHA2PHA: case MODE_CHA2AMP: + wait(0.1); if(state == MODE_CHA1PHA) pc.printf("%s", cmd1); else if(state == MODE_CHA1AMP) @@ -195,22 +204,51 @@ // in display mode case MODE_DISPLAY: - pc.printf("Current phase shift value for channel 1 is %d degrees\n", cha1_pha*-7); - pc.printf("Current phase shift value for channel 2 is %d degrees\n", cha2_pha*-7); - pc.printf("Current attentuation for channel 1 is %.1f dB\n", cha1_amp*5.0/10.0); - pc.printf("Current attentuation for channel 2 is %.1f dB\n", cha2_amp*5.0/10.0); + wait(0.1); + 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); + pc.printf("Attentuation for channel 1 is %.1f dB\n", cha1_amp*5.0/10.0); + pc.printf("Attentuation for channel 2 is %.1f dB\n", cha2_amp*5.0/10.0); pc.printf("%s", msg_ret); pc.getc(); state = MODE_IDLE; break; case MODE_HELP: + wait(0.1); pc.printf("%s", msg_help); pc.printf("%s", msg_ret); pc.getc(); state = MODE_IDLE; break; + case MODE_SEND: + wait(0.1); + 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); + pc.printf("Attentuation for channel 1 is %.1f dB\n", cha1_amp*5.0/10.0); + pc.printf("Attentuation for channel 2 is %.1f dB\n", cha2_amp*5.0/10.0); + pc.printf("\nspi bit stream:\n"); + for(i=15; i>=0; i--) + pc.printf("Bit%d ", i); + pc.printf("\n"); + spi_stream = 0; + j = 0x8000; + spi_stream = (cha2_amp << 12) | (cha2_pha << 8) | (cha1_amp << 4) | (cha1_pha); + for(i=0; i<=15; i++) + { + if(spi_stream >= j) + pc.printf(" %d", 1); + else + pc.printf(" %d", 0); + + j = j>>1; + } + pc.printf("\n"); + pc.printf("%s", msg_ret); + pc.getc(); + state = MODE_IDLE; + break; default: state = MODE_IDLE; }