Charles Young's development fork. Going forward I only want to push mature code to main repository.
Fork of GEO_COUNTER_L432KC by
Diff: LED7segDisplay.cpp
- Revision:
- 25:0161bf1adc81
- Child:
- 26:166dbe6022e8
diff -r db7494389c03 -r 0161bf1adc81 LED7segDisplay.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LED7segDisplay.cpp Wed Sep 05 10:15:52 2018 -0700 @@ -0,0 +1,148 @@ +/** + * @author Charles Young + * + */ + +#include "LED7segDisplay.hpp" + +LED7segDisplay::LED7segDisplay() +{ + Display_init(); +} + +//--------------------------------------------------------------------------- +// Initialize the MAX7219 + +void LED7segDisplay::Display_init(void) +{ + uint8_t i; + uint16_t data_to_send[6] = {SHUTDOWN, TURN_ON, DEC_MODE, brightness, SCAN_LIM, TEST}; + + for(i = 0; i < sizeof(data_to_send)/sizeof(uint16_t); i++) + { + sendDataToDisplay(data_to_send[i]); + } + + return; +} + +void Display_brightness_up() +{ + if (brightness < BRIGHTNESS_MAX) + { + Display_brightness(++brightness); + } +} + +void Display_brightness_down() +{ + if (brightness > BRIGHTNESS_MIN) + { + Display_brightness(--brightness); + } +} + +void Display_brightness(uint16_t brightness) +{ + sendDataToDisplay(brightness); +} + +//--------------------------------------------------------------------------- +// Refresh the 6 digits of the main display + +void LED7segDisplay::Display_6D_write(uint8_t value) +{ + + uint8_t digit; + uint16_t data_to_send; + char TextString[6]; + + // int to string, then string to digits + + sprintf(TextString, "%6d", value); // int to string + + for(uint8_t i=0; i<6; i++) + { + if(TextString[i] == ' ') // blank empty digits + Disp_Digit[i] = 0xFF; + else + Disp_Digit[i] = TextString[i]-'0'; + } + + // write to chip + + SCK = 0; + wait_us(DT); + + for(digit = 1; digit <7; digit++) + { + // each stream consists of digit address and data to show + data_to_send = 7 - digit; + data_to_send<<=8; + data_to_send = data_to_send | Disp_Digit[digit-1]; + sendDataToDisplay(data_to_send); + } + + return; +} + + +//--------------------------------------------------------------------------- +// Refresh the 2 digits of the gate display + +void LED7segDisplay::Display_2D_write(unsigned short value) +{ + + uint8_t digit; + uint16_t data_to_send; + char TextString[2]; + + // int to string, then string to digits + + sprintf(TextString, "%2d", value); // int to string + + if(TextString[0] == ' ') // blank empty digits + Disp_Digit[7] = 0xFF; + else + Disp_Digit[7] = TextString[0] - '0'; + + Disp_Digit[6] = TextString[1] - '0'; + + // write to chip + + SCK = 0; + wait_us(DT); + + for(digit = 7; digit <9; digit++) + { + // each stream consists of digit address and data to show + data_to_send = digit; + data_to_send<<=8; + data_to_send = data_to_send | Disp_Digit[digit-1]; + sendDataToDisplay(data_to_send); + } + + return; +} + +void LED7segDisplay::sendDataToDisplay(uint16_t data_to_send) +{ + CS1 = 0; + for(uint16_t mask = 0x8000; mask!= 0; mask>>= 1) + { + wait_us(DT); + SCK = 0; + if(mask & data_to_send) + MOSI = 1; + else + MOSI = 0; + + wait_us(DT); + SCK = 1; + } + + wait_us(DT); + SCK = 0; + wait_us(DT); + CS1 = 1; +}