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:
- 11:0e42dd431fb5
- Parent:
- 10:ff8c2470f019
- Child:
- 12:5e4cba1182ab
--- a/main.cpp Sun Jul 14 06:00:56 2013 +0000 +++ b/main.cpp Sun Jul 14 21:18:39 2013 +0000 @@ -7,13 +7,14 @@ Serial pc(USBTX, USBRX); char recv; +char temp; + int state; char cha1_pha, cha2_pha; char cha1_amp, cha2_amp; int ret; -short spi_stream; -short j; +unsigned short spi_stream; 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 @@ -22,7 +23,7 @@ int main() { - pc.baud(115200); //config buad rate + pc.baud(19200); //config buad rate state = MODE_IDLE; line_buf[3] = 0; line_buf[2] = 255; @@ -38,17 +39,16 @@ switch(state) { case MODE_IDLE: - wait(0.1); pc.printf("%s", main_menu); recv = pc.getc(); mode_idle_handler(&state, recv); //pc.printf("%d", state); break; + case MODE_CHA1PHA: 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) @@ -204,7 +204,7 @@ // in display mode case MODE_DISPLAY: - 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); @@ -215,7 +215,7 @@ break; case MODE_HELP: - wait(0.1); + pc.printf("%s", msg_help); pc.printf("%s", msg_ret); pc.getc(); @@ -223,27 +223,39 @@ 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"); + 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); + if(spi_stream >= 0x8000) + { + if(i < 6) + pc.printf("%d ", 1); + else + pc.printf("%d ", 1); + } else - pc.printf(" %d", 0); - - j = j>>1; + { + if(i < 6) + pc.printf("%d ", 0); + else + pc.printf("%d ", 0); + } + spi_stream = spi_stream << 1; } + pc.printf("\n"); pc.printf("%s", msg_ret); pc.getc();