Display_nums
Dependencies: mbed
Fork of Microprocessors_Template by
Diff: main.cpp
- Revision:
- 3:48be985187c6
- Parent:
- 2:8412c8623314
--- a/main.cpp Thu Feb 22 01:50:12 2018 +0000 +++ b/main.cpp Thu Feb 22 02:32:50 2018 +0000 @@ -26,16 +26,24 @@ #define EIGHT 56 #define NINE 57 -SPI display_ctr(PA_7, PA_6, PA_5); -DigitalOut dsp_ncs(PC_7); +#define SPI_SCLOCK PA_5 +#define SPI_MOSI PA_7 +#define SPI_MISO PA_6 +#define NOT_CHIP_SEL PC_7 + +SPI display_ctr(SPI_MOSI, SPI_MISO, SPI_SCLOCK); +DigitalOut dsp_ncs(NOT_CHIP_SEL); Serial pc(USBTX, USBRX); char input; +int current_digit; void promptUser(); +void write(int digit, int number); int main() { + current_digit = 0; // Setting the formal of display_ctr dsp_ncs = 1; @@ -69,21 +77,25 @@ dsp_ncs = 1; wait(.5); - //dsp_ncs = 0; - //display_ctr.write(0x0104); // write a 4 - //dsp_ncs = 1; - //wait(0.5); - // Sets the display to full brightness dsp_ncs = 0; - display_ctr.write(0x0A); + display_ctr.write(0x0A0F); dsp_ncs = 1; wait(.5); dsp_ncs = 0; + // on start, reset to zero + write(1, 0); + write(2, 0); + write(3, 0); + write(4, 0); + write(5, 0); + + while (1) { promptUser(); + } }// pcw @@ -103,47 +115,64 @@ { case ZERO: pc.printf("You typed 0\n"); - display_ctr.write(0x0100); + write(current_digit, 0); + //display_ctr.write(0x0100); break; case ONE: pc.printf("You typed 1\n"); - display_ctr.write(0x0101); + write(current_digit, 1); break; case TWO: pc.printf("You typed 2\n"); - display_ctr.write(0x0102); + write(current_digit, 2); break; case THREE: pc.printf("You typed 3\n"); - display_ctr.write(0x0103); + write(current_digit, 3); break; case FOUR: pc.printf("You typed 4\n"); - display_ctr.write(0x0104); + write(current_digit, 4); break; case FIVE: pc.printf("You typed 5\n"); - display_ctr.write(0x0105); + write(current_digit, 5); break; case SIX: pc.printf("You typed 6\n"); - display_ctr.write(0x0106); + write(current_digit, 6); break; case SEVEN: pc.printf("You typed 7\n"); - display_ctr.write(0x0107); + write(current_digit, 7); break; case EIGHT: pc.printf("You typed 8\n"); - display_ctr.write(0x0108); + write(current_digit, 8); break; case NINE: - display_ctr.write(0x0109); - pc.printf("You typed 9\n"); + //display_ctr.write(0x0109); + write(current_digit, 9); break; } dsp_ncs = 1; wait(0.5); dsp_ncs = 0; } + current_digit++; + if(current_digit == 6){ + current_digit = 1; + } +} + +void write(int digit, int number){ + int message; + message = digit * 256; + message = message + number; + + dsp_ncs = 0; + display_ctr.write(message); + dsp_ncs = 1; + wait(.5); + dsp_ncs = 0; } \ No newline at end of file