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:
charlesdavidyoung
Date:
Wed Sep 05 16:05:07 2018 +0000
Revision:
24:db7494389c03
Parent:
21:5640ebc362a0
Child:
25:0161bf1adc81
Still developing mode selection.  LEDs turn off when not in mode selection.  Pressing once enters mode selection. Pressing again enters submode.  Temporarily the rotary switcha adjusts the display brightness.  This is just for testing.

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