MAXREFDES63# Code Documentation  V01.00
8-Channel Digital Output MicroPLC
 All Files Functions Variables Macros Pages
utilities.c
Go to the documentation of this file.
1 
30 /*
31 * Copyright (C) 2012 Maxim Integrated Products, Inc., All Rights Reserved.
32 *
33 * Permission is hereby granted, free of charge, to any person obtaining a
34 * copy of this software and associated documentation files (the "Software"),
35 * to deal in the Software without reps_striction, including without limitation
36 * the rights to use, copy, modify, merge, publish, dips_stribute, sublicense,
37 * and/or sell copies of the Software, and to permit persons to whom the
38 * Software is furnished to do so, subject to the following conditions:
39 *
40 * The above copyright notice and this permission notice shall be included
41 * in all copies or substantial portions of the Software.
42 *
43 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
44 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46 * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
47 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
48 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
49 * OTHER DEALINGS IN THE SOFTWARE.
50 *
51 * Except as contained in this notice, the name of Maxim Integrated Products
52 * shall not be used except as stated in the Maxim Integrated Products
53 * Branding Policy.
54 *
55 * The mere transfer of this software does not imply any licenses
56 * of trade secrets, proprietary technology, copyrights, patents,
57 * trademarks, maskwork rights, or any other form of intellectual
58 * property whatsoever. Maxim Integrated Products retains all ownership rights.
59 *
60 ***************************************************************************/
61 
62 #include "utilities.h"
63 #include "stm32f10x.h"
64 #include "stdio.h"
65 #include "stdlib.h"
66 
67 void maxim_delay(uint32_t un_delay)
75 {
76  uint32_t un_count;
77  for(un_count=0;un_count<un_delay;un_count++);
78 }
79 
80 int maxim_get_hex(void)
88 {
89  char s_string[20];
90  char ch_char;
91  int i=0;
92 
93  printf(">> 0x");
94  for(i=0; i<20 && ch_char!=0x0D; i++)
95  {
96  ch_char=getchar();
97  printf("%c",ch_char);
98  s_string[i]=ch_char;
99  }
100  s_string[i]='\0';
101  return maxim_htoi(s_string);
102 }
103 
104 int maxim_htoi(char *ps_str)
112 {
113  int n_ret=0;
114  int n_end=0;
115  int i;
116  for(i=0;i<100;i++)
117  {
118  switch(ps_str[i])
119  {
120  case '0': n_ret=n_ret<<4; n_ret=n_ret+0; break;
121  case '1': n_ret=n_ret<<4; n_ret=n_ret+1; break;
122  case '2': n_ret=n_ret<<4; n_ret=n_ret+2; break;
123  case '3': n_ret=n_ret<<4; n_ret=n_ret+3; break;
124  case '4': n_ret=n_ret<<4; n_ret=n_ret+4; break;
125  case '5': n_ret=n_ret<<4; n_ret=n_ret+5; break;
126  case '6': n_ret=n_ret<<4; n_ret=n_ret+6; break;
127  case '7': n_ret=n_ret<<4; n_ret=n_ret+7; break;
128  case '8': n_ret=n_ret<<4; n_ret=n_ret+8; break;
129  case '9': n_ret=n_ret<<4; n_ret=n_ret+9; break;
130  case 'a': n_ret=n_ret<<4; n_ret=n_ret+10; break;
131  case 'b': n_ret=n_ret<<4; n_ret=n_ret+11; break;
132  case 'c': n_ret=n_ret<<4; n_ret=n_ret+12; break;
133  case 'd': n_ret=n_ret<<4; n_ret=n_ret+13; break;
134  case 'e': n_ret=n_ret<<4; n_ret=n_ret+14; break;
135  case 'f': n_ret=n_ret<<4; n_ret=n_ret+15; break;
136  case 'A': n_ret=n_ret<<4; n_ret=n_ret+10; break;
137  case 'B': n_ret=n_ret<<4; n_ret=n_ret+11; break;
138  case 'C': n_ret=n_ret<<4; n_ret=n_ret+12; break;
139  case 'D': n_ret=n_ret<<4; n_ret=n_ret+13; break;
140  case 'E': n_ret=n_ret<<4; n_ret=n_ret+14; break;
141  case 'F': n_ret=n_ret<<4; n_ret=n_ret+15; break;
142  default: n_end=1; break;
143  }
144  if(n_end==1)
145  {
146  break;
147  }
148  }
149  return n_ret;
150 }