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@41:08bf3ea5eba4, 2018-09-06 (annotated)
- Committer:
- Charles David Young
- Date:
- Thu Sep 06 10:42:07 2018 -0700
- Revision:
- 41:08bf3ea5eba4
- Parent:
- 29:3a2152a3a9d1
- Child:
- 44:a26ca542ae5e
blank 2D display when not in submode
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 |
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 |
29:3a2152a3a9d1 | 72 | void LED7segDisplay::Display_6D_write(uint32_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 |
25:0161bf1adc81 | 102 | void LED7segDisplay::Display_2D_write(unsigned short value) |
Charles David Young |
25:0161bf1adc81 | 103 | { |
Charles David Young |
25:0161bf1adc81 | 104 | uint8_t digit; |
Charles David Young |
25:0161bf1adc81 | 105 | uint16_t data_to_send; |
Charles David Young |
25:0161bf1adc81 | 106 | char TextString[2]; |
Charles David Young |
25:0161bf1adc81 | 107 | |
Charles David Young |
25:0161bf1adc81 | 108 | // int to string, then string to digits |
Charles David Young |
25:0161bf1adc81 | 109 | sprintf(TextString, "%2d", value); // int to string |
Charles David Young |
25:0161bf1adc81 | 110 | |
Charles David Young |
25:0161bf1adc81 | 111 | if(TextString[0] == ' ') // blank empty digits |
Charles David Young |
27:81c417f7cf1a | 112 | Disp_Digit[7] = 0x7F; |
Charles David Young |
25:0161bf1adc81 | 113 | else |
Charles David Young |
25:0161bf1adc81 | 114 | Disp_Digit[7] = TextString[0] - '0'; |
Charles David Young |
25:0161bf1adc81 | 115 | |
Charles David Young |
25:0161bf1adc81 | 116 | Disp_Digit[6] = TextString[1] - '0'; |
Charles David Young |
25:0161bf1adc81 | 117 | |
Charles David Young |
25:0161bf1adc81 | 118 | for(digit = 7; digit <9; digit++) |
Charles David Young |
25:0161bf1adc81 | 119 | { |
Charles David Young |
25:0161bf1adc81 | 120 | // each stream consists of digit address and data to show |
Charles David Young |
25:0161bf1adc81 | 121 | data_to_send = digit; |
Charles David Young |
25:0161bf1adc81 | 122 | data_to_send<<=8; |
Charles David Young |
25:0161bf1adc81 | 123 | data_to_send = data_to_send | Disp_Digit[digit-1]; |
Charles David Young |
25:0161bf1adc81 | 124 | sendDataToDisplay(data_to_send); |
Charles David Young |
25:0161bf1adc81 | 125 | } |
Charles David Young |
25:0161bf1adc81 | 126 | |
Charles David Young |
25:0161bf1adc81 | 127 | return; |
Charles David Young |
25:0161bf1adc81 | 128 | } |
Charles David Young |
25:0161bf1adc81 | 129 | |
Charles David Young |
25:0161bf1adc81 | 130 | void LED7segDisplay::sendDataToDisplay(uint16_t data_to_send) |
Charles David Young |
25:0161bf1adc81 | 131 | { |
Charles David Young |
25:0161bf1adc81 | 132 | CS1 = 0; |
Charles David Young |
25:0161bf1adc81 | 133 | for(uint16_t mask = 0x8000; mask!= 0; mask>>= 1) |
Charles David Young |
25:0161bf1adc81 | 134 | { |
Charles David Young |
25:0161bf1adc81 | 135 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 136 | SCK = 0; |
Charles David Young |
25:0161bf1adc81 | 137 | if(mask & data_to_send) |
Charles David Young |
25:0161bf1adc81 | 138 | MOSI = 1; |
Charles David Young |
25:0161bf1adc81 | 139 | else |
Charles David Young |
25:0161bf1adc81 | 140 | MOSI = 0; |
Charles David Young |
25:0161bf1adc81 | 141 | |
Charles David Young |
25:0161bf1adc81 | 142 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 143 | SCK = 1; |
Charles David Young |
25:0161bf1adc81 | 144 | } |
Charles David Young |
25:0161bf1adc81 | 145 | |
Charles David Young |
25:0161bf1adc81 | 146 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 147 | SCK = 0; |
Charles David Young |
25:0161bf1adc81 | 148 | wait_us(DT); |
Charles David Young |
25:0161bf1adc81 | 149 | CS1 = 1; |
Charles David Young |
25:0161bf1adc81 | 150 | } |