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.
MAX7219.cpp
00001 /** 00002 * @brief MAX7219.h 00003 * @details Serially Interfaced, 8-Digit LED Display Drivers. 00004 * Header file. 00005 * 00006 * 00007 * @return NA 00008 * 00009 * @author Manuel Caballero 00010 * @date 9/October/2017 00011 * @version 9/October/2017 The ORIGIN 00012 * @pre NaN. 00013 * @warning NaN 00014 * @pre This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ). 00015 */ 00016 00017 #include "MAX7219.h" 00018 00019 00020 MAX7219::MAX7219 ( PinName mosi, PinName miso, PinName sclk, PinName cs, uint32_t freq ) 00021 : _spi ( mosi, miso, sclk ) 00022 , _cs ( cs ) 00023 { 00024 _spi.frequency( freq ); 00025 } 00026 00027 00028 MAX7219::~MAX7219() 00029 { 00030 } 00031 00032 00033 00034 /** 00035 * @brief MAX7219_Mode ( MAX7219_shutdown_reg_t ) 00036 * 00037 * @details It puts the device in shutdown mode. 00038 * 00039 * @param[in] myMAX7219mode: Shutdown or Normal operation mode. 00040 * 00041 * @param[out] NaN. 00042 * 00043 * 00044 * @return Status of MAX7219_Mode. 00045 * 00046 * 00047 * @author Manuel Caballero 00048 * @date 9/October/2017 00049 * @version 9/October/2017 The ORIGIN 00050 * @pre NaN 00051 * @warning NaN. 00052 */ 00053 MAX7219::MAX7219_status_t MAX7219::MAX7219_Mode ( MAX7219_shutdown_reg_t myMAX7219mode ) 00054 { 00055 char cmd[] = { SHUTDOWN , 0 }; 00056 int mySPI_status = 0; 00057 00058 00059 cmd[ 1 ] = myMAX7219mode; 00060 00061 _cs = 0; 00062 mySPI_status = _spi.write ( &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), &cmd[0], 0 ); 00063 _cs = 1; 00064 00065 00066 if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) 00067 return MAX7219_SUCCESS; 00068 else 00069 return MAX7219_FAILURE; 00070 } 00071 00072 00073 00074 /** 00075 * @brief MAX7219_DisplayTest ( MAX7219_display_test_reg_t ) 00076 * 00077 * @details It turns all the LEDs on ( Test mode enabled ) or normal operation. 00078 * 00079 * @param[in] myMAX7219DisplayTestMode: Mode: Test or Normal operation. 00080 * 00081 * @param[out] NaN. 00082 * 00083 * 00084 * @return Status of MAX7219_DisplayTest. 00085 * 00086 * 00087 * @author Manuel Caballero 00088 * @date 9/October/2017 00089 * @version 9/October/2017 The ORIGIN 00090 * @pre NaN 00091 * @warning NaN. 00092 */ 00093 MAX7219::MAX7219_status_t MAX7219::MAX7219_DisplayTest ( MAX7219_display_test_reg_t myMAX7219DisplayTestMode ) 00094 { 00095 char cmd[] = { DISPLAY_TEST , 0 }; 00096 int mySPI_status = 0; 00097 00098 00099 cmd[ 1 ] = myMAX7219DisplayTestMode; 00100 00101 00102 _cs = 0; 00103 mySPI_status = _spi.write ( &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), &cmd[0], 0 ); 00104 _cs = 1; 00105 00106 00107 00108 if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) 00109 return MAX7219_SUCCESS; 00110 else 00111 return MAX7219_FAILURE; 00112 } 00113 00114 00115 00116 /** 00117 * @brief MAX7219_DecodeMode ( MAX7219_decode_mode_reg_t ) 00118 * 00119 * @details It enables and configures the decode-mode or turns it off. 00120 * 00121 * @param[in] myMAX7219DecodeMode: Decode-mode option. 00122 * 00123 * @param[out] NaN. 00124 * 00125 * 00126 * @return Status of MAX7219_DecodeMode. 00127 * 00128 * 00129 * @author Manuel Caballero 00130 * @date 9/October/2017 00131 * @version 9/October/2017 The ORIGIN 00132 * @pre NaN 00133 * @warning NaN. 00134 */ 00135 MAX7219::MAX7219_status_t MAX7219::MAX7219_DecodeMode ( MAX7219_decode_mode_reg_t myMAX7219DecodeMode ) 00136 { 00137 char cmd[] = { DECODE_MODE , 0 }; 00138 int mySPI_status = 0; 00139 00140 00141 cmd[ 1 ] = myMAX7219DecodeMode; 00142 00143 00144 _cs = 0; 00145 mySPI_status = _spi.write ( &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), &cmd[0], 0 ); 00146 _cs = 1; 00147 00148 00149 00150 if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) 00151 return MAX7219_SUCCESS; 00152 else 00153 return MAX7219_FAILURE; 00154 } 00155 00156 00157 00158 /** 00159 * @brief MAX7219_SetIntensity ( MAX7219_intensity_reg_t ) 00160 * 00161 * @details It configures the intensity of the device. 00162 * 00163 * @param[in] myMAX7219Intensity: Intensity option. 00164 * 00165 * @param[out] NaN. 00166 * 00167 * 00168 * @return Status of MAX7219_SetIntensity. 00169 * 00170 * 00171 * @author Manuel Caballero 00172 * @date 9/October/2017 00173 * @version 9/October/2017 The ORIGIN 00174 * @pre NaN 00175 * @warning NaN. 00176 */ 00177 MAX7219::MAX7219_status_t MAX7219::MAX7219_SetIntensity ( MAX7219_intensity_reg_t myMAX7219Intensity ) 00178 { 00179 char cmd[] = { INTENSITY , 0 }; 00180 int mySPI_status = 0; 00181 00182 00183 cmd[ 1 ] = myMAX7219Intensity; 00184 00185 00186 _cs = 0; 00187 mySPI_status = _spi.write ( &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), &cmd[0], 0 ); 00188 _cs = 1; 00189 00190 00191 00192 if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) 00193 return MAX7219_SUCCESS; 00194 else 00195 return MAX7219_FAILURE; 00196 } 00197 00198 00199 00200 /** 00201 * @brief MAX7219_SetScanLimit ( MAX7219_scan_limit_reg_t ) 00202 * 00203 * @details It configures duty cycle of the device. 00204 * 00205 * @param[in] MAX7219_scan_limit_reg_t: Duty cycle option. 00206 * 00207 * @param[out] NaN. 00208 * 00209 * 00210 * @return Status of MAX7219_SetScanLimit. 00211 * 00212 * 00213 * @author Manuel Caballero 00214 * @date 9/October/2017 00215 * @version 9/October/2017 The ORIGIN 00216 * @pre NaN 00217 * @warning NaN. 00218 */ 00219 MAX7219::MAX7219_status_t MAX7219::MAX7219_SetScanLimit ( MAX7219_scan_limit_reg_t myMAX7219ScanLimit ) 00220 { 00221 char cmd[] = { SCAN_LIMIT , 0 }; 00222 int mySPI_status = 0; 00223 00224 00225 cmd[ 1 ] = myMAX7219ScanLimit; 00226 00227 00228 _cs = 0; 00229 mySPI_status = _spi.write ( &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), &cmd[0], 0 ); 00230 _cs = 1; 00231 00232 00233 00234 if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) 00235 return MAX7219_SUCCESS; 00236 else 00237 return MAX7219_FAILURE; 00238 } 00239 00240 00241 00242 /** 00243 * @brief MAX7219_SetDigit ( MAX7219_digit_t , MAX7219_code_b_font_reg_t , MAX7219_code_b_dp_t ) 00244 * 00245 * @details It sets the digit to be written and its value. 00246 * 00247 * @param[in] myMAX7219Digit: Digit to be written. 00248 * @param[in] myCharacter: The current value. 00249 * @param[in] myDP_status: DP enabled/disabled. 00250 * 00251 * @param[out] NaN. 00252 * 00253 * 00254 * @return Status of MAX7219_SetDigit. 00255 * 00256 * 00257 * @author Manuel Caballero 00258 * @date 9/October/2017 00259 * @version 9/October/2017 The ORIGIN 00260 * @pre NaN 00261 * @warning NaN. 00262 */ 00263 MAX7219::MAX7219_status_t MAX7219::MAX7219_SetDigit ( MAX7219_digit_t myMAX7219Digit, MAX7219_code_b_font_reg_t myCharacter, MAX7219_code_b_dp_t myDP_status ) 00264 { 00265 char cmd[] = { 0, 0 }; 00266 int mySPI_status = 0; 00267 00268 00269 switch ( myMAX7219Digit ) { 00270 default: 00271 case SET_DIGIT_0 : 00272 cmd[ 0 ] = DIGIT_0 ; 00273 break; 00274 00275 case SET_DIGIT_1 : 00276 cmd[ 0 ] = DIGIT_1 ; 00277 break; 00278 00279 case SET_DIGIT_2 : 00280 cmd[ 0 ] = DIGIT_2 ; 00281 break; 00282 00283 case SET_DIGIT_3 : 00284 cmd[ 0 ] = DIGIT_3 ; 00285 break; 00286 00287 case SET_DIGIT_4 : 00288 cmd[ 0 ] = DIGIT_4 ; 00289 break; 00290 00291 case SET_DIGIT_5 : 00292 cmd[ 0 ] = DIGIT_5 ; 00293 break; 00294 00295 case SET_DIGIT_6 : 00296 cmd[ 0 ] = DIGIT_6 ; 00297 break; 00298 00299 case SET_DIGIT_7 : 00300 cmd[ 0 ] = DIGIT_7 ; 00301 break; 00302 } 00303 00304 00305 if ( myDP_status == DP_ENABLED ) 00306 cmd[ 1 ] = ( myCharacter | 0x80 ); 00307 else 00308 cmd[ 1 ] = myCharacter; 00309 00310 00311 _cs = 0; 00312 mySPI_status = _spi.write ( &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), &cmd[0], 0 ); 00313 _cs = 1; 00314 00315 00316 00317 if ( ( mySPI_status / ( sizeof( cmd )/sizeof( cmd[0] ) ) ) == SPI_SUCCESS ) 00318 return MAX7219_SUCCESS; 00319 else 00320 return MAX7219_FAILURE; 00321 }
Generated on Sun Aug 21 2022 18:15:08 by
1.7.2