Demo for MAXREFDES99

Dependencies:   MAX7219 mbed

Committer:
j3
Date:
Tue Jan 12 23:44:43 2016 +0000
Revision:
0:6b0161c3e440
Child:
3:41bdbc9b3cec
Initial commit

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
j3 0:6b0161c3e440 34 #include "maxrefdes99.h"
j3 0:6b0161c3e440 35
j3 0:6b0161c3e440 36
j3 0:6b0161c3e440 37 int main(void)
j3 0:6b0161c3e440 38 {
j3 0:6b0161c3e440 39 Max7219 display(D11, D12, D13, D10);
j3 0:6b0161c3e440 40
j3 0:6b0161c3e440 41 //struct for holding MAX7219 configuration data
j3 0:6b0161c3e440 42 max7219_configuration_t display_config;
j3 0:6b0161c3e440 43
j3 0:6b0161c3e440 44 //configuration data
j3 0:6b0161c3e440 45 display_config.decode_mode = 0; //no BCD decode
j3 0:6b0161c3e440 46 display_config.intensity = 0x0F; //max intensity
j3 0:6b0161c3e440 47 display_config.scan_limit = 0x07; //scan all digits
j3 0:6b0161c3e440 48
j3 0:6b0161c3e440 49 //set number of MAX7219 devices being used
j3 0:6b0161c3e440 50 display.set_num_devices(4);
j3 0:6b0161c3e440 51
j3 0:6b0161c3e440 52 //config display
j3 0:6b0161c3e440 53 display.init_display(display_config);
j3 0:6b0161c3e440 54
j3 0:6b0161c3e440 55 //ensure all data registers are 0
j3 0:6b0161c3e440 56 display.display_all_off();
j3 0:6b0161c3e440 57
j3 0:6b0161c3e440 58 display.enable_display();
j3 0:6b0161c3e440 59
j3 0:6b0161c3e440 60 uint32_t user_input = 0; //
j3 0:6b0161c3e440 61 uint32_t shift_right;
j3 0:6b0161c3e440 62 char user_char;
j3 0:6b0161c3e440 63 char *p_str;
j3 0:6b0161c3e440 64
j3 0:6b0161c3e440 65 while(user_input != 9)
j3 0:6b0161c3e440 66 {
j3 0:6b0161c3e440 67 user_input = print_menu();
j3 0:6b0161c3e440 68
j3 0:6b0161c3e440 69 switch(user_input)
j3 0:6b0161c3e440 70 {
j3 0:6b0161c3e440 71 case 1:
j3 0:6b0161c3e440 72
j3 0:6b0161c3e440 73 user_input = get_user_input("\nPlease enter a value from 0 to 15: ", 15);
j3 0:6b0161c3e440 74
j3 0:6b0161c3e440 75 printf("\nUpdating display configuration...\n");
j3 0:6b0161c3e440 76
j3 0:6b0161c3e440 77 display_config.intensity = user_input;
j3 0:6b0161c3e440 78
j3 0:6b0161c3e440 79 display.init_display(display_config);
j3 0:6b0161c3e440 80
j3 0:6b0161c3e440 81 //make sure is good for next loop
j3 0:6b0161c3e440 82 user_input = 0;
j3 0:6b0161c3e440 83
j3 0:6b0161c3e440 84 break;
j3 0:6b0161c3e440 85
j3 0:6b0161c3e440 86 case 2:
j3 0:6b0161c3e440 87
j3 0:6b0161c3e440 88 user_input = get_user_input("\nPlease enter which position, 1 to 32: ", 32);
j3 0:6b0161c3e440 89
j3 0:6b0161c3e440 90 user_char = get_user_char("\nPlease enter an ASCII character from 'space' (0x20), to '~' (0x7E): ");
j3 0:6b0161c3e440 91
j3 0:6b0161c3e440 92 print_char(&display, user_input, user_char);
j3 0:6b0161c3e440 93
j3 0:6b0161c3e440 94 //make sure is good for next loop
j3 0:6b0161c3e440 95 user_input = 0;
j3 0:6b0161c3e440 96
j3 0:6b0161c3e440 97 break;
j3 0:6b0161c3e440 98
j3 0:6b0161c3e440 99 case 3:
j3 0:6b0161c3e440 100
j3 0:6b0161c3e440 101 user_input = get_user_input("\nPlease enter which position, 1 to 32: ", 32);
j3 0:6b0161c3e440 102
j3 0:6b0161c3e440 103 p_str = get_user_string("\nPlease enter a string less than 24 characters: ");
j3 0:6b0161c3e440 104
j3 0:6b0161c3e440 105 print_string(&display, user_input, p_str);
j3 0:6b0161c3e440 106
j3 0:6b0161c3e440 107 //make sure is good for next loop
j3 0:6b0161c3e440 108 user_input = 0;
j3 0:6b0161c3e440 109
j3 0:6b0161c3e440 110 break;
j3 0:6b0161c3e440 111
j3 0:6b0161c3e440 112 case 4:
j3 0:6b0161c3e440 113
j3 0:6b0161c3e440 114 user_input = get_user_input("\nPlease enter number of shifts, 1 to 32: ", 32);
j3 0:6b0161c3e440 115 shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right.: ", 1);
j3 0:6b0161c3e440 116
j3 0:6b0161c3e440 117 if(shift_right)
j3 0:6b0161c3e440 118 {
j3 0:6b0161c3e440 119 printf("\nShifting Display Right %d positions\n", user_input);
j3 0:6b0161c3e440 120 shift_display_right(&display, user_input, 100);
j3 0:6b0161c3e440 121 }
j3 0:6b0161c3e440 122 else
j3 0:6b0161c3e440 123 {
j3 0:6b0161c3e440 124 printf("\nShifting Display Left %d positions\n", user_input);
j3 0:6b0161c3e440 125 shift_display_left(&display, user_input, 100);
j3 0:6b0161c3e440 126 }
j3 0:6b0161c3e440 127
j3 0:6b0161c3e440 128 break;
j3 0:6b0161c3e440 129
j3 0:6b0161c3e440 130 case 5:
j3 0:6b0161c3e440 131
j3 0:6b0161c3e440 132 all_off(&display);
j3 0:6b0161c3e440 133
j3 0:6b0161c3e440 134 break;
j3 0:6b0161c3e440 135
j3 0:6b0161c3e440 136 case 6:
j3 0:6b0161c3e440 137
j3 0:6b0161c3e440 138 printf("\nRunning Demo\n");
j3 0:6b0161c3e440 139 demo(&display, display_config, false);
j3 0:6b0161c3e440 140
j3 0:6b0161c3e440 141 break;
j3 0:6b0161c3e440 142
j3 0:6b0161c3e440 143 case 7:
j3 0:6b0161c3e440 144
j3 0:6b0161c3e440 145 printf("\nEntering Endless Loop\n");
j3 0:6b0161c3e440 146 demo(&display, display_config, true);
j3 0:6b0161c3e440 147
j3 0:6b0161c3e440 148 break;
j3 0:6b0161c3e440 149
j3 0:6b0161c3e440 150 case 8:
j3 0:6b0161c3e440 151
j3 0:6b0161c3e440 152 //blocking case, endless loop
j3 0:6b0161c3e440 153 shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right.: ", 1);
j3 0:6b0161c3e440 154 endless_scroll_display(&display, shift_right);
j3 0:6b0161c3e440 155
j3 0:6b0161c3e440 156 break;
j3 0:6b0161c3e440 157
j3 0:6b0161c3e440 158 case 9:
j3 0:6b0161c3e440 159
j3 0:6b0161c3e440 160 printf("\nEnding Program\n");
j3 0:6b0161c3e440 161
j3 0:6b0161c3e440 162 break;
j3 0:6b0161c3e440 163
j3 0:6b0161c3e440 164 default:
j3 0:6b0161c3e440 165 printf("\nInvalid entry, please try again\n");
j3 0:6b0161c3e440 166 break;
j3 0:6b0161c3e440 167 }
j3 0:6b0161c3e440 168 }
j3 0:6b0161c3e440 169
j3 0:6b0161c3e440 170 return 0;
j3 0:6b0161c3e440 171 }