Charles Young's development fork. Going forward I only want to push mature code to main repository.
Fork of GEO_COUNTER_L432KC by
LED7segDisplay.cpp@26:166dbe6022e8, 2018-09-05 (annotated)
- Committer:
- charlesdavidyoung
- Date:
- Wed Sep 05 17:31:35 2018 +0000
- Revision:
- 26:166dbe6022e8
- Parent:
- 25:0161bf1adc81
- Child:
- 27:81c417f7cf1a
LED7segDisplay class debugged
Who changed what in which revision?
User | Revision | Line number | New 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 |
25:0161bf1adc81 | 54 | void LED7segDisplay::Display_6D_write(uint8_t value) |
Charles David Young |
25:0161bf1adc81 | 55 | { |
Charles David Young |
25:0161bf1adc81 | 56 | |
Charles David Young |
25:0161bf1adc81 | 57 | uint8_t digit; |
Charles David Young |
25:0161bf1adc81 | 58 | uint16_t data_to_send; |
Charles David Young |
25:0161bf1adc81 | 59 | char TextString[6]; |
Charles David Young |
25:0161bf1adc81 | 60 | |
Charles David Young |
25:0161bf1adc81 | 61 | // int to string, then string to digits |
Charles David Young |
25:0161bf1adc81 | 62 | |
Charles David Young |
25:0161bf1adc81 | 63 | sprintf(TextString, "%6d", value); // int to string |
Charles David Young |
25:0161bf1adc81 | 64 | |
Charles David Young |
25:0161bf1adc81 | 65 | for(uint8_t i=0; i<6; i++) |
Charles David Young |
25:0161bf1adc81 | 66 | { |
Charles David Young |
25:0161bf1adc81 | 67 | if(TextString[i] == ' ') // blank empty digits |
Charles David Young |
25:0161bf1adc81 | 68 | Disp_Digit[i] = 0xFF; |
Charles David Young |
25:0161bf1adc81 | 69 | else |
Charles David Young |
25:0161bf1adc81 | 70 | Disp_Digit[i] = TextString[i]-'0'; |
Charles David Young |
25:0161bf1adc81 | 71 | } |
Charles David Young |
25:0161bf1adc81 | 72 | |
Charles David Young |
25:0161bf1adc81 | 73 | // write to chip |
Charles David Young |
25:0161bf1adc81 | 74 | |
Charles David Young |
25:0161bf1adc81 | 75 | SCK = 0; |
Charles David Young |
25:0161bf1adc81 | 76 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 77 | |
Charles David Young |
25:0161bf1adc81 | 78 | for(digit = 1; digit <7; digit++) |
Charles David Young |
25:0161bf1adc81 | 79 | { |
Charles David Young |
25:0161bf1adc81 | 80 | // each stream consists of digit address and data to show |
Charles David Young |
25:0161bf1adc81 | 81 | data_to_send = 7 - digit; |
Charles David Young |
25:0161bf1adc81 | 82 | data_to_send<<=8; |
Charles David Young |
25:0161bf1adc81 | 83 | data_to_send = data_to_send | Disp_Digit[digit-1]; |
Charles David Young |
25:0161bf1adc81 | 84 | sendDataToDisplay(data_to_send); |
Charles David Young |
25:0161bf1adc81 | 85 | } |
Charles David Young |
25:0161bf1adc81 | 86 | |
Charles David Young |
25:0161bf1adc81 | 87 | return; |
Charles David Young |
25:0161bf1adc81 | 88 | } |
Charles David Young |
25:0161bf1adc81 | 89 | |
Charles David Young |
25:0161bf1adc81 | 90 | |
Charles David Young |
25:0161bf1adc81 | 91 | //--------------------------------------------------------------------------- |
Charles David Young |
25:0161bf1adc81 | 92 | // Refresh the 2 digits of the gate display |
Charles David Young |
25:0161bf1adc81 | 93 | |
Charles David Young |
25:0161bf1adc81 | 94 | void LED7segDisplay::Display_2D_write(unsigned short value) |
Charles David Young |
25:0161bf1adc81 | 95 | { |
Charles David Young |
25:0161bf1adc81 | 96 | |
Charles David Young |
25:0161bf1adc81 | 97 | uint8_t digit; |
Charles David Young |
25:0161bf1adc81 | 98 | uint16_t data_to_send; |
Charles David Young |
25:0161bf1adc81 | 99 | char TextString[2]; |
Charles David Young |
25:0161bf1adc81 | 100 | |
Charles David Young |
25:0161bf1adc81 | 101 | // int to string, then string to digits |
Charles David Young |
25:0161bf1adc81 | 102 | |
Charles David Young |
25:0161bf1adc81 | 103 | sprintf(TextString, "%2d", value); // int to string |
Charles David Young |
25:0161bf1adc81 | 104 | |
Charles David Young |
25:0161bf1adc81 | 105 | if(TextString[0] == ' ') // blank empty digits |
Charles David Young |
25:0161bf1adc81 | 106 | Disp_Digit[7] = 0xFF; |
Charles David Young |
25:0161bf1adc81 | 107 | else |
Charles David Young |
25:0161bf1adc81 | 108 | Disp_Digit[7] = TextString[0] - '0'; |
Charles David Young |
25:0161bf1adc81 | 109 | |
Charles David Young |
25:0161bf1adc81 | 110 | Disp_Digit[6] = TextString[1] - '0'; |
Charles David Young |
25:0161bf1adc81 | 111 | |
Charles David Young |
25:0161bf1adc81 | 112 | // write to chip |
Charles David Young |
25:0161bf1adc81 | 113 | |
Charles David Young |
25:0161bf1adc81 | 114 | SCK = 0; |
Charles David Young |
25:0161bf1adc81 | 115 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 116 | |
Charles David Young |
25:0161bf1adc81 | 117 | for(digit = 7; digit <9; digit++) |
Charles David Young |
25:0161bf1adc81 | 118 | { |
Charles David Young |
25:0161bf1adc81 | 119 | // each stream consists of digit address and data to show |
Charles David Young |
25:0161bf1adc81 | 120 | data_to_send = digit; |
Charles David Young |
25:0161bf1adc81 | 121 | data_to_send<<=8; |
Charles David Young |
25:0161bf1adc81 | 122 | data_to_send = data_to_send | Disp_Digit[digit-1]; |
Charles David Young |
25:0161bf1adc81 | 123 | sendDataToDisplay(data_to_send); |
Charles David Young |
25:0161bf1adc81 | 124 | } |
Charles David Young |
25:0161bf1adc81 | 125 | |
Charles David Young |
25:0161bf1adc81 | 126 | return; |
Charles David Young |
25:0161bf1adc81 | 127 | } |
Charles David Young |
25:0161bf1adc81 | 128 | |
Charles David Young |
25:0161bf1adc81 | 129 | void LED7segDisplay::sendDataToDisplay(uint16_t data_to_send) |
Charles David Young |
25:0161bf1adc81 | 130 | { |
Charles David Young |
25:0161bf1adc81 | 131 | CS1 = 0; |
Charles David Young |
25:0161bf1adc81 | 132 | for(uint16_t mask = 0x8000; mask!= 0; mask>>= 1) |
Charles David Young |
25:0161bf1adc81 | 133 | { |
Charles David Young |
25:0161bf1adc81 | 134 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 135 | SCK = 0; |
Charles David Young |
25:0161bf1adc81 | 136 | if(mask & data_to_send) |
Charles David Young |
25:0161bf1adc81 | 137 | MOSI = 1; |
Charles David Young |
25:0161bf1adc81 | 138 | else |
Charles David Young |
25:0161bf1adc81 | 139 | MOSI = 0; |
Charles David Young |
25:0161bf1adc81 | 140 | |
Charles David Young |
25:0161bf1adc81 | 141 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 142 | SCK = 1; |
Charles David Young |
25:0161bf1adc81 | 143 | } |
Charles David Young |
25:0161bf1adc81 | 144 | |
Charles David Young |
25:0161bf1adc81 | 145 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 146 | SCK = 0; |
Charles David Young |
25:0161bf1adc81 | 147 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 148 | CS1 = 1; |
Charles David Young |
25:0161bf1adc81 | 149 | } |