MAXREFDES63# Code Documentation  V01.00
8-Channel Digital Output MicroPLC
 All Files Functions Variables Macros Pages
main.c
Go to the documentation of this file.
1 
28 /*
29 * Copyright (C) 2012 Maxim Integrated Products, Inc., All Rights Reserved.
30 *
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
37 *
38 * The above copyright notice and this permission notice shall be included
39 * in all copies or substantial portions of the Software.
40 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
42 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44 * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
45 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47 * OTHER DEALINGS IN THE SOFTWARE.
48 *
49 * Except as contained in this notice, the name of Maxim Integrated Products
50 * shall not be used except as stated in the Maxim Integrated Products
51 * Branding Policy.
52 *
53 * The mere transfer of this software does not imply any licenses
54 * of trade secrets, proprietary technology, copyrights, patents,
55 * trademarks, maskwork rights, or any other form of intellectual
56 * property whatsoever. Maxim Integrated Products retains all ownership rights.
57 *
58 ***************************************************************************/
75 /* Includes ------------------------------------------------------------------*/
76 #include "stm32f10x.h"
77 #include "stm32f10x_gpio.h"
78 #include "stm32f10x_rcc.h"
79 #include "stm32f10x_usart.h"
80 #include "stm32f10x_spi.h"
81 #include "init_config.h"
82 #include "menu.h"
83 #include "utilities.h"
84 #include "max14900e.h"
85 #include <stdio.h>
86 
87 
88 /* Private typedef -----------------------------------------------------------*/
89 /* Private define ------------------------------------------------------------*/
90 #define MAJOR_REVISION 01
91 #define MINOR_REVISION 00
92 /* Private macro -------------------------------------------------------------*/
93 /* Private variables ---------------------------------------------------------*/
94 /* Private function prototypes -----------------------------------------------*/
95 /* Private functions ---------------------------------------------------------*/
96 
105 int main(void)
106 {
107  int n_menu_state=MAIN_MENU;
108  uint8_t uch_first_entry=1;
109  uint8_t uch_input;
110  uint16_t u_config, u_value, u_fault;
111 
112  maxim_gpio_init();
113  maxim_spi_init();
114  maxim_uart_init();
116 
117  // Clear the Screen, and then display the big Maxim banner for about 2 seconds
118  maxim_menu_cls();
120  printf("Maxim MAXREFDES63#\r\n");
121  printf("Revision v%d.%d\r\n",MAJOR_REVISION,MINOR_REVISION);
122 
123  maxim_delay(2*ONE_SECOND); //2 second pause
124 
125  while(1)
126  {
127  switch(n_menu_state)
128  {
129  case MAIN_MENU:
130  maxim_menu_cls();
132  do{
133  if(uch_first_entry==1)
134  {
135  if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET)
136  {
137  maxim_delay(ONE_SECOND); //1 sec pause
138  }
139  if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET)
140  {
141  maxim_delay(ONE_SECOND); //1 sec pause
142  n_menu_state = MAIN_MENU;
143  break;
144  }
145  }
146  uch_first_entry=0;
147  uch_input = getchar(); //press any key
148  printf("%c\r\n",uch_input);
149  n_menu_state = SET_CONFIG;
150  break;
151  }while(1);
152  break;
153 
154  case SET_CONFIG:
156  printf("\n\n\n\rEnter in the Configuration Byte in hex format. \n\rFor example FF to set all outputs to push-pull mode\n\r");
157  u_config=maxim_get_hex();
158  n_menu_state = SET_OUTPUT;
159  break;
160 
161  case SET_OUTPUT:
163  printf("\n\n\n\rEnter the desired output data in hex format. \n\rFor example, type FF for all output high\n\r");
164  u_value=maxim_get_hex();
165  u_value=(u_value<<8)+u_config;
166  u_fault=maxim_set_output(u_value);
167  u_fault>>=8;
168  printf("\n\n\rFault status byte = 0x%2.0X",u_fault);;
170  n_menu_state = MAIN_MENU;
171  break;
172 
173  default:
174  printf("\n\rInvalid Keypress, please try again\r\n");
176  n_menu_state = MAIN_MENU;
177  break;
178  }
179  }
180 }
181 
182 #ifdef USE_FULL_ASSERT
183 
191 void assert_failed(uint8_t* file, uint32_t line)
192 {
193  /* User can add his own implementation to report the file name and line number,
194  ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
195 
196  /* Infinite loop */
197  while (1)
198  {
199  }
200 }
201 
202 #endif
203 
212 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/