Maxim Integrated
/
MAXREFDES99_demo
Demo for MAXREFDES99
main.cpp@8:a6a0c9e280ae, 2016-05-24 (annotated)
- Committer:
- pradipv
- Date:
- Tue May 24 08:40:07 2016 +0000
- Revision:
- 8:a6a0c9e280ae
- Parent:
- 7:4b81ed6da6ab
version1.2 - Updated with code cleanup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:6b0161c3e440 | 1 | /*********************************************************************** |
j3 | 0:6b0161c3e440 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:6b0161c3e440 | 3 | * |
j3 | 0:6b0161c3e440 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:6b0161c3e440 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:6b0161c3e440 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 0:6b0161c3e440 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:6b0161c3e440 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:6b0161c3e440 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:6b0161c3e440 | 10 | * |
j3 | 0:6b0161c3e440 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 0:6b0161c3e440 | 12 | * in all copies or substantial portions of the Software. |
j3 | 0:6b0161c3e440 | 13 | * |
j3 | 0:6b0161c3e440 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:6b0161c3e440 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:6b0161c3e440 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:6b0161c3e440 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:6b0161c3e440 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:6b0161c3e440 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:6b0161c3e440 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:6b0161c3e440 | 21 | * |
j3 | 0:6b0161c3e440 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:6b0161c3e440 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:6b0161c3e440 | 24 | * Products, Inc. Branding Policy. |
j3 | 0:6b0161c3e440 | 25 | * |
j3 | 0:6b0161c3e440 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 0:6b0161c3e440 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:6b0161c3e440 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:6b0161c3e440 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:6b0161c3e440 | 30 | * ownership rights. |
j3 | 0:6b0161c3e440 | 31 | **********************************************************************/ |
pradipv | 8:a6a0c9e280ae | 32 | #include "maxrefdes99.h" |
j3 | 0:6b0161c3e440 | 33 | |
j3 | 0:6b0161c3e440 | 34 | |
j3 | 0:6b0161c3e440 | 35 | int main(void) |
j3 | 0:6b0161c3e440 | 36 | { |
j3 | 0:6b0161c3e440 | 37 | Max7219 display(D11, D12, D13, D10); |
j3 | 0:6b0161c3e440 | 38 | |
j3 | 0:6b0161c3e440 | 39 | //struct for holding MAX7219 configuration data |
j3 | 0:6b0161c3e440 | 40 | max7219_configuration_t display_config; |
pradipv | 8:a6a0c9e280ae | 41 | |
j3 | 0:6b0161c3e440 | 42 | //configuration data |
j3 | 0:6b0161c3e440 | 43 | display_config.decode_mode = 0; //no BCD decode |
pradipv | 8:a6a0c9e280ae | 44 | display_config.intensity = Max7219::MAX7219_INTENSITY_F; //max intensity |
pradipv | 8:a6a0c9e280ae | 45 | display_config.scan_limit = Max7219::MAX7219_SCAN_8; //scan all digits |
j3 | 0:6b0161c3e440 | 46 | |
j3 | 0:6b0161c3e440 | 47 | //set number of MAX7219 devices being used |
j3 | 0:6b0161c3e440 | 48 | display.set_num_devices(4); |
j3 | 0:6b0161c3e440 | 49 | |
j3 | 0:6b0161c3e440 | 50 | //config display |
j3 | 0:6b0161c3e440 | 51 | display.init_display(display_config); |
j3 | 0:6b0161c3e440 | 52 | |
j3 | 0:6b0161c3e440 | 53 | //ensure all data registers are 0 |
j3 | 0:6b0161c3e440 | 54 | display.display_all_off(); |
j3 | 0:6b0161c3e440 | 55 | |
j3 | 0:6b0161c3e440 | 56 | display.enable_display(); |
j3 | 0:6b0161c3e440 | 57 | |
pradipv | 3:41bdbc9b3cec | 58 | uint32_t user_input = 0,user_font = 0; |
j3 | 0:6b0161c3e440 | 59 | uint32_t shift_right; |
j3 | 0:6b0161c3e440 | 60 | char user_char; |
j3 | 0:6b0161c3e440 | 61 | char *p_str; |
j3 | 0:6b0161c3e440 | 62 | |
j3 | 0:6b0161c3e440 | 63 | while(user_input != 9) |
j3 | 0:6b0161c3e440 | 64 | { |
j3 | 0:6b0161c3e440 | 65 | user_input = print_menu(); |
j3 | 0:6b0161c3e440 | 66 | |
j3 | 0:6b0161c3e440 | 67 | switch(user_input) |
j3 | 0:6b0161c3e440 | 68 | { |
pradipv | 8:a6a0c9e280ae | 69 | case 1: |
pradipv | 8:a6a0c9e280ae | 70 | printf("\n 0: For 5x7 font"); |
pradipv | 8:a6a0c9e280ae | 71 | printf("\n 1: For 16x16 Aerial bold font"); |
pradipv | 8:a6a0c9e280ae | 72 | printf("\n 2: For 16x16 Manual font"); |
pradipv | 8:a6a0c9e280ae | 73 | user_font = get_user_input("\nPlease select font: ", 2); |
pradipv | 8:a6a0c9e280ae | 74 | if((user_font == 1) || (user_font == 2)) |
pradipv | 8:a6a0c9e280ae | 75 | printf("\nNote:Position option works only for 5x7 font\n"); |
pradipv | 8:a6a0c9e280ae | 76 | break; |
pradipv | 3:41bdbc9b3cec | 77 | case 2: |
pradipv | 8:a6a0c9e280ae | 78 | user_input = get_user_input("\nPlease enter a value from 0 to 15: ", 15); |
pradipv | 8:a6a0c9e280ae | 79 | printf("\nUpdating display configuration...\n"); |
pradipv | 8:a6a0c9e280ae | 80 | display_config.intensity = user_input; |
pradipv | 8:a6a0c9e280ae | 81 | display.init_display(display_config); |
pradipv | 8:a6a0c9e280ae | 82 | //make sure is good for next loop |
pradipv | 8:a6a0c9e280ae | 83 | user_input = 0; |
pradipv | 8:a6a0c9e280ae | 84 | break; |
pradipv | 8:a6a0c9e280ae | 85 | case 3: |
pradipv | 8:a6a0c9e280ae | 86 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 87 | user_input = get_user_input("\nPlease enter which position, 1 to 32: ", 32); |
pradipv | 8:a6a0c9e280ae | 88 | user_char = get_user_char("\nPlease enter an ASCII character from '0' (zero) to 'z' (0x7A): "); |
pradipv | 8:a6a0c9e280ae | 89 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 90 | print_char(&display, user_input, user_char); |
pradipv | 8:a6a0c9e280ae | 91 | else if(user_font >= 1) |
pradipv | 8:a6a0c9e280ae | 92 | print_char_16x16(&display, 0, user_char, user_font); |
pradipv | 8:a6a0c9e280ae | 93 | //make sure is good for next loop |
pradipv | 8:a6a0c9e280ae | 94 | user_input = 0; |
pradipv | 8:a6a0c9e280ae | 95 | break; |
pradipv | 3:41bdbc9b3cec | 96 | case 4: |
pradipv | 8:a6a0c9e280ae | 97 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 98 | user_input = get_user_input("\nPlease enter which position 1 to 32: ", 32); |
pradipv | 8:a6a0c9e280ae | 99 | p_str = get_user_string("\nPlease enter a string less than 24 characters: "); |
pradipv | 8:a6a0c9e280ae | 100 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 101 | print_string(&display, user_input, p_str); |
pradipv | 8:a6a0c9e280ae | 102 | else if(user_font >=1) |
pradipv | 8:a6a0c9e280ae | 103 | print_string_16x16(&display, p_str, user_font); |
pradipv | 8:a6a0c9e280ae | 104 | //make sure is good for next loop |
pradipv | 8:a6a0c9e280ae | 105 | user_input = 0; |
pradipv | 8:a6a0c9e280ae | 106 | break; |
pradipv | 3:41bdbc9b3cec | 107 | case 5: |
pradipv | 8:a6a0c9e280ae | 108 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 109 | user_input = get_user_input("\nPlease enter number of shifts, 1 to 32: ", 32); |
pradipv | 8:a6a0c9e280ae | 110 | else if(user_font >= 1) |
pradipv | 8:a6a0c9e280ae | 111 | user_input = get_user_input("\nPlease enter number of shifts, 1 to 96: ", 96); |
pradipv | 8:a6a0c9e280ae | 112 | shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right: ", 1); |
pradipv | 8:a6a0c9e280ae | 113 | if(shift_right) |
pradipv | 8:a6a0c9e280ae | 114 | { |
pradipv | 8:a6a0c9e280ae | 115 | printf("\nShifting Display Right %d positions\n", user_input); |
pradipv | 8:a6a0c9e280ae | 116 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 117 | shift_display_right(&display, user_input, 100); |
pradipv | 8:a6a0c9e280ae | 118 | else if(user_font >= 1) |
pradipv | 8:a6a0c9e280ae | 119 | shift_display_right_16x16(&display, user_input, 100); |
pradipv | 8:a6a0c9e280ae | 120 | } |
pradipv | 8:a6a0c9e280ae | 121 | else |
pradipv | 8:a6a0c9e280ae | 122 | { |
pradipv | 8:a6a0c9e280ae | 123 | printf("\nShifting Display Left %d positions\n", user_input); |
pradipv | 8:a6a0c9e280ae | 124 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 125 | shift_display_left(&display, user_input, 100); |
pradipv | 8:a6a0c9e280ae | 126 | else if(user_font >= 1) |
pradipv | 8:a6a0c9e280ae | 127 | shift_display_left_16x16(&display, user_input, 100); |
pradipv | 8:a6a0c9e280ae | 128 | } |
pradipv | 8:a6a0c9e280ae | 129 | break; |
pradipv | 8:a6a0c9e280ae | 130 | case 6: |
pradipv | 8:a6a0c9e280ae | 131 | all_off(&display); |
pradipv | 8:a6a0c9e280ae | 132 | break; |
pradipv | 8:a6a0c9e280ae | 133 | case 7: |
pradipv | 8:a6a0c9e280ae | 134 | printf("\nRunning Demo\n"); |
pradipv | 3:41bdbc9b3cec | 135 | if(user_font==0) |
pradipv | 8:a6a0c9e280ae | 136 | demo(&display, display_config, false); |
pradipv | 8:a6a0c9e280ae | 137 | else if(user_font >= 1) |
pradipv | 8:a6a0c9e280ae | 138 | demo_16x16(&display, display_config, user_font, false); |
pradipv | 8:a6a0c9e280ae | 139 | break; |
j3 | 0:6b0161c3e440 | 140 | case 8: |
pradipv | 8:a6a0c9e280ae | 141 | //blocking case, endless loop |
pradipv | 8:a6a0c9e280ae | 142 | shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right: ", 1); |
pradipv | 8:a6a0c9e280ae | 143 | if(user_font == 0) |
pradipv | 8:a6a0c9e280ae | 144 | endless_scroll_display(&display, shift_right); |
pradipv | 8:a6a0c9e280ae | 145 | else if(user_font >= 1) |
pradipv | 8:a6a0c9e280ae | 146 | endless_scroll_display_16x16(&display, shift_right); |
pradipv | 8:a6a0c9e280ae | 147 | break; |
j3 | 0:6b0161c3e440 | 148 | case 9: |
pradipv | 8:a6a0c9e280ae | 149 | printf("\nEnding Program\n"); |
pradipv | 8:a6a0c9e280ae | 150 | break; |
j3 | 0:6b0161c3e440 | 151 | default: |
pradipv | 8:a6a0c9e280ae | 152 | printf("\nInvalid entry, please try again\n"); |
pradipv | 8:a6a0c9e280ae | 153 | break; |
j3 | 0:6b0161c3e440 | 154 | } |
j3 | 0:6b0161c3e440 | 155 | } |
j3 | 0:6b0161c3e440 | 156 | return 0; |
j3 | 0:6b0161c3e440 | 157 | } |
pradipv | 3:41bdbc9b3cec | 158 |