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 01:03:30 2018 +0000
Revision:
22:2616a57327d8
Parent:
21:5640ebc362a0
Not sure why I need to commit again

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