Jasper Wallace
/
dispatcher
Dispatch console driver.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut green(p22); 00004 DigitalOut red(p21); 00005 DigitalOut led1(LED1); 00006 DigitalOut led2(LED2); 00007 DigitalOut led3(LED3); 00008 DigitalOut led4(LED4); 00009 00010 #define CH7 0x00000001 00011 #define KEY_HASH 0x00000002 00012 #define CH6 0x00000004 00013 #define CH5 0x00000008 00014 #define CH4 0x00000010 00015 #define CH3 0x00000020 00016 #define CH2 0x00000040 00017 #define CH1 0x00000080 00018 #define TAPE 0x00000100 00019 #define B_CAST 0x00000200 00020 #define CONN 0x00000400 00021 #define T_T 0x00000800 00022 #define MON 0x00001000 00023 #define SEL 0x00002000 00024 #define LS 0x00004000 00025 #define TEL 0x00008000 00026 #define KEY_5 0x00010000 00027 #define KEY_4 0x00020000 00028 #define KEY_3 0x00040000 00029 #define KEY_2 0x00080000 00030 #define KEY_1 0x00100000 00031 #define BRB 0x00200000 00032 #define FUNC 0x00400000 00033 #define CTCSS 0x00800000 00034 #define KEY_6 0x01000000 00035 #define KEY_0 0x02000000 00036 #define KEY_STAR 0x04000000 00037 #define KEY_9 0x08000000 00038 #define KEY_8 0x10000000 00039 #define KEY_7 0x20000000 00040 00041 00042 DigitalOut buttonspl(p20); 00043 DigitalOut ledclock(p19); 00044 DigitalOut leddata(p18); 00045 DigitalOut ledstrobe(p17); 00046 DigitalIn buttonsdata(p16); 00047 00048 void blues(int ledc) 00049 { 00050 led1 = led2 = led3 = led4 = 0; 00051 switch (ledc) { 00052 case 0: 00053 led1 = 1; 00054 break; 00055 case 1: 00056 led2 = 1; 00057 break; 00058 case 2: 00059 led3 = 1; 00060 break; 00061 case 3: 00062 led4 = 1; 00063 break; 00064 case 4: 00065 led3 = 1; 00066 break; 00067 case 5: 00068 led2 = 1; 00069 break; 00070 } 00071 } 00072 00073 void switchled(int led) { 00074 int i; 00075 00076 for (i = 0; i < 32 ; i++) { 00077 ledclock = 0; 00078 if (i == led) 00079 leddata = 0; 00080 else 00081 leddata = 1; 00082 ledclock = 1; 00083 } 00084 } 00085 00086 void button_test(uint32_t buttons) { 00087 printf("keys down: "); 00088 if (buttons & CH7) printf("CH7 "); 00089 if (buttons & KEY_HASH) printf("KEY_HASH "); 00090 if (buttons & CH6) printf("CH6 "); 00091 if (buttons & CH5) printf("CH5 "); 00092 if (buttons & CH4) printf("CH4 "); 00093 if (buttons & CH3) printf("CH3 "); 00094 if (buttons & CH2) printf("CH2 "); 00095 if (buttons & CH1) printf("CH1 "); 00096 if (buttons & TAPE) printf("TAPE "); 00097 if (buttons & B_CAST) printf("B_CAST "); 00098 if (buttons & CONN) printf("CONN "); 00099 if (buttons & T_T) printf("T_T "); 00100 if (buttons & MON) printf("MON "); 00101 if (buttons & SEL) printf("SEL "); 00102 if (buttons & LS) printf("LS "); 00103 if (buttons & TEL) printf("TEL "); 00104 if (buttons & KEY_5) printf("KEY_5 "); 00105 if (buttons & KEY_4) printf("KEY_4 "); 00106 if (buttons & KEY_3) printf("KEY_3 "); 00107 if (buttons & KEY_2) printf("KEY_2 "); 00108 if (buttons & KEY_1) printf("KEY_1 "); 00109 if (buttons & BRB) printf("BRB "); 00110 if (buttons & FUNC) printf("FUNC "); 00111 if (buttons & CTCSS) printf("CTCSS "); 00112 if (buttons & KEY_6) printf("KEY_6 "); 00113 if (buttons & KEY_0) printf("KEY_0 "); 00114 if (buttons & KEY_STAR) printf("KEY_STAR "); 00115 if (buttons & KEY_9) printf("KEY_9 "); 00116 if (buttons & KEY_8) printf("KEY_8 "); 00117 if (buttons & KEY_7) printf("KEY_7 "); 00118 printf("\r\n"); 00119 } 00120 00121 int boardstatus(uint32_t leds) 00122 { 00123 uint32_t buttons = 0; 00124 int i, bbit; 00125 00126 buttonspl = 1; 00127 wait_us(20); 00128 buttonspl = 0; 00129 00130 ledstrobe = 1; 00131 00132 for (i = 0; i < 32 ; i++) { 00133 ledclock = 1; 00134 if (leds & (1 << i)) 00135 leddata = 0; 00136 else 00137 leddata = 1; 00138 ledclock = 0; 00139 bbit = buttonsdata; 00140 buttons |= bbit << i; 00141 } 00142 00143 ledstrobe = 0; 00144 00145 return buttons; 00146 } 00147 00148 int main() { 00149 green = 1; red = 0; 00150 int count = 0; 00151 int buttons, obuttons; 00152 uint32_t bleds; 00153 00154 ledclock = 0; 00155 bleds = 0; 00156 00157 buttons = obuttons = 0; 00158 00159 printf("Hello\r\n"); 00160 00161 while(1) { 00162 if ((count % 10) == 0) 00163 green = !green; 00164 00165 if ((count % 5) == 0) 00166 red = !red; 00167 00168 buttons = boardstatus(bleds); 00169 00170 if (buttons != obuttons) { 00171 button_test(buttons); 00172 00173 #define ISPRESSED(x) (buttons & x) 00174 #define WASPRESSED(x) (!(buttons &x ) && (obuttons & x)) 00175 00176 if (ISPRESSED(CH1)) {bleds |= 0xf;} 00177 if (ISPRESSED(CH2)) {bleds |= 0xf0;} 00178 if (ISPRESSED(CH3)) {bleds |= 0xf00;} 00179 if (ISPRESSED(CH4)) {bleds |= 0xf000;} 00180 if (ISPRESSED(CH5)) {bleds |= (uint32_t)0xf << 28;} 00181 if (ISPRESSED(CH6)) {bleds |= (uint32_t)0xf << 24;} 00182 if (ISPRESSED(CH7)) {bleds |= 0xf << 20;} 00183 00184 if (WASPRESSED(CH1)) {bleds &= ~0xf;} 00185 if (WASPRESSED(CH2)) {bleds &= ~0xf0;} 00186 if (WASPRESSED(CH3)) {bleds &= ~0xf00;} 00187 if (WASPRESSED(CH4)) {bleds &= ~0xf000;} 00188 if (WASPRESSED(CH5)) {bleds &= ~((uint32_t)0xf << 28);} 00189 if (WASPRESSED(CH6)) {bleds &= ~((uint32_t)0xf << 24);} 00190 if (WASPRESSED(CH7)) {bleds &= ~(0xf << 20);} 00191 00192 if (ISPRESSED(BRB)) {bleds = 0;} 00193 obuttons = buttons; 00194 } 00195 00196 if (count & 1) { 00197 bleds |= 1 << 16; 00198 bleds &= ~(1 << 17); 00199 } else { 00200 bleds |= 1 << 17; 00201 bleds &= ~(1 << 16); 00202 } 00203 00204 count++; 00205 wait(0.1); 00206 } 00207 }
Generated on Sun Jul 17 2022 10:52:12 by 1.7.2