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:
Wed Sep 05 10:15:52 2018 -0700
Revision:
25:0161bf1adc81
Child:
26:166dbe6022e8
Created LED7segDisplay class

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