Rick Drolet
/
EA_SegIoTest
EA Base Board Simple I/O Tests
main.cpp@0:bd580f96eb45, 2010-03-30 (annotated)
- Committer:
- caprock
- Date:
- Tue Mar 30 21:39:07 2010 +0000
- Revision:
- 0:bd580f96eb45
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caprock | 0:bd580f96eb45 | 1 | #include "mbed.h" |
caprock | 0:bd580f96eb45 | 2 | |
caprock | 0:bd580f96eb45 | 3 | Serial pc(USBTX,USBRX); |
caprock | 0:bd580f96eb45 | 4 | BusOut myled(LED1,LED2,LED3,LED4); // all leds of mbed lsb -> msb |
caprock | 0:bd580f96eb45 | 5 | DigitalOut ssel(p24); // SSEL pio1_11/mbed p24 |
caprock | 0:bd580f96eb45 | 6 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
caprock | 0:bd580f96eb45 | 7 | |
caprock | 0:bd580f96eb45 | 8 | BusOut rgb(p26,p18,p25); // red, blue, green |
caprock | 0:bd580f96eb45 | 9 | InterruptIn button(p12); // 0= active/pushed |
caprock | 0:bd580f96eb45 | 10 | |
caprock | 0:bd580f96eb45 | 11 | // rgb buss assignments |
caprock | 0:bd580f96eb45 | 12 | #define RGB_RED 0x01 |
caprock | 0:bd580f96eb45 | 13 | #define RGB_BLUE 0x02 |
caprock | 0:bd580f96eb45 | 14 | #define RGB_GREEN 0x04 |
caprock | 0:bd580f96eb45 | 15 | |
caprock | 0:bd580f96eb45 | 16 | /* 7 Segment Display - this Rev A layout is rotated 180 degrees such that the |
caprock | 0:bd580f96eb45 | 17 | decimal point is at the Top/Left |
caprock | 0:bd580f96eb45 | 18 | |
caprock | 0:bd580f96eb45 | 19 | Rev A schematic defines segent order as: |
caprock | 0:bd580f96eb45 | 20 | |
caprock | 0:bd580f96eb45 | 21 | msb 7 6 5 4 3 2 1 0 |
caprock | 0:bd580f96eb45 | 22 | F C . B A G E D |
caprock | 0:bd580f96eb45 | 23 | |
caprock | 0:bd580f96eb45 | 24 | but setting individual segments shows: |
caprock | 0:bd580f96eb45 | 25 | msb 7 6 5 4 3 2 1 0 |
caprock | 0:bd580f96eb45 | 26 | F . E D G B A C |
caprock | 0:bd580f96eb45 | 27 | |
caprock | 0:bd580f96eb45 | 28 | |
caprock | 0:bd580f96eb45 | 29 | --A-- |
caprock | 0:bd580f96eb45 | 30 | | | |
caprock | 0:bd580f96eb45 | 31 | F B |
caprock | 0:bd580f96eb45 | 32 | | | |
caprock | 0:bd580f96eb45 | 33 | --G-- |
caprock | 0:bd580f96eb45 | 34 | | | |
caprock | 0:bd580f96eb45 | 35 | E C |
caprock | 0:bd580f96eb45 | 36 | | | |
caprock | 0:bd580f96eb45 | 37 | --D-- |
caprock | 0:bd580f96eb45 | 38 | */ |
caprock | 0:bd580f96eb45 | 39 | |
caprock | 0:bd580f96eb45 | 40 | // actual segments |
caprock | 0:bd580f96eb45 | 41 | #define SA 0xfd |
caprock | 0:bd580f96eb45 | 42 | #define SB 0xfb |
caprock | 0:bd580f96eb45 | 43 | #define SC 0xfe |
caprock | 0:bd580f96eb45 | 44 | #define SD 0xef |
caprock | 0:bd580f96eb45 | 45 | #define SE 0xdf |
caprock | 0:bd580f96eb45 | 46 | #define SF 0x7f |
caprock | 0:bd580f96eb45 | 47 | #define SG 0xf7 |
caprock | 0:bd580f96eb45 | 48 | #define SDP 0xbf |
caprock | 0:bd580f96eb45 | 49 | |
caprock | 0:bd580f96eb45 | 50 | |
caprock | 0:bd580f96eb45 | 51 | #define WTIME 2.5 // delay between cycles |
caprock | 0:bd580f96eb45 | 52 | |
caprock | 0:bd580f96eb45 | 53 | short curTest = 0; // 0= all segments, 1= march segments |
caprock | 0:bd580f96eb45 | 54 | |
caprock | 0:bd580f96eb45 | 55 | /* nextTest ** Interrupt Event for pin fall ** |
caprock | 0:bd580f96eb45 | 56 | |
caprock | 0:bd580f96eb45 | 57 | Advance curTest |
caprock | 0:bd580f96eb45 | 58 | */ |
caprock | 0:bd580f96eb45 | 59 | |
caprock | 0:bd580f96eb45 | 60 | void nextTest(void) { |
caprock | 0:bd580f96eb45 | 61 | curTest++; |
caprock | 0:bd580f96eb45 | 62 | if (curTest >= 3) |
caprock | 0:bd580f96eb45 | 63 | curTest = 0; |
caprock | 0:bd580f96eb45 | 64 | } |
caprock | 0:bd580f96eb45 | 65 | |
caprock | 0:bd580f96eb45 | 66 | /* setIO |
caprock | 0:bd580f96eb45 | 67 | |
caprock | 0:bd580f96eb45 | 68 | This procedure is used to set the following I/P ports: |
caprock | 0:bd580f96eb45 | 69 | |
caprock | 0:bd580f96eb45 | 70 | ph myLed Shows the test phase |
caprock | 0:bd580f96eb45 | 71 | sv SPI 7-Segment value 0=On |
caprock | 0:bd580f96eb45 | 72 | lc RGB Led Color |
caprock | 0:bd580f96eb45 | 73 | */ |
caprock | 0:bd580f96eb45 | 74 | void setIO(short ph, short sv, short lc) { |
caprock | 0:bd580f96eb45 | 75 | myled = ph; // identify phase |
caprock | 0:bd580f96eb45 | 76 | |
caprock | 0:bd580f96eb45 | 77 | ssel = 0; // start ssel (sets RCLK to 0) |
caprock | 0:bd580f96eb45 | 78 | spi.write(sv); // write to the shift register |
caprock | 0:bd580f96eb45 | 79 | ssel = 1; // Toggle RCLK/STCP to apply the SR --> NumDisplay (Rising edge action) |
caprock | 0:bd580f96eb45 | 80 | |
caprock | 0:bd580f96eb45 | 81 | rgb = lc; // set led color |
caprock | 0:bd580f96eb45 | 82 | wait(WTIME); // common delay |
caprock | 0:bd580f96eb45 | 83 | } |
caprock | 0:bd580f96eb45 | 84 | |
caprock | 0:bd580f96eb45 | 85 | /* groupSegs |
caprock | 0:bd580f96eb45 | 86 | |
caprock | 0:bd580f96eb45 | 87 | This test groups all segments (G:A and DP) |
caprock | 0:bd580f96eb45 | 88 | |
caprock | 0:bd580f96eb45 | 89 | 1: Segs=Off, DP=Off, Red |
caprock | 0:bd580f96eb45 | 90 | 2: Segs=Off, DP=On, Green |
caprock | 0:bd580f96eb45 | 91 | 3: Segs:On, DP=Off, Blue |
caprock | 0:bd580f96eb45 | 92 | 4: Segs=On, DP=On, RGB |
caprock | 0:bd580f96eb45 | 93 | */ |
caprock | 0:bd580f96eb45 | 94 | void groupSegs(void) { |
caprock | 0:bd580f96eb45 | 95 | |
caprock | 0:bd580f96eb45 | 96 | setIO(1,0xff,RGB_RED); // 1: all Off, Red |
caprock | 0:bd580f96eb45 | 97 | setIO(2,0xbf,RGB_GREEN); // 2: b6 decimal on, others OFF, Green |
caprock | 0:bd580f96eb45 | 98 | setIO(4,0x40,RGB_BLUE); // 3: b6 decimal off, others On, Blue |
caprock | 0:bd580f96eb45 | 99 | setIO(8,0x00,RGB_RED | RGB_GREEN | RGB_BLUE); // 3: all on, all colors |
caprock | 0:bd580f96eb45 | 100 | } |
caprock | 0:bd580f96eb45 | 101 | |
caprock | 0:bd580f96eb45 | 102 | /* marchBits |
caprock | 0:bd580f96eb45 | 103 | |
caprock | 0:bd580f96eb45 | 104 | Marches by bit position: 0 -> 7 |
caprock | 0:bd580f96eb45 | 105 | |
caprock | 0:bd580f96eb45 | 106 | This test marches the bits Low to turn on each segment |
caprock | 0:bd580f96eb45 | 107 | in the order of bit 0 --> bit 7 |
caprock | 0:bd580f96eb45 | 108 | |
caprock | 0:bd580f96eb45 | 109 | The initail setting is phase F and all segments Off |
caprock | 0:bd580f96eb45 | 110 | */ |
caprock | 0:bd580f96eb45 | 111 | |
caprock | 0:bd580f96eb45 | 112 | void marchBits(void) { |
caprock | 0:bd580f96eb45 | 113 | setIO(0xf,0xff,0); // 1: all Off |
caprock | 0:bd580f96eb45 | 114 | setIO(0,0xfe,0); // 2: b0 |
caprock | 0:bd580f96eb45 | 115 | setIO(1,0xfd,0); // 3: b1 |
caprock | 0:bd580f96eb45 | 116 | setIO(2,0xfb,0); // 4: b2 |
caprock | 0:bd580f96eb45 | 117 | setIO(3,0xf7,0); // 1: b3 |
caprock | 0:bd580f96eb45 | 118 | setIO(4,0xef,0); // 2: b4 |
caprock | 0:bd580f96eb45 | 119 | setIO(5,0xdf,0); // 3: b5 |
caprock | 0:bd580f96eb45 | 120 | setIO(6,0xbf,0); // 4: b6 |
caprock | 0:bd580f96eb45 | 121 | setIO(7,0x7f,0); // 4: b7 |
caprock | 0:bd580f96eb45 | 122 | } |
caprock | 0:bd580f96eb45 | 123 | |
caprock | 0:bd580f96eb45 | 124 | /* marchSegs |
caprock | 0:bd580f96eb45 | 125 | |
caprock | 0:bd580f96eb45 | 126 | Marches by Segments: A -> G, DP |
caprock | 0:bd580f96eb45 | 127 | |
caprock | 0:bd580f96eb45 | 128 | This test marches the bits Low to turn on each segment |
caprock | 0:bd580f96eb45 | 129 | in the order of the segments A -> G, DP |
caprock | 0:bd580f96eb45 | 130 | |
caprock | 0:bd580f96eb45 | 131 | The initail setting is phase F and all segments Off |
caprock | 0:bd580f96eb45 | 132 | */ |
caprock | 0:bd580f96eb45 | 133 | |
caprock | 0:bd580f96eb45 | 134 | void marchSegs(void) { |
caprock | 0:bd580f96eb45 | 135 | setIO(0xf,0xff,0); // 1: all Off |
caprock | 0:bd580f96eb45 | 136 | setIO(0,SA,0); // 2: b1 |
caprock | 0:bd580f96eb45 | 137 | setIO(1,SB,0); // 3: b2 |
caprock | 0:bd580f96eb45 | 138 | setIO(2,SC,0); // 4: b0 |
caprock | 0:bd580f96eb45 | 139 | setIO(3,SD,0); // 1: b4 |
caprock | 0:bd580f96eb45 | 140 | setIO(4,SE,0); // 2: b5 |
caprock | 0:bd580f96eb45 | 141 | setIO(5,SF,0); // 3: b7 |
caprock | 0:bd580f96eb45 | 142 | setIO(6,SG,0); // 4: b3 |
caprock | 0:bd580f96eb45 | 143 | setIO(7,SDP,0); // 4: b6 |
caprock | 0:bd580f96eb45 | 144 | } |
caprock | 0:bd580f96eb45 | 145 | |
caprock | 0:bd580f96eb45 | 146 | |
caprock | 0:bd580f96eb45 | 147 | /* main |
caprock | 0:bd580f96eb45 | 148 | |
caprock | 0:bd580f96eb45 | 149 | */ |
caprock | 0:bd580f96eb45 | 150 | int main() { |
caprock | 0:bd580f96eb45 | 151 | pc.printf("\nEA: Segment & Board I/O Tests\n"); |
caprock | 0:bd580f96eb45 | 152 | pc.printf("\n Depress/Push Joystick to change tests at end of test cycle\n"); |
caprock | 0:bd580f96eb45 | 153 | button.fall(&nextTest); |
caprock | 0:bd580f96eb45 | 154 | |
caprock | 0:bd580f96eb45 | 155 | myled = 0; |
caprock | 0:bd580f96eb45 | 156 | spi.format(8,1); // set format as 8b/pol:pha=0 |
caprock | 0:bd580f96eb45 | 157 | spi.frequency(1000000); // default is 1mhz |
caprock | 0:bd580f96eb45 | 158 | |
caprock | 0:bd580f96eb45 | 159 | /* curTest is advanced by the depression/push down of the Joystick */ |
caprock | 0:bd580f96eb45 | 160 | while(1) { |
caprock | 0:bd580f96eb45 | 161 | switch (curTest){ |
caprock | 0:bd580f96eb45 | 162 | case 0: |
caprock | 0:bd580f96eb45 | 163 | printf(" Group Segments & RGB Led...\n"); |
caprock | 0:bd580f96eb45 | 164 | groupSegs(); |
caprock | 0:bd580f96eb45 | 165 | break; |
caprock | 0:bd580f96eb45 | 166 | |
caprock | 0:bd580f96eb45 | 167 | case 1: |
caprock | 0:bd580f96eb45 | 168 | printf(" March Bits b0 => b7...\n"); |
caprock | 0:bd580f96eb45 | 169 | marchBits(); |
caprock | 0:bd580f96eb45 | 170 | break; |
caprock | 0:bd580f96eb45 | 171 | |
caprock | 0:bd580f96eb45 | 172 | case 2: |
caprock | 0:bd580f96eb45 | 173 | printf(" March Segments SA => SG, DP...\n"); |
caprock | 0:bd580f96eb45 | 174 | marchSegs(); |
caprock | 0:bd580f96eb45 | 175 | break; |
caprock | 0:bd580f96eb45 | 176 | |
caprock | 0:bd580f96eb45 | 177 | default: curTest = 0; break; |
caprock | 0:bd580f96eb45 | 178 | } |
caprock | 0:bd580f96eb45 | 179 | } |
caprock | 0:bd580f96eb45 | 180 | } |
caprock | 0:bd580f96eb45 | 181 | |
caprock | 0:bd580f96eb45 | 182 |