Demo for MAXREFDES99

Dependencies:   MAX7219 mbed

Committer:
pradipv
Date:
Thu Apr 28 08:46:24 2016 +0000
Revision:
7:4b81ed6da6ab
Parent:
6:00aabe967e51
Child:
8:a6a0c9e280ae
version 0.2 - Updated with note while using 16x16 fonts

Who changed what in which revision?

UserRevisionLine numberNew 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 **********************************************************************/
j3 0:6b0161c3e440 32
j3 0:6b0161c3e440 33 #include "maxrefdes99.h"
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;
j3 0:6b0161c3e440 41
j3 0:6b0161c3e440 42 //configuration data
j3 0:6b0161c3e440 43 display_config.decode_mode = 0; //no BCD decode
j3 0:6b0161c3e440 44 display_config.intensity = 0x0F; //max intensity
j3 0:6b0161c3e440 45 display_config.scan_limit = 0x07; //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 3:41bdbc9b3cec 69
pradipv 3:41bdbc9b3cec 70 case 1:
pradipv 6:00aabe967e51 71 printf("\n 0: For 5x7 font");
pradipv 6:00aabe967e51 72 printf("\n 1: For 16x16 Aerial bold font");
pradipv 6:00aabe967e51 73 printf("\n 2: For 16x16 Manual font");
pradipv 6:00aabe967e51 74 user_font = get_user_input("\nPlease select font: ", 2);
pradipv 7:4b81ed6da6ab 75 if((user_font ==1)||(user_font ==2))
pradipv 6:00aabe967e51 76 printf("\nNote:Position option works only for 5x7 font\n");
pradipv 3:41bdbc9b3cec 77 break;
pradipv 3:41bdbc9b3cec 78
pradipv 3:41bdbc9b3cec 79 case 2:
j3 0:6b0161c3e440 80
j3 0:6b0161c3e440 81 user_input = get_user_input("\nPlease enter a value from 0 to 15: ", 15);
j3 0:6b0161c3e440 82
j3 0:6b0161c3e440 83 printf("\nUpdating display configuration...\n");
j3 0:6b0161c3e440 84
j3 0:6b0161c3e440 85 display_config.intensity = user_input;
j3 0:6b0161c3e440 86
j3 0:6b0161c3e440 87 display.init_display(display_config);
j3 0:6b0161c3e440 88
j3 0:6b0161c3e440 89 //make sure is good for next loop
j3 0:6b0161c3e440 90 user_input = 0;
j3 0:6b0161c3e440 91
j3 0:6b0161c3e440 92 break;
j3 0:6b0161c3e440 93
pradipv 3:41bdbc9b3cec 94 case 3:
pradipv 3:41bdbc9b3cec 95
pradipv 3:41bdbc9b3cec 96 if(user_font==0)
pradipv 3:41bdbc9b3cec 97 user_input = get_user_input("\nPlease enter which position, 1 to 32: ", 32);
pradipv 3:41bdbc9b3cec 98
pradipv 3:41bdbc9b3cec 99 user_char = get_user_char("\nPlease enter an ASCII character from '0' (zero) to 'z' (0x7A): ");
j3 0:6b0161c3e440 100
pradipv 3:41bdbc9b3cec 101 if(user_font==0)
pradipv 3:41bdbc9b3cec 102 print_char(&display, user_input, user_char);
pradipv 6:00aabe967e51 103 else if(user_font>=1)
pradipv 6:00aabe967e51 104 print_char_16x16(&display, 0, user_char,user_font);
pradipv 3:41bdbc9b3cec 105
j3 0:6b0161c3e440 106 //make sure is good for next loop
j3 0:6b0161c3e440 107 user_input = 0;
j3 0:6b0161c3e440 108
j3 0:6b0161c3e440 109 break;
j3 0:6b0161c3e440 110
pradipv 3:41bdbc9b3cec 111 case 4:
j3 0:6b0161c3e440 112
pradipv 3:41bdbc9b3cec 113 if(user_font==0)
pradipv 6:00aabe967e51 114 user_input = get_user_input("\nPlease enter which position 1 to 32: ", 32);
pradipv 3:41bdbc9b3cec 115
j3 0:6b0161c3e440 116 p_str = get_user_string("\nPlease enter a string less than 24 characters: ");
j3 0:6b0161c3e440 117
pradipv 3:41bdbc9b3cec 118 if(user_font==0)
pradipv 3:41bdbc9b3cec 119 print_string(&display, user_input, p_str);
pradipv 6:00aabe967e51 120 else if(user_font>=1)
pradipv 6:00aabe967e51 121 print_string_16x16(&display,p_str,user_font);
pradipv 3:41bdbc9b3cec 122
j3 0:6b0161c3e440 123 //make sure is good for next loop
j3 0:6b0161c3e440 124 user_input = 0;
j3 0:6b0161c3e440 125
j3 0:6b0161c3e440 126 break;
j3 0:6b0161c3e440 127
pradipv 3:41bdbc9b3cec 128 case 5:
j3 0:6b0161c3e440 129
pradipv 3:41bdbc9b3cec 130 if(user_font==0)
pradipv 3:41bdbc9b3cec 131 user_input = get_user_input("\nPlease enter number of shifts, 1 to 32: ", 32);
pradipv 6:00aabe967e51 132 else if(user_font>=1)
pradipv 3:41bdbc9b3cec 133 user_input = get_user_input("\nPlease enter number of shifts, 1 to 96: ", 96);
pradipv 3:41bdbc9b3cec 134
pradipv 3:41bdbc9b3cec 135 shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right: ", 1);
j3 0:6b0161c3e440 136
j3 0:6b0161c3e440 137 if(shift_right)
j3 0:6b0161c3e440 138 {
j3 0:6b0161c3e440 139 printf("\nShifting Display Right %d positions\n", user_input);
pradipv 3:41bdbc9b3cec 140 if(user_font==0)
pradipv 3:41bdbc9b3cec 141 shift_display_right(&display, user_input, 100);
pradipv 6:00aabe967e51 142 else if(user_font>=1)
pradipv 3:41bdbc9b3cec 143 shift_display_right_16x16(&display, user_input, 100);
j3 0:6b0161c3e440 144 }
j3 0:6b0161c3e440 145 else
j3 0:6b0161c3e440 146 {
j3 0:6b0161c3e440 147 printf("\nShifting Display Left %d positions\n", user_input);
pradipv 3:41bdbc9b3cec 148 if(user_font==0)
pradipv 3:41bdbc9b3cec 149 shift_display_left(&display, user_input, 100);
pradipv 6:00aabe967e51 150 else if(user_font>=1)
pradipv 3:41bdbc9b3cec 151 shift_display_left_16x16(&display, user_input, 100);
pradipv 3:41bdbc9b3cec 152
j3 0:6b0161c3e440 153 }
j3 0:6b0161c3e440 154
j3 0:6b0161c3e440 155 break;
j3 0:6b0161c3e440 156
pradipv 3:41bdbc9b3cec 157 case 6:
j3 0:6b0161c3e440 158
j3 0:6b0161c3e440 159 all_off(&display);
j3 0:6b0161c3e440 160
j3 0:6b0161c3e440 161 break;
j3 0:6b0161c3e440 162
pradipv 3:41bdbc9b3cec 163 case 7:
j3 0:6b0161c3e440 164
j3 0:6b0161c3e440 165 printf("\nRunning Demo\n");
pradipv 3:41bdbc9b3cec 166 if(user_font==0)
pradipv 6:00aabe967e51 167 demo(&display, display_config, false);
pradipv 6:00aabe967e51 168 else if(user_font>=1)
pradipv 6:00aabe967e51 169 demo_16x16(&display, display_config, user_font,false);
j3 0:6b0161c3e440 170
j3 0:6b0161c3e440 171 break;
pradipv 3:41bdbc9b3cec 172
j3 0:6b0161c3e440 173 case 8:
j3 0:6b0161c3e440 174
j3 0:6b0161c3e440 175 //blocking case, endless loop
pradipv 3:41bdbc9b3cec 176 shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right: ", 1);
pradipv 3:41bdbc9b3cec 177 if(user_font==0)
pradipv 6:00aabe967e51 178 endless_scroll_display(&display, shift_right);
pradipv 6:00aabe967e51 179 else if(user_font>=1)
pradipv 6:00aabe967e51 180 endless_scroll_display_16x16(&display, shift_right);
j3 0:6b0161c3e440 181
j3 0:6b0161c3e440 182 break;
j3 0:6b0161c3e440 183
j3 0:6b0161c3e440 184 case 9:
pradipv 3:41bdbc9b3cec 185 printf("\nEnding Program\n");
j3 0:6b0161c3e440 186 break;
j3 0:6b0161c3e440 187
j3 0:6b0161c3e440 188 default:
j3 0:6b0161c3e440 189 printf("\nInvalid entry, please try again\n");
j3 0:6b0161c3e440 190 break;
j3 0:6b0161c3e440 191 }
j3 0:6b0161c3e440 192 }
j3 0:6b0161c3e440 193 return 0;
j3 0:6b0161c3e440 194 }
pradipv 3:41bdbc9b3cec 195