Charles Young's development fork. Going forward I only want to push mature code to main repository.

Dependencies:   mbed

Fork of GEO_COUNTER_L432KC by Geo Electronics "Geo Counter"

Committer:
Charles David Young
Date:
Tue Sep 04 17:40:29 2018 -0700
Revision:
21:5640ebc362a0
Parent:
20:fb73eaaf0894
Child:
22:2616a57327d8
Child:
24:db7494389c03
Trying to adjust intensity

Who changed what in which revision?

UserRevisionLine numberNew contents of line
walter76 2:ac0ed3d84d44 1 // GEO COUNTER V1 firmware
walter76 2:ac0ed3d84d44 2 // This FW provides a basic operation of GEO-COUNTER
walter76 2:ac0ed3d84d44 3 //
walter76 2:ac0ed3d84d44 4 // Latest review: August 27, 2018 - Walter Trovo
walter76 1:75827d765e34 5 //
walter76 1:75827d765e34 6 // Feb 14, 2018: initial release aimed to test the counters, the serial port
walter76 1:75827d765e34 7 // the PWM output and the MAX7219 operation.
walter76 1:75827d765e34 8 // Feb 15, 2018: Removed MAX7219 libray (replaced with custom routine).
walter76 1:75827d765e34 9 // Added 74HC595 routine. Added beep. Added Gate_write
walter76 1:75827d765e34 10 //
walter76 2:ac0ed3d84d44 11
walter76 1:75827d765e34 12
walter76 1:75827d765e34 13 // this block includes key libraries
Charles David Young 21:5640ebc362a0 14 #include "mbed.h" // global Mbed library (always needed)
walter76 1:75827d765e34 15 #include <string> // strings management
charlesdavidyoung 20:fb73eaaf0894 16
Charles David Young 21:5640ebc362a0 17 #include <RotarySwitch.hpp>
charlesdavidyoung 20:fb73eaaf0894 18 RotarySwitch ModeSwitch;
walter76 1:75827d765e34 19
walter76 1:75827d765e34 20 // definitions of fixed parameters
walter76 0:6d1742703713 21
walter76 1:75827d765e34 22 #define DEC_MODE 0x09FF // BCD decoding on all digits
walter76 1:75827d765e34 23 #define BRIGHTNESS 0x0A0F // max brightness
walter76 1:75827d765e34 24 #define SCAN_LIM 0x0B07 // use all 8 digits
walter76 1:75827d765e34 25 #define TURN_ON 0x0C01 // no shutdown (operating)
walter76 1:75827d765e34 26 #define SHUTDOWN 0x0C00 // shutdown
walter76 1:75827d765e34 27 #define TEST 0x0F00 // no test
walter76 1:75827d765e34 28
walter76 1:75827d765e34 29 #define DT 1 // delay time in us for SPI emulation
walter76 1:75827d765e34 30
walter76 1:75827d765e34 31 #define TGATE 10 // gate time (currently fixed for testing purpose)
walter76 1:75827d765e34 32 #define MAX_VAL 999999 // Max value managed by the 6-digits display
walter76 0:6d1742703713 33
Charles David Young 21:5640ebc362a0 34 // definitions of the input/outputs (pins)
Charles David Young 21:5640ebc362a0 35 DigitalOut AUX (D2); // AUX control for GPS module
Charles David Young 21:5640ebc362a0 36 InterruptIn TRIG1 (D3); // Counter 1 trigger
Charles David Young 21:5640ebc362a0 37 InterruptIn TRIG2 (D6); // Counter 2 trigger
Charles David Young 21:5640ebc362a0 38 PwmOut PWM (D10); // PWM output
Charles David Young 21:5640ebc362a0 39 DigitalOut BUZZ (D13); // Buzzer
Charles David Young 21:5640ebc362a0 40
Charles David Young 21:5640ebc362a0 41 AnalogIn AIN0 (A0); // ADC input 0 (High Voltage)
Charles David Young 21:5640ebc362a0 42 AnalogIn AIN1 (A1); // ADC input 1 (aux)
Charles David Young 21:5640ebc362a0 43 DigitalOut CS2 (A2); // 74HC595 RCLK (pin 12)
Charles David Young 21:5640ebc362a0 44 DigitalOut CS1 (A3); // MAX7219 CS (pin 12)
Charles David Young 21:5640ebc362a0 45 DigitalOut SCK (A4); // 74HC595 SRCLK (pin 11) & MAX7219 SCK (pin 13)
Charles David Young 21:5640ebc362a0 46 AnalogIn KEYB (A5); // Keyboard input (SW2 & SW3)
Charles David Young 21:5640ebc362a0 47 DigitalOut MOSI (A6); // 74HC595 SER (pin 14) & MAX7219 DIN (pin 1)
Charles David Young 21:5640ebc362a0 48 DigitalIn UN (A7); // Unused (in V1 PCB A5 and A7 must be connected)
Charles David Young 21:5640ebc362a0 49
charlesdavidyoung 5:4f90b458dbdf 50 // LED on processor board
charlesdavidyoung 5:4f90b458dbdf 51 DigitalOut led1(LED1);
walter76 1:75827d765e34 52
walter76 1:75827d765e34 53 // definitions of peripherals and devices
Charles David Young 7:9f975e00600c 54
charlesdavidyoung 17:6eed17197004 55 I2C i2c(D4, D5); // I2C port
charlesdavidyoung 17:6eed17197004 56 Ticker SecTenth_Beat; // .1 second ticker
walter76 1:75827d765e34 57 Ticker Sec_Beat; // 1 second ticker
walter76 1:75827d765e34 58 Serial PC(USBTX, USBRX); // Virtual COM via USB (PC connection)
walter76 1:75827d765e34 59 Serial GPS(D1, D0); // Serial port for GPS module
walter76 0:6d1742703713 60
walter76 0:6d1742703713 61 // Global variables
walter76 1:75827d765e34 62 uint8_t Disp_Digit[8]; // used to manage 8-digits through MAX7219
walter76 1:75827d765e34 63 uint16_t Stream; // used to stream out serial data to MAX7219
walter76 1:75827d765e34 64 time_t seconds; // Real-Time Clock (RTC) timestamp
walter76 1:75827d765e34 65 unsigned int value = 0; // displayed value on the 6-digits of the display
walter76 1:75827d765e34 66 uint8_t gate = TGATE; // displayed value on the 2-digits display
walter76 1:75827d765e34 67 uint32_t Count1, Count2; // pulse counters (32-bit)
walter76 1:75827d765e34 68 char Text[40]=""; // used to send messages over the serial port
walter76 1:75827d765e34 69 uint8_t Disp_mode = 0x01, Disp_unit = 0xA0; // status of 1st row and 2nd rows of LEDs
kd5byb 4:b17c6556cf1f 70 bool Stopped = 0; // status of counting activity
charlesdavidyoung 5:4f90b458dbdf 71 bool StartStopPressed = 0;// status of counting activity
walter76 1:75827d765e34 72 double ADC_val; // used to read ADC value
walter76 0:6d1742703713 73
walter76 1:75827d765e34 74 // ----- Prototypes of routines (defined below the main) -------------------
Charles David Young 16:b2e77eb76ab4 75 void UpdateInput(void); // periodically called by the ticker
Charles David Young 16:b2e77eb76ab4 76 void UpdateOutput(void); // periodically called by the ticker
walter76 1:75827d765e34 77 void Count1_up(void); // called every time an edge is detected on TRIG1 pin
walter76 1:75827d765e34 78 void Count2_up(void); // called every time an edge is detected on TRIG2 pin
walter76 1:75827d765e34 79 void Beep(void); // used to generate a short beep (buzzer)
walter76 1:75827d765e34 80 void Display_init(void); // initialize MAX7219
walter76 1:75827d765e34 81 void Display_6D_write(uint8_t); // write to MAX7219 (Main 6-digits display)
walter76 1:75827d765e34 82 void Display_2D_write(unsigned short); // write to MAX7219 (Gate 2-digits display)
walter76 0:6d1742703713 83
walter76 0:6d1742703713 84 //==============================================================================
walter76 0:6d1742703713 85 //==============================================================================
walter76 0:6d1742703713 86
walter76 0:6d1742703713 87 int main()
walter76 0:6d1742703713 88 {
walter76 0:6d1742703713 89
walter76 1:75827d765e34 90 PC.baud(115200); // set baud-rate of virtual COM port (PC connection)
charlesdavidyoung 5:4f90b458dbdf 91 PC.printf("\nGEO COUNTER V1 2108");
walter76 1:75827d765e34 92 PC.printf(__DATE__);
walter76 1:75827d765e34 93 PC.printf(" ");
walter76 1:75827d765e34 94 PC.printf(__TIME__);
walter76 1:75827d765e34 95
walter76 2:ac0ed3d84d44 96 GPS.baud(9600); // set the baud-rate of the serial port dedicated to the GPS
walter76 0:6d1742703713 97
walter76 1:75827d765e34 98 CS1 = 1; // presets CS of MAX7219
walter76 1:75827d765e34 99 CS2 = 1; // preset CS of 74HC595
walter76 1:75827d765e34 100
charlesdavidyoung 13:0e7b06af9a2a 101 Display_6D_write(0x543210);
walter76 1:75827d765e34 102 Display_2D_write(TGATE);
walter76 1:75827d765e34 103 Display_init(); // initialize MAX7219
walter76 0:6d1742703713 104
walter76 1:75827d765e34 105 // RTC is supposed to be loose time at power down (no backup battery)
walter76 1:75827d765e34 106 // An initialization is performed anyway
walter76 1:75827d765e34 107 set_time(0); // Set time
Charles David Young 21:5640ebc362a0 108
walter76 1:75827d765e34 109 PWM.period_ms(3); // set the PWM period
walter76 1:75827d765e34 110 PWM.write(0.8); // set the PWM duty-cycle
walter76 1:75827d765e34 111
walter76 1:75827d765e34 112 Beep(); // initial beep
walter76 1:75827d765e34 113
walter76 1:75827d765e34 114 // set the 1 sec ticker to periodically call the Update() routine
walter76 1:75827d765e34 115 // NOTE: this is also the 1-sec time base for counters. A better approach
walter76 1:75827d765e34 116 // would replace the ticker with an interrupt from the RTC (to be implemented)
charlesdavidyoung 17:6eed17197004 117 SecTenth_Beat.attach_us(&UpdateInput, 100000);
Charles David Young 16:b2e77eb76ab4 118 Sec_Beat.attach_us(&UpdateOutput, 1000000);
walter76 0:6d1742703713 119 //RTC::attach(&Update, RTC::Second);
walter76 1:75827d765e34 120 //RTC::detach(RTC::Second);
walter76 1:75827d765e34 121
walter76 1:75827d765e34 122 // main loop does nothing as all activities are interrupt driven
walter76 0:6d1742703713 123 while(1)
walter76 0:6d1742703713 124 {
walter76 2:ac0ed3d84d44 125 // dance (or drink a beer)
walter76 0:6d1742703713 126 }
walter76 0:6d1742703713 127 }
walter76 0:6d1742703713 128
walter76 0:6d1742703713 129
walter76 1:75827d765e34 130 //-------- END OF MAIN --------------
walter76 0:6d1742703713 131 //==============================================================================
walter76 0:6d1742703713 132
walter76 1:75827d765e34 133 // Definition of routines
walter76 1:75827d765e34 134
walter76 1:75827d765e34 135 //---------------------------------------------------------------------------
walter76 1:75827d765e34 136 // Update values to be displayed
Charles David Young 10:f48cc6be5ae8 137 void logToPC()
Charles David Young 10:f48cc6be5ae8 138 {
Charles David Young 10:f48cc6be5ae8 139 PC.printf("\nADC: %.02f", ADC_val);
Charles David Young 10:f48cc6be5ae8 140 PC.printf(Stopped ? " stopped" : " started");
Charles David Young 10:f48cc6be5ae8 141 // Timestamp to PC (debug)
Charles David Young 10:f48cc6be5ae8 142 seconds = time(NULL); // get current time
Charles David Young 10:f48cc6be5ae8 143 strftime(Text, 50, "%H:%M:%S", localtime(&seconds));
Charles David Young 10:f48cc6be5ae8 144 PC.printf(" RTC: %s, CNT1: %7d CNT2: %7d",Text, Count1, Count2);
Charles David Young 21:5640ebc362a0 145 // PC.printf(" wheel %d %d", WheelCurrent, QEPB.read());
Charles David Young 10:f48cc6be5ae8 146 }
walter76 1:75827d765e34 147
Charles David Young 16:b2e77eb76ab4 148 void UpdateOutput()
charlesdavidyoung 18:ef5678ab1889 149 {
Charles David Young 16:b2e77eb76ab4 150 if(Stopped)
Charles David Young 16:b2e77eb76ab4 151 {
Charles David Young 16:b2e77eb76ab4 152 // disable interrupts on TRIG1 and TRIG2
Charles David Young 16:b2e77eb76ab4 153
Charles David Young 16:b2e77eb76ab4 154 TRIG1.rise(NULL);
Charles David Young 16:b2e77eb76ab4 155 TRIG2.rise(NULL);
Charles David Young 16:b2e77eb76ab4 156
Charles David Young 16:b2e77eb76ab4 157 // show zero gate time
Charles David Young 16:b2e77eb76ab4 158 gate = 0;
Charles David Young 16:b2e77eb76ab4 159 Display_2D_write(gate);
Charles David Young 16:b2e77eb76ab4 160
Charles David Young 16:b2e77eb76ab4 161 // show selected content on main display
Charles David Young 16:b2e77eb76ab4 162 value = (int)(Count1/TGATE);
Charles David Young 16:b2e77eb76ab4 163 Display_6D_write(value); // refresh the main display
Charles David Young 16:b2e77eb76ab4 164 }
Charles David Young 16:b2e77eb76ab4 165
Charles David Young 16:b2e77eb76ab4 166 else
Charles David Young 16:b2e77eb76ab4 167 {
Charles David Young 16:b2e77eb76ab4 168 // Enable interrupts on rising edge of digital inputs TRIG1 & TRIG2
Charles David Young 16:b2e77eb76ab4 169 TRIG1.rise(&Count1_up);
Charles David Young 16:b2e77eb76ab4 170 TRIG2.rise(&Count2_up);
Charles David Young 16:b2e77eb76ab4 171
Charles David Young 16:b2e77eb76ab4 172 if(gate==0) // show the counter value at the end of the gate time
Charles David Young 16:b2e77eb76ab4 173 {
Charles David Young 16:b2e77eb76ab4 174 value = (int)(Count1/TGATE);
Charles David Young 16:b2e77eb76ab4 175
Charles David Young 16:b2e77eb76ab4 176 Display_6D_write(value); // refresh the main display
Charles David Young 7:9f975e00600c 177
Charles David Young 16:b2e77eb76ab4 178 Count1 = 0; // clear both counters
Charles David Young 16:b2e77eb76ab4 179 Count2 = 0;
Charles David Young 16:b2e77eb76ab4 180 gate = TGATE;// and reload the gate time
Charles David Young 16:b2e77eb76ab4 181
Charles David Young 16:b2e77eb76ab4 182 }
Charles David Young 16:b2e77eb76ab4 183
Charles David Young 16:b2e77eb76ab4 184 Display_2D_write(gate); // show gate time countdown
Charles David Young 16:b2e77eb76ab4 185 gate--;
Charles David Young 16:b2e77eb76ab4 186 }
Charles David Young 16:b2e77eb76ab4 187 }
Charles David Young 16:b2e77eb76ab4 188
Charles David Young 16:b2e77eb76ab4 189 void UpdateInput()
Charles David Young 21:5640ebc362a0 190 {
Charles David Young 16:b2e77eb76ab4 191 ADC_val = KEYB.read(); // read voltage from keyboard
Charles David Young 16:b2e77eb76ab4 192 if ( (ADC_val<0.1) // START/STOP pushbutton pressed
Charles David Young 16:b2e77eb76ab4 193 && (!StartStopPressed))
Charles David Young 16:b2e77eb76ab4 194 {
Charles David Young 16:b2e77eb76ab4 195 StartStopPressed = true;
Charles David Young 16:b2e77eb76ab4 196 Stopped=!Stopped; // toggle status
Charles David Young 16:b2e77eb76ab4 197 }
Charles David Young 16:b2e77eb76ab4 198 else
Charles David Young 16:b2e77eb76ab4 199 StartStopPressed = false;
charlesdavidyoung 5:4f90b458dbdf 200
Charles David Young 16:b2e77eb76ab4 201 if((ADC_val>0.6)&&(ADC_val<0.7)) // CLEAR pushbutton pressed
Charles David Young 16:b2e77eb76ab4 202 {
Charles David Young 16:b2e77eb76ab4 203 Count1 = 0; // clear counters
Charles David Young 16:b2e77eb76ab4 204 Count2 = 0;
charlesdavidyoung 5:4f90b458dbdf 205 }
Charles David Young 21:5640ebc362a0 206
Charles David Young 16:b2e77eb76ab4 207 logToPC();
Charles David Young 16:b2e77eb76ab4 208 return;
Charles David Young 16:b2e77eb76ab4 209 }
walter76 1:75827d765e34 210
walter76 0:6d1742703713 211 //---------------------------------------------------------------------------
walter76 1:75827d765e34 212 // Increment CNT1 every time a rising edge is detected on TRIG1 (interrupt)
walter76 1:75827d765e34 213
walter76 1:75827d765e34 214 void Count1_up(void)
walter76 1:75827d765e34 215 {
walter76 1:75827d765e34 216 Count1++;
walter76 1:75827d765e34 217 return;
walter76 1:75827d765e34 218 }
walter76 1:75827d765e34 219
Charles David Young 21:5640ebc362a0 220
walter76 1:75827d765e34 221 //---------------------------------------------------------------------------
walter76 1:75827d765e34 222 // Increment CNT1 every time a rising edge is detected on TRIG2 (interrupt)
walter76 1:75827d765e34 223
walter76 1:75827d765e34 224 void Count2_up(void)
walter76 1:75827d765e34 225 {
walter76 1:75827d765e34 226 Count2++;
walter76 1:75827d765e34 227 return;
walter76 1:75827d765e34 228 }
walter76 1:75827d765e34 229
walter76 1:75827d765e34 230
walter76 1:75827d765e34 231 //---------------------------------------------------------------------------
walter76 1:75827d765e34 232 //Generates a short beep via BUZZ
walter76 1:75827d765e34 233
walter76 1:75827d765e34 234 void Beep(void)
walter76 1:75827d765e34 235 {
walter76 1:75827d765e34 236 BUZZ = 1; // turn-on the buzzer
walter76 1:75827d765e34 237 wait(0.3); // wait
walter76 1:75827d765e34 238 BUZZ = 0; // turn-off the buzzer
walter76 0:6d1742703713 239 return;
walter76 0:6d1742703713 240 }
walter76 0:6d1742703713 241
Charles David Young 21:5640ebc362a0 242
walter76 1:75827d765e34 243 //---------------------------------------------------------------------------
walter76 1:75827d765e34 244 // Initialize the MAX7219
walter76 1:75827d765e34 245
walter76 1:75827d765e34 246 void Display_init(void)
walter76 1:75827d765e34 247 {
walter76 1:75827d765e34 248 uint8_t i;
walter76 1:75827d765e34 249 uint16_t mask;
walter76 1:75827d765e34 250 uint16_t data_to_send[6] = {SHUTDOWN, TURN_ON, DEC_MODE, BRIGHTNESS, SCAN_LIM, TEST};
walter76 1:75827d765e34 251 //{SHUTDOWN, TURN_ON, DEC_MODE, BRIGHTNESS, SCAN_LIM, TEST};
walter76 1:75827d765e34 252 for(i = 0; i <6; i++)
walter76 1:75827d765e34 253 {
walter76 1:75827d765e34 254 CS1 = 0;
walter76 1:75827d765e34 255
walter76 1:75827d765e34 256 for(mask = 0x8000; mask!= 0; mask>>= 1)
walter76 1:75827d765e34 257 {
walter76 1:75827d765e34 258 wait_us(DT);
walter76 1:75827d765e34 259 SCK = 0;
walter76 1:75827d765e34 260 if(mask & data_to_send[i])
walter76 1:75827d765e34 261 MOSI = 1;
walter76 1:75827d765e34 262 else
walter76 1:75827d765e34 263 MOSI = 0;
walter76 1:75827d765e34 264 wait_us(DT);
walter76 1:75827d765e34 265 SCK = 1;
walter76 1:75827d765e34 266 }
walter76 1:75827d765e34 267
walter76 1:75827d765e34 268 wait_us(DT);
walter76 1:75827d765e34 269 SCK = 0;
walter76 1:75827d765e34 270 wait_us(DT);
walter76 1:75827d765e34 271 CS1 = 1;
walter76 1:75827d765e34 272 }
walter76 1:75827d765e34 273
walter76 1:75827d765e34 274 return;
walter76 1:75827d765e34 275 }
walter76 1:75827d765e34 276
walter76 1:75827d765e34 277
walter76 1:75827d765e34 278 //---------------------------------------------------------------------------
walter76 1:75827d765e34 279 // Refresh the 6 digits of the main display
walter76 1:75827d765e34 280
walter76 1:75827d765e34 281 void Display_6D_write(uint8_t value)
walter76 1:75827d765e34 282 {
walter76 1:75827d765e34 283
walter76 1:75827d765e34 284 uint8_t digit;
walter76 1:75827d765e34 285 uint16_t mask, data_to_send;
walter76 1:75827d765e34 286 char TextString[6];
walter76 1:75827d765e34 287
walter76 1:75827d765e34 288 // int to string, then string to digits
walter76 1:75827d765e34 289
walter76 1:75827d765e34 290 sprintf(TextString, "%6d", value); // int to string
walter76 1:75827d765e34 291
walter76 1:75827d765e34 292 for(uint8_t i=0; i<6; i++)
walter76 1:75827d765e34 293 {
walter76 1:75827d765e34 294 if(TextString[i] == ' ') // blank empty digits
walter76 1:75827d765e34 295 Disp_Digit[i] = 0xFF;
walter76 1:75827d765e34 296 else
walter76 1:75827d765e34 297 Disp_Digit[i] = TextString[i]-'0';
walter76 1:75827d765e34 298 }
walter76 1:75827d765e34 299
walter76 1:75827d765e34 300 // write to chip
walter76 1:75827d765e34 301
walter76 1:75827d765e34 302 SCK = 0;
walter76 1:75827d765e34 303 wait_us(DT);
walter76 1:75827d765e34 304
walter76 1:75827d765e34 305 for(digit = 1; digit <7; digit++)
walter76 1:75827d765e34 306 {
walter76 1:75827d765e34 307 // each stream consists of digit address and data to show
Charles David Young 6:05201ecabb95 308 data_to_send = 7 - digit;
walter76 1:75827d765e34 309 data_to_send<<=8;
walter76 1:75827d765e34 310 data_to_send = data_to_send | Disp_Digit[digit-1];
walter76 1:75827d765e34 311
walter76 1:75827d765e34 312 CS1 = 0;
walter76 1:75827d765e34 313
walter76 1:75827d765e34 314 for(mask = 0x8000; mask!= 0; mask>>= 1)
walter76 1:75827d765e34 315 {
walter76 1:75827d765e34 316 wait_us(DT);
walter76 1:75827d765e34 317 SCK = 0;
walter76 1:75827d765e34 318 if(mask & data_to_send)
walter76 1:75827d765e34 319 MOSI = 1;
walter76 1:75827d765e34 320 else
walter76 1:75827d765e34 321 MOSI = 0;
walter76 1:75827d765e34 322
walter76 1:75827d765e34 323 wait_us(DT);
walter76 1:75827d765e34 324 SCK = 1;
walter76 1:75827d765e34 325 }
walter76 1:75827d765e34 326
walter76 1:75827d765e34 327 wait_us(DT);
walter76 1:75827d765e34 328 SCK = 0;
walter76 1:75827d765e34 329 wait_us(DT);
walter76 1:75827d765e34 330 CS1 = 1;
walter76 1:75827d765e34 331 }
walter76 1:75827d765e34 332
walter76 1:75827d765e34 333 return;
walter76 1:75827d765e34 334 }
walter76 1:75827d765e34 335
walter76 1:75827d765e34 336
walter76 1:75827d765e34 337 //---------------------------------------------------------------------------
walter76 1:75827d765e34 338 // Refresh the 2 digits of the gate display
walter76 1:75827d765e34 339
walter76 1:75827d765e34 340 void Display_2D_write(unsigned short value)
walter76 1:75827d765e34 341 {
walter76 1:75827d765e34 342
walter76 1:75827d765e34 343 uint8_t digit;
walter76 1:75827d765e34 344 uint16_t mask, data_to_send;
walter76 1:75827d765e34 345 char TextString[2];
walter76 1:75827d765e34 346
walter76 1:75827d765e34 347 // int to string, then string to digits
walter76 1:75827d765e34 348
walter76 1:75827d765e34 349 sprintf(TextString, "%2d", value); // int to string
walter76 1:75827d765e34 350
walter76 1:75827d765e34 351 if(TextString[0] == ' ') // blank empty digits
walter76 1:75827d765e34 352 Disp_Digit[7] = 0xFF;
walter76 1:75827d765e34 353 else
walter76 1:75827d765e34 354 Disp_Digit[7] = TextString[0] - '0';
walter76 1:75827d765e34 355
walter76 1:75827d765e34 356 Disp_Digit[6] = TextString[1] - '0';
walter76 1:75827d765e34 357
walter76 1:75827d765e34 358 // write to chip
walter76 1:75827d765e34 359
walter76 1:75827d765e34 360 SCK = 0;
walter76 1:75827d765e34 361 wait_us(DT);
walter76 1:75827d765e34 362
walter76 1:75827d765e34 363 for(digit = 7; digit <9; digit++)
walter76 1:75827d765e34 364 {
walter76 1:75827d765e34 365 // each stream consists of digit address and data to show
walter76 1:75827d765e34 366 data_to_send = digit;
walter76 1:75827d765e34 367 data_to_send<<=8;
walter76 1:75827d765e34 368 data_to_send = data_to_send | Disp_Digit[digit-1];
walter76 1:75827d765e34 369
walter76 1:75827d765e34 370 CS1 = 0;
walter76 1:75827d765e34 371
walter76 1:75827d765e34 372 for(mask = 0x8000; mask!= 0; mask>>= 1)
walter76 1:75827d765e34 373 {
walter76 1:75827d765e34 374 wait_us(DT);
walter76 1:75827d765e34 375 SCK = 0;
walter76 1:75827d765e34 376
walter76 1:75827d765e34 377 if(mask & data_to_send)
walter76 1:75827d765e34 378 MOSI = 1;
walter76 1:75827d765e34 379 else
walter76 1:75827d765e34 380 MOSI = 0;
walter76 1:75827d765e34 381
walter76 1:75827d765e34 382 wait_us(DT);
walter76 1:75827d765e34 383 SCK = 1;
walter76 1:75827d765e34 384 }
walter76 1:75827d765e34 385
walter76 1:75827d765e34 386 wait_us(DT);
walter76 1:75827d765e34 387 SCK = 0;
walter76 1:75827d765e34 388 wait_us(DT);
walter76 1:75827d765e34 389 CS1 = 1;
walter76 1:75827d765e34 390 }
walter76 1:75827d765e34 391
walter76 1:75827d765e34 392 return;
walter76 1:75827d765e34 393 }
walter76 1:75827d765e34 394
walter76 1:75827d765e34 395 //-------- END OF FILE --------------
walter76 1:75827d765e34 396 //==============================================================================
walter76 1:75827d765e34 397
walter76 1:75827d765e34 398
walter76 1:75827d765e34 399