Display_nums
Dependencies: mbed
Fork of Microprocessors_Template by
main.cpp@3:48be985187c6, 2018-02-22 (annotated)
- Committer:
- michaelccodega
- Date:
- Thu Feb 22 02:32:50 2018 +0000
- Revision:
- 3:48be985187c6
- Parent:
- 2:8412c8623314
UPDATE;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
anr41 | 0:24202d4eadef | 1 | /******************************************************************************* |
anr41 | 0:24202d4eadef | 2 | *EECS397 |
anr41 | 0:24202d4eadef | 3 | * |
anr41 | 1:b46d63943c99 | 4 | *Assignment Name: Lab 4 Part 1; Display_nums |
anr41 | 0:24202d4eadef | 5 | * |
anr41 | 0:24202d4eadef | 6 | *Author(s): Ashley Roberson, Michael Codega |
anr41 | 0:24202d4eadef | 7 | * |
anr41 | 0:24202d4eadef | 8 | *Purpose: |
anr41 | 0:24202d4eadef | 9 | * |
anr41 | 1:b46d63943c99 | 10 | *Last Modified: February 15, 2018 |
anr41 | 0:24202d4eadef | 11 | * |
anr41 | 0:24202d4eadef | 12 | *******************************************************************************/ |
anr41 | 0:24202d4eadef | 13 | #include "mbed.h" |
anr41 | 1:b46d63943c99 | 14 | #define DSP_TST_ON 0x0f01 |
anr41 | 1:b46d63943c99 | 15 | #define DSP_TST_OFF 0x0f00 |
anr41 | 0:24202d4eadef | 16 | |
anr41 | 1:b46d63943c99 | 17 | //ASCII character values of decimal numbers |
michaelccodega | 2:8412c8623314 | 18 | #define ZERO 48 |
anr41 | 1:b46d63943c99 | 19 | #define ONE 49 |
anr41 | 1:b46d63943c99 | 20 | #define TWO 50 |
anr41 | 1:b46d63943c99 | 21 | #define THREE 51 |
anr41 | 1:b46d63943c99 | 22 | #define FOUR 52 |
anr41 | 1:b46d63943c99 | 23 | #define FIVE 53 |
anr41 | 1:b46d63943c99 | 24 | #define SIX 54 |
anr41 | 1:b46d63943c99 | 25 | #define SEVEN 55 |
anr41 | 1:b46d63943c99 | 26 | #define EIGHT 56 |
anr41 | 1:b46d63943c99 | 27 | #define NINE 57 |
anr41 | 1:b46d63943c99 | 28 | |
michaelccodega | 3:48be985187c6 | 29 | #define SPI_SCLOCK PA_5 |
michaelccodega | 3:48be985187c6 | 30 | #define SPI_MOSI PA_7 |
michaelccodega | 3:48be985187c6 | 31 | #define SPI_MISO PA_6 |
michaelccodega | 3:48be985187c6 | 32 | #define NOT_CHIP_SEL PC_7 |
michaelccodega | 3:48be985187c6 | 33 | |
michaelccodega | 3:48be985187c6 | 34 | SPI display_ctr(SPI_MOSI, SPI_MISO, SPI_SCLOCK); |
michaelccodega | 3:48be985187c6 | 35 | DigitalOut dsp_ncs(NOT_CHIP_SEL); |
anr41 | 1:b46d63943c99 | 36 | |
anr41 | 1:b46d63943c99 | 37 | Serial pc(USBTX, USBRX); |
anr41 | 1:b46d63943c99 | 38 | char input; |
michaelccodega | 3:48be985187c6 | 39 | int current_digit; |
anr41 | 1:b46d63943c99 | 40 | |
anr41 | 1:b46d63943c99 | 41 | void promptUser(); |
michaelccodega | 3:48be985187c6 | 42 | void write(int digit, int number); |
anr41 | 1:b46d63943c99 | 43 | |
anr41 | 1:b46d63943c99 | 44 | int main() |
anr41 | 1:b46d63943c99 | 45 | { |
michaelccodega | 3:48be985187c6 | 46 | current_digit = 0; |
anr41 | 1:b46d63943c99 | 47 | |
michaelccodega | 2:8412c8623314 | 48 | // Setting the formal of display_ctr |
anr41 | 1:b46d63943c99 | 49 | dsp_ncs = 1; |
anr41 | 1:b46d63943c99 | 50 | display_ctr.format(16, 0); |
michaelccodega | 2:8412c8623314 | 51 | |
michaelccodega | 2:8412c8623314 | 52 | // Setting to Normal Mode |
michaelccodega | 2:8412c8623314 | 53 | dsp_ncs = 0; |
michaelccodega | 2:8412c8623314 | 54 | display_ctr.write(DSP_TST_OFF); //normal mode |
michaelccodega | 2:8412c8623314 | 55 | dsp_ncs = 1; |
michaelccodega | 2:8412c8623314 | 56 | wait(.5); |
anr41 | 0:24202d4eadef | 57 | |
michaelccodega | 2:8412c8623314 | 58 | |
michaelccodega | 2:8412c8623314 | 59 | // Setting it to display 5 digits |
michaelccodega | 2:8412c8623314 | 60 | dsp_ncs = 0; |
michaelccodega | 2:8412c8623314 | 61 | display_ctr.write(0x0b04); //display 5 digits |
michaelccodega | 2:8412c8623314 | 62 | dsp_ncs = 1; |
michaelccodega | 2:8412c8623314 | 63 | wait(.5); |
michaelccodega | 2:8412c8623314 | 64 | |
michaelccodega | 2:8412c8623314 | 65 | /* Setting decode mode */ |
michaelccodega | 2:8412c8623314 | 66 | // This means it only looks at the lower nibble of data, ignoring the |
michaelccodega | 2:8412c8623314 | 67 | // first portion of data |
michaelccodega | 2:8412c8623314 | 68 | dsp_ncs = 0; |
michaelccodega | 2:8412c8623314 | 69 | display_ctr.write(0x090F); //decode mode |
michaelccodega | 2:8412c8623314 | 70 | dsp_ncs = 1; |
michaelccodega | 2:8412c8623314 | 71 | wait(.5); |
michaelccodega | 2:8412c8623314 | 72 | |
michaelccodega | 2:8412c8623314 | 73 | |
michaelccodega | 2:8412c8623314 | 74 | // Setting it to shutdown mode |
michaelccodega | 2:8412c8623314 | 75 | dsp_ncs = 0; |
michaelccodega | 2:8412c8623314 | 76 | display_ctr.write(0x0c01); //shutdown mode |
michaelccodega | 2:8412c8623314 | 77 | dsp_ncs = 1; |
michaelccodega | 2:8412c8623314 | 78 | wait(.5); |
michaelccodega | 2:8412c8623314 | 79 | |
michaelccodega | 2:8412c8623314 | 80 | // Sets the display to full brightness |
michaelccodega | 2:8412c8623314 | 81 | dsp_ncs = 0; |
michaelccodega | 3:48be985187c6 | 82 | display_ctr.write(0x0A0F); |
michaelccodega | 2:8412c8623314 | 83 | dsp_ncs = 1; |
michaelccodega | 2:8412c8623314 | 84 | wait(.5); |
michaelccodega | 2:8412c8623314 | 85 | dsp_ncs = 0; |
michaelccodega | 2:8412c8623314 | 86 | |
michaelccodega | 3:48be985187c6 | 87 | // on start, reset to zero |
michaelccodega | 3:48be985187c6 | 88 | write(1, 0); |
michaelccodega | 3:48be985187c6 | 89 | write(2, 0); |
michaelccodega | 3:48be985187c6 | 90 | write(3, 0); |
michaelccodega | 3:48be985187c6 | 91 | write(4, 0); |
michaelccodega | 3:48be985187c6 | 92 | write(5, 0); |
michaelccodega | 3:48be985187c6 | 93 | |
michaelccodega | 3:48be985187c6 | 94 | |
michaelccodega | 2:8412c8623314 | 95 | while (1) |
michaelccodega | 2:8412c8623314 | 96 | { |
anr41 | 1:b46d63943c99 | 97 | promptUser(); |
michaelccodega | 3:48be985187c6 | 98 | |
anr41 | 1:b46d63943c99 | 99 | } |
michaelccodega | 2:8412c8623314 | 100 | }// pcw |
anr41 | 1:b46d63943c99 | 101 | |
anr41 | 1:b46d63943c99 | 102 | //Prompt User for Numbers |
anr41 | 1:b46d63943c99 | 103 | void promptUser() |
anr41 | 1:b46d63943c99 | 104 | { |
michaelccodega | 2:8412c8623314 | 105 | pc.printf("Please enter a number 0-9:\n"); |
anr41 | 1:b46d63943c99 | 106 | input = pc.getc(); |
michaelccodega | 2:8412c8623314 | 107 | if (input < 48 || input > 57) |
michaelccodega | 2:8412c8623314 | 108 | { |
anr41 | 1:b46d63943c99 | 109 | pc.printf("Invalid Number.\n"); |
anr41 | 1:b46d63943c99 | 110 | promptUser(); |
michaelccodega | 2:8412c8623314 | 111 | } |
michaelccodega | 2:8412c8623314 | 112 | else |
michaelccodega | 2:8412c8623314 | 113 | { |
michaelccodega | 2:8412c8623314 | 114 | switch (input) |
michaelccodega | 2:8412c8623314 | 115 | { |
michaelccodega | 2:8412c8623314 | 116 | case ZERO: |
michaelccodega | 2:8412c8623314 | 117 | pc.printf("You typed 0\n"); |
michaelccodega | 3:48be985187c6 | 118 | write(current_digit, 0); |
michaelccodega | 3:48be985187c6 | 119 | //display_ctr.write(0x0100); |
michaelccodega | 2:8412c8623314 | 120 | break; |
michaelccodega | 2:8412c8623314 | 121 | case ONE: |
michaelccodega | 2:8412c8623314 | 122 | pc.printf("You typed 1\n"); |
michaelccodega | 3:48be985187c6 | 123 | write(current_digit, 1); |
michaelccodega | 2:8412c8623314 | 124 | break; |
michaelccodega | 2:8412c8623314 | 125 | case TWO: |
michaelccodega | 2:8412c8623314 | 126 | pc.printf("You typed 2\n"); |
michaelccodega | 3:48be985187c6 | 127 | write(current_digit, 2); |
michaelccodega | 2:8412c8623314 | 128 | break; |
michaelccodega | 2:8412c8623314 | 129 | case THREE: |
michaelccodega | 2:8412c8623314 | 130 | pc.printf("You typed 3\n"); |
michaelccodega | 3:48be985187c6 | 131 | write(current_digit, 3); |
michaelccodega | 2:8412c8623314 | 132 | break; |
michaelccodega | 2:8412c8623314 | 133 | case FOUR: |
michaelccodega | 2:8412c8623314 | 134 | pc.printf("You typed 4\n"); |
michaelccodega | 3:48be985187c6 | 135 | write(current_digit, 4); |
michaelccodega | 2:8412c8623314 | 136 | break; |
michaelccodega | 2:8412c8623314 | 137 | case FIVE: |
michaelccodega | 2:8412c8623314 | 138 | pc.printf("You typed 5\n"); |
michaelccodega | 3:48be985187c6 | 139 | write(current_digit, 5); |
michaelccodega | 2:8412c8623314 | 140 | break; |
michaelccodega | 2:8412c8623314 | 141 | case SIX: |
michaelccodega | 2:8412c8623314 | 142 | pc.printf("You typed 6\n"); |
michaelccodega | 3:48be985187c6 | 143 | write(current_digit, 6); |
michaelccodega | 2:8412c8623314 | 144 | break; |
michaelccodega | 2:8412c8623314 | 145 | case SEVEN: |
michaelccodega | 2:8412c8623314 | 146 | pc.printf("You typed 7\n"); |
michaelccodega | 3:48be985187c6 | 147 | write(current_digit, 7); |
michaelccodega | 2:8412c8623314 | 148 | break; |
michaelccodega | 2:8412c8623314 | 149 | case EIGHT: |
michaelccodega | 2:8412c8623314 | 150 | pc.printf("You typed 8\n"); |
michaelccodega | 3:48be985187c6 | 151 | write(current_digit, 8); |
michaelccodega | 2:8412c8623314 | 152 | break; |
michaelccodega | 2:8412c8623314 | 153 | case NINE: |
michaelccodega | 3:48be985187c6 | 154 | //display_ctr.write(0x0109); |
michaelccodega | 3:48be985187c6 | 155 | write(current_digit, 9); |
michaelccodega | 2:8412c8623314 | 156 | break; |
anr41 | 1:b46d63943c99 | 157 | } |
anr41 | 1:b46d63943c99 | 158 | dsp_ncs = 1; |
anr41 | 1:b46d63943c99 | 159 | wait(0.5); |
michaelccodega | 2:8412c8623314 | 160 | dsp_ncs = 0; |
anr41 | 1:b46d63943c99 | 161 | } |
michaelccodega | 3:48be985187c6 | 162 | current_digit++; |
michaelccodega | 3:48be985187c6 | 163 | if(current_digit == 6){ |
michaelccodega | 3:48be985187c6 | 164 | current_digit = 1; |
michaelccodega | 3:48be985187c6 | 165 | } |
michaelccodega | 3:48be985187c6 | 166 | } |
michaelccodega | 3:48be985187c6 | 167 | |
michaelccodega | 3:48be985187c6 | 168 | void write(int digit, int number){ |
michaelccodega | 3:48be985187c6 | 169 | int message; |
michaelccodega | 3:48be985187c6 | 170 | message = digit * 256; |
michaelccodega | 3:48be985187c6 | 171 | message = message + number; |
michaelccodega | 3:48be985187c6 | 172 | |
michaelccodega | 3:48be985187c6 | 173 | dsp_ncs = 0; |
michaelccodega | 3:48be985187c6 | 174 | display_ctr.write(message); |
michaelccodega | 3:48be985187c6 | 175 | dsp_ncs = 1; |
michaelccodega | 3:48be985187c6 | 176 | wait(.5); |
michaelccodega | 3:48be985187c6 | 177 | dsp_ncs = 0; |
anr41 | 1:b46d63943c99 | 178 | } |