Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GEO_COUNTER_L432KC by
LED7segDisplay.cpp
00001 /** 00002 * @author Charles Young 00003 * 00004 */ 00005 00006 #include "LED7segDisplay.hpp" 00007 00008 LED7segDisplay::LED7segDisplay() 00009 { 00010 brightness = BRIGHTNESS_MAX; 00011 Display_init(); 00012 } 00013 00014 //--------------------------------------------------------------------------- 00015 // Initialize the MAX7219 00016 00017 void LED7segDisplay::Display_init(void) 00018 { 00019 uint8_t i; 00020 uint16_t data_to_send[6] = {SHUTDOWN, TURN_ON, DEC_MODE, brightness, SCAN_LIM, TEST}; 00021 00022 for(i = 0; i < sizeof(data_to_send)/sizeof(uint16_t); i++) 00023 { 00024 sendDataToDisplay(data_to_send[i]); 00025 } 00026 00027 return; 00028 } 00029 00030 void LED7segDisplay::Display_brightness_up() 00031 { 00032 if (brightness < BRIGHTNESS_MAX) 00033 { 00034 Display_brightness(++brightness); 00035 } 00036 } 00037 00038 void LED7segDisplay::Display_brightness_down() 00039 { 00040 if (brightness > BRIGHTNESS_MIN) 00041 { 00042 Display_brightness(--brightness); 00043 } 00044 } 00045 00046 void LED7segDisplay::Display_brightness(uint16_t brightness) 00047 { 00048 sendDataToDisplay(brightness); 00049 } 00050 00051 //--------------------------------------------------------------------------- 00052 // Refresh the 6 digits of the main display 00053 00054 00055 //--------------------------------------------------------------------------- 00056 // Refresh the 2 digits of the gate display 00057 00058 void LED7segDisplay::Display_2D_Blank() 00059 { 00060 uint16_t data_to_send; 00061 00062 for(uint8_t digit = 7; digit < 9; digit++) 00063 { 00064 // each stream consists of digit address and data to show 00065 data_to_send = digit; 00066 data_to_send<<=8; 00067 data_to_send = data_to_send | 0x7F; 00068 sendDataToDisplay(data_to_send); 00069 } 00070 } 00071 00072 void LED7segDisplay::Display_6D_write(int32_t value) 00073 { 00074 00075 uint8_t digit; 00076 uint16_t data_to_send; 00077 char TextString[6]; 00078 00079 // int to string, then string to digits 00080 sprintf(TextString, "%6d", value); // int to string 00081 00082 for(uint8_t i=0; i<6; i++) 00083 { 00084 if(TextString[i] == ' ') // blank empty digits 00085 Disp_Digit[i] = 0x7F; 00086 else 00087 Disp_Digit[i] = TextString[i]-'0'; 00088 } 00089 00090 for(digit = 1; digit <7; digit++) 00091 { 00092 // each stream consists of digit address and data to show 00093 data_to_send = 7 - digit; 00094 data_to_send<<=8; 00095 data_to_send = data_to_send | Disp_Digit[digit-1]; 00096 sendDataToDisplay(data_to_send); 00097 } 00098 00099 return; 00100 } 00101 00102 void LED7segDisplay::Display_2D_write(int16_t value) 00103 { 00104 bool negative = false; 00105 if (value < 0) 00106 negative = true; 00107 value = abs(value); 00108 00109 uint8_t digit; 00110 uint16_t data_to_send; 00111 char TextString[2]; 00112 00113 // int to string, then string to digits 00114 sprintf(TextString, "%2d", value); // int to string 00115 00116 if(TextString[0] == ' ') // blank empty digits 00117 Disp_Digit[7] = 0x7F; 00118 else 00119 Disp_Digit[7] = TextString[0] - '0'; 00120 00121 Disp_Digit[6] = TextString[1] - '0'; 00122 // turn on decimal point to indicate negative 00123 if (negative) 00124 Disp_Digit[6] |= 0x80; 00125 00126 for(digit = 7; digit <9; digit++) 00127 { 00128 // each stream consists of digit address and data to show 00129 data_to_send = digit; 00130 data_to_send<<=8; 00131 data_to_send = data_to_send | Disp_Digit[digit-1]; 00132 sendDataToDisplay(data_to_send); 00133 } 00134 00135 return; 00136 } 00137 00138 void LED7segDisplay::sendDataToDisplay(uint16_t data_to_send) 00139 { 00140 CS1 = 0; 00141 for(uint16_t mask = 0x8000; mask!= 0; mask>>= 1) 00142 { 00143 wait_us(DT); 00144 SCK = 0; 00145 if(mask & data_to_send) 00146 MOSI = 1; 00147 else 00148 MOSI = 0; 00149 00150 wait_us(DT); 00151 SCK = 1; 00152 } 00153 00154 wait_us(DT); 00155 SCK = 0; 00156 wait_us(DT); 00157 CS1 = 1; 00158 }
Generated on Sun Jul 24 2022 06:22:38 by
1.7.2
