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.
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX,USBRX); 00004 BusOut myled(LED1,LED2,LED3,LED4); // all leds of mbed lsb -> msb 00005 DigitalOut ssel(p24); // SSEL pio1_11/mbed p24 00006 SPI spi(p5, p6, p7); // mosi, miso, sclk 00007 00008 BusOut rgb(p26,p18,p25); // red, blue, green 00009 InterruptIn button(p12); // 0= active/pushed 00010 00011 // rgb buss assignments 00012 #define RGB_RED 0x01 00013 #define RGB_BLUE 0x02 00014 #define RGB_GREEN 0x04 00015 00016 /* 7 Segment Display - this Rev A layout is rotated 180 degrees such that the 00017 decimal point is at the Top/Left 00018 00019 Rev A schematic defines segent order as: 00020 00021 msb 7 6 5 4 3 2 1 0 00022 F C . B A G E D 00023 00024 but setting individual segments shows: 00025 msb 7 6 5 4 3 2 1 0 00026 F . E D G B A C 00027 00028 00029 --A-- 00030 | | 00031 F B 00032 | | 00033 --G-- 00034 | | 00035 E C 00036 | | 00037 --D-- 00038 */ 00039 00040 // actual segments 00041 #define SA 0xfd 00042 #define SB 0xfb 00043 #define SC 0xfe 00044 #define SD 0xef 00045 #define SE 0xdf 00046 #define SF 0x7f 00047 #define SG 0xf7 00048 #define SDP 0xbf 00049 00050 00051 #define WTIME 2.5 // delay between cycles 00052 00053 short curTest = 0; // 0= all segments, 1= march segments 00054 00055 /* nextTest ** Interrupt Event for pin fall ** 00056 00057 Advance curTest 00058 */ 00059 00060 void nextTest(void) { 00061 curTest++; 00062 if (curTest >= 3) 00063 curTest = 0; 00064 } 00065 00066 /* setIO 00067 00068 This procedure is used to set the following I/P ports: 00069 00070 ph myLed Shows the test phase 00071 sv SPI 7-Segment value 0=On 00072 lc RGB Led Color 00073 */ 00074 void setIO(short ph, short sv, short lc) { 00075 myled = ph; // identify phase 00076 00077 ssel = 0; // start ssel (sets RCLK to 0) 00078 spi.write(sv); // write to the shift register 00079 ssel = 1; // Toggle RCLK/STCP to apply the SR --> NumDisplay (Rising edge action) 00080 00081 rgb = lc; // set led color 00082 wait(WTIME); // common delay 00083 } 00084 00085 /* groupSegs 00086 00087 This test groups all segments (G:A and DP) 00088 00089 1: Segs=Off, DP=Off, Red 00090 2: Segs=Off, DP=On, Green 00091 3: Segs:On, DP=Off, Blue 00092 4: Segs=On, DP=On, RGB 00093 */ 00094 void groupSegs(void) { 00095 00096 setIO(1,0xff,RGB_RED); // 1: all Off, Red 00097 setIO(2,0xbf,RGB_GREEN); // 2: b6 decimal on, others OFF, Green 00098 setIO(4,0x40,RGB_BLUE); // 3: b6 decimal off, others On, Blue 00099 setIO(8,0x00,RGB_RED | RGB_GREEN | RGB_BLUE); // 3: all on, all colors 00100 } 00101 00102 /* marchBits 00103 00104 Marches by bit position: 0 -> 7 00105 00106 This test marches the bits Low to turn on each segment 00107 in the order of bit 0 --> bit 7 00108 00109 The initail setting is phase F and all segments Off 00110 */ 00111 00112 void marchBits(void) { 00113 setIO(0xf,0xff,0); // 1: all Off 00114 setIO(0,0xfe,0); // 2: b0 00115 setIO(1,0xfd,0); // 3: b1 00116 setIO(2,0xfb,0); // 4: b2 00117 setIO(3,0xf7,0); // 1: b3 00118 setIO(4,0xef,0); // 2: b4 00119 setIO(5,0xdf,0); // 3: b5 00120 setIO(6,0xbf,0); // 4: b6 00121 setIO(7,0x7f,0); // 4: b7 00122 } 00123 00124 /* marchSegs 00125 00126 Marches by Segments: A -> G, DP 00127 00128 This test marches the bits Low to turn on each segment 00129 in the order of the segments A -> G, DP 00130 00131 The initail setting is phase F and all segments Off 00132 */ 00133 00134 void marchSegs(void) { 00135 setIO(0xf,0xff,0); // 1: all Off 00136 setIO(0,SA,0); // 2: b1 00137 setIO(1,SB,0); // 3: b2 00138 setIO(2,SC,0); // 4: b0 00139 setIO(3,SD,0); // 1: b4 00140 setIO(4,SE,0); // 2: b5 00141 setIO(5,SF,0); // 3: b7 00142 setIO(6,SG,0); // 4: b3 00143 setIO(7,SDP,0); // 4: b6 00144 } 00145 00146 00147 /* main 00148 00149 */ 00150 int main() { 00151 pc.printf("\nEA: Segment & Board I/O Tests\n"); 00152 pc.printf("\n Depress/Push Joystick to change tests at end of test cycle\n"); 00153 button.fall(&nextTest); 00154 00155 myled = 0; 00156 spi.format(8,1); // set format as 8b/pol:pha=0 00157 spi.frequency(1000000); // default is 1mhz 00158 00159 /* curTest is advanced by the depression/push down of the Joystick */ 00160 while(1) { 00161 switch (curTest){ 00162 case 0: 00163 printf(" Group Segments & RGB Led...\n"); 00164 groupSegs(); 00165 break; 00166 00167 case 1: 00168 printf(" March Bits b0 => b7...\n"); 00169 marchBits(); 00170 break; 00171 00172 case 2: 00173 printf(" March Segments SA => SG, DP...\n"); 00174 marchSegs(); 00175 break; 00176 00177 default: curTest = 0; break; 00178 } 00179 } 00180 } 00181 00182
Generated on Wed Jul 13 2022 08:09:02 by
1.7.2