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:
Sun Oct 07 13:13:53 2018 +0000
Revision:
80:5770804da1b0
Parent:
44:a26ca542ae5e
get rid of pulldown

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Charles David Young 25:0161bf1adc81 1 /**
Charles David Young 25:0161bf1adc81 2 * @author Charles Young
Charles David Young 25:0161bf1adc81 3 *
Charles David Young 25:0161bf1adc81 4 */
Charles David Young 25:0161bf1adc81 5
Charles David Young 25:0161bf1adc81 6 #include "LED7segDisplay.hpp"
Charles David Young 25:0161bf1adc81 7
Charles David Young 25:0161bf1adc81 8 LED7segDisplay::LED7segDisplay()
Charles David Young 25:0161bf1adc81 9 {
charlesdavidyoung 26:166dbe6022e8 10 brightness = BRIGHTNESS_MAX;
Charles David Young 25:0161bf1adc81 11 Display_init();
Charles David Young 25:0161bf1adc81 12 }
Charles David Young 25:0161bf1adc81 13
Charles David Young 25:0161bf1adc81 14 //---------------------------------------------------------------------------
Charles David Young 25:0161bf1adc81 15 // Initialize the MAX7219
Charles David Young 25:0161bf1adc81 16
Charles David Young 25:0161bf1adc81 17 void LED7segDisplay::Display_init(void)
Charles David Young 25:0161bf1adc81 18 {
Charles David Young 25:0161bf1adc81 19 uint8_t i;
Charles David Young 25:0161bf1adc81 20 uint16_t data_to_send[6] = {SHUTDOWN, TURN_ON, DEC_MODE, brightness, SCAN_LIM, TEST};
Charles David Young 25:0161bf1adc81 21
Charles David Young 25:0161bf1adc81 22 for(i = 0; i < sizeof(data_to_send)/sizeof(uint16_t); i++)
Charles David Young 25:0161bf1adc81 23 {
Charles David Young 25:0161bf1adc81 24 sendDataToDisplay(data_to_send[i]);
Charles David Young 25:0161bf1adc81 25 }
Charles David Young 25:0161bf1adc81 26
Charles David Young 25:0161bf1adc81 27 return;
Charles David Young 25:0161bf1adc81 28 }
Charles David Young 25:0161bf1adc81 29
charlesdavidyoung 26:166dbe6022e8 30 void LED7segDisplay::Display_brightness_up()
Charles David Young 25:0161bf1adc81 31 {
Charles David Young 25:0161bf1adc81 32 if (brightness < BRIGHTNESS_MAX)
Charles David Young 25:0161bf1adc81 33 {
Charles David Young 25:0161bf1adc81 34 Display_brightness(++brightness);
Charles David Young 25:0161bf1adc81 35 }
Charles David Young 25:0161bf1adc81 36 }
Charles David Young 25:0161bf1adc81 37
charlesdavidyoung 26:166dbe6022e8 38 void LED7segDisplay::Display_brightness_down()
Charles David Young 25:0161bf1adc81 39 {
Charles David Young 25:0161bf1adc81 40 if (brightness > BRIGHTNESS_MIN)
Charles David Young 25:0161bf1adc81 41 {
Charles David Young 25:0161bf1adc81 42 Display_brightness(--brightness);
Charles David Young 25:0161bf1adc81 43 }
Charles David Young 25:0161bf1adc81 44 }
Charles David Young 25:0161bf1adc81 45
charlesdavidyoung 26:166dbe6022e8 46 void LED7segDisplay::Display_brightness(uint16_t brightness)
Charles David Young 25:0161bf1adc81 47 {
Charles David Young 25:0161bf1adc81 48 sendDataToDisplay(brightness);
Charles David Young 25:0161bf1adc81 49 }
Charles David Young 25:0161bf1adc81 50
Charles David Young 25:0161bf1adc81 51 //---------------------------------------------------------------------------
Charles David Young 25:0161bf1adc81 52 // Refresh the 6 digits of the main display
Charles David Young 25:0161bf1adc81 53
Charles David Young 41:08bf3ea5eba4 54
Charles David Young 41:08bf3ea5eba4 55 //---------------------------------------------------------------------------
Charles David Young 41:08bf3ea5eba4 56 // Refresh the 2 digits of the gate display
Charles David Young 41:08bf3ea5eba4 57
Charles David Young 41:08bf3ea5eba4 58 void LED7segDisplay::Display_2D_Blank()
Charles David Young 41:08bf3ea5eba4 59 {
Charles David Young 41:08bf3ea5eba4 60 uint16_t data_to_send;
Charles David Young 41:08bf3ea5eba4 61
Charles David Young 41:08bf3ea5eba4 62 for(uint8_t digit = 7; digit < 9; digit++)
Charles David Young 41:08bf3ea5eba4 63 {
Charles David Young 41:08bf3ea5eba4 64 // each stream consists of digit address and data to show
Charles David Young 41:08bf3ea5eba4 65 data_to_send = digit;
Charles David Young 41:08bf3ea5eba4 66 data_to_send<<=8;
Charles David Young 41:08bf3ea5eba4 67 data_to_send = data_to_send | 0x7F;
Charles David Young 41:08bf3ea5eba4 68 sendDataToDisplay(data_to_send);
Charles David Young 41:08bf3ea5eba4 69 }
Charles David Young 41:08bf3ea5eba4 70 }
Charles David Young 41:08bf3ea5eba4 71
Charles David Young 44:a26ca542ae5e 72 void LED7segDisplay::Display_6D_write(int32_t value)
Charles David Young 25:0161bf1adc81 73 {
Charles David Young 25:0161bf1adc81 74
Charles David Young 25:0161bf1adc81 75 uint8_t digit;
Charles David Young 25:0161bf1adc81 76 uint16_t data_to_send;
Charles David Young 25:0161bf1adc81 77 char TextString[6];
Charles David Young 25:0161bf1adc81 78
Charles David Young 25:0161bf1adc81 79 // int to string, then string to digits
Charles David Young 25:0161bf1adc81 80 sprintf(TextString, "%6d", value); // int to string
Charles David Young 25:0161bf1adc81 81
Charles David Young 25:0161bf1adc81 82 for(uint8_t i=0; i<6; i++)
Charles David Young 25:0161bf1adc81 83 {
Charles David Young 25:0161bf1adc81 84 if(TextString[i] == ' ') // blank empty digits
Charles David Young 27:81c417f7cf1a 85 Disp_Digit[i] = 0x7F;
Charles David Young 25:0161bf1adc81 86 else
Charles David Young 25:0161bf1adc81 87 Disp_Digit[i] = TextString[i]-'0';
Charles David Young 25:0161bf1adc81 88 }
Charles David Young 25:0161bf1adc81 89
Charles David Young 25:0161bf1adc81 90 for(digit = 1; digit <7; digit++)
Charles David Young 25:0161bf1adc81 91 {
Charles David Young 25:0161bf1adc81 92 // each stream consists of digit address and data to show
Charles David Young 25:0161bf1adc81 93 data_to_send = 7 - digit;
Charles David Young 25:0161bf1adc81 94 data_to_send<<=8;
Charles David Young 25:0161bf1adc81 95 data_to_send = data_to_send | Disp_Digit[digit-1];
Charles David Young 25:0161bf1adc81 96 sendDataToDisplay(data_to_send);
Charles David Young 25:0161bf1adc81 97 }
Charles David Young 25:0161bf1adc81 98
Charles David Young 25:0161bf1adc81 99 return;
Charles David Young 25:0161bf1adc81 100 }
Charles David Young 25:0161bf1adc81 101
Charles David Young 44:a26ca542ae5e 102 void LED7segDisplay::Display_2D_write(int16_t value)
Charles David Young 25:0161bf1adc81 103 {
Charles David Young 44:a26ca542ae5e 104 bool negative = false;
Charles David Young 44:a26ca542ae5e 105 if (value < 0)
Charles David Young 44:a26ca542ae5e 106 negative = true;
Charles David Young 44:a26ca542ae5e 107 value = abs(value);
Charles David Young 44:a26ca542ae5e 108
Charles David Young 25:0161bf1adc81 109 uint8_t digit;
Charles David Young 25:0161bf1adc81 110 uint16_t data_to_send;
Charles David Young 25:0161bf1adc81 111 char TextString[2];
Charles David Young 25:0161bf1adc81 112
Charles David Young 25:0161bf1adc81 113 // int to string, then string to digits
Charles David Young 25:0161bf1adc81 114 sprintf(TextString, "%2d", value); // int to string
Charles David Young 25:0161bf1adc81 115
Charles David Young 25:0161bf1adc81 116 if(TextString[0] == ' ') // blank empty digits
Charles David Young 27:81c417f7cf1a 117 Disp_Digit[7] = 0x7F;
Charles David Young 25:0161bf1adc81 118 else
Charles David Young 25:0161bf1adc81 119 Disp_Digit[7] = TextString[0] - '0';
Charles David Young 25:0161bf1adc81 120
Charles David Young 25:0161bf1adc81 121 Disp_Digit[6] = TextString[1] - '0';
Charles David Young 44:a26ca542ae5e 122 // turn on decimal point to indicate negative
Charles David Young 44:a26ca542ae5e 123 if (negative)
Charles David Young 44:a26ca542ae5e 124 Disp_Digit[6] |= 0x80;
Charles David Young 25:0161bf1adc81 125
Charles David Young 25:0161bf1adc81 126 for(digit = 7; digit <9; digit++)
Charles David Young 25:0161bf1adc81 127 {
Charles David Young 25:0161bf1adc81 128 // each stream consists of digit address and data to show
Charles David Young 25:0161bf1adc81 129 data_to_send = digit;
Charles David Young 25:0161bf1adc81 130 data_to_send<<=8;
Charles David Young 25:0161bf1adc81 131 data_to_send = data_to_send | Disp_Digit[digit-1];
Charles David Young 25:0161bf1adc81 132 sendDataToDisplay(data_to_send);
Charles David Young 25:0161bf1adc81 133 }
Charles David Young 25:0161bf1adc81 134
Charles David Young 25:0161bf1adc81 135 return;
Charles David Young 25:0161bf1adc81 136 }
Charles David Young 25:0161bf1adc81 137
Charles David Young 25:0161bf1adc81 138 void LED7segDisplay::sendDataToDisplay(uint16_t data_to_send)
Charles David Young 25:0161bf1adc81 139 {
Charles David Young 25:0161bf1adc81 140 CS1 = 0;
Charles David Young 25:0161bf1adc81 141 for(uint16_t mask = 0x8000; mask!= 0; mask>>= 1)
Charles David Young 25:0161bf1adc81 142 {
Charles David Young 25:0161bf1adc81 143 wait_us(DT);
Charles David Young 25:0161bf1adc81 144 SCK = 0;
Charles David Young 25:0161bf1adc81 145 if(mask & data_to_send)
Charles David Young 25:0161bf1adc81 146 MOSI = 1;
Charles David Young 25:0161bf1adc81 147 else
Charles David Young 25:0161bf1adc81 148 MOSI = 0;
Charles David Young 25:0161bf1adc81 149
Charles David Young 25:0161bf1adc81 150 wait_us(DT);
Charles David Young 25:0161bf1adc81 151 SCK = 1;
Charles David Young 25:0161bf1adc81 152 }
Charles David Young 25:0161bf1adc81 153
Charles David Young 25:0161bf1adc81 154 wait_us(DT);
Charles David Young 25:0161bf1adc81 155 SCK = 0;
Charles David Young 25:0161bf1adc81 156 wait_us(DT);
Charles David Young 25:0161bf1adc81 157 CS1 = 1;
Charles David Young 25:0161bf1adc81 158 }