Subversion Repositories group.electronics

Rev

Rev 134 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 134 Rev 139
Line 60... Line 60...
60
 * Use like:
60
 * Use like:
61
 * 	uint8_t[10] values; itobcd(ui32num, values);
61
 * 	uint8_t[10] values; itobcd(ui32num, values);
62
 * 	values will be an array with BCD digits
62
 * 	values will be an array with BCD digits
63
 * 	returned value will be how many digits used
63
 * 	returned value will be how many digits used
64
 */
64
 */
65
uint8_t itobcd(uint32_t val, uint8_t *result) {
65
uint8_t itobcd32(uint32_t val, uint8_t *result) {
66
  char BCD_text[10]; // max 10 digits on uint32
66
  char BCD_text[10]; // max 10 digits on uint32
67
  uint8_t i = 0;
67
  uint8_t i = 0;
68
 
68
 
69
  itoa(val, BCD_text, 10);
69
  itoa(val, BCD_text, 10);
70
  while(BCD_text[i]) {
70
  while(BCD_text[i]) {
71
    result[i] = BCD_text[i]-'0';
71
    result[i] = BCD_text[i]-'0';
-
 
72
    i++;
-
 
73
  }
-
 
74
  return i;
-
 
75
}
-
 
76
 
-
 
77
/*
-
 
78
 * Convert from a uint16 to BCD
-
 
79
 * Use like:
-
 
80
 * 	uint8_t[5] values; itobcd(ui16num, values);
-
 
81
 * 	values will be an array with BCD digits
-
 
82
 * 	returned value will be how many digits used
-
 
83
 */
-
 
84
uint8_t itobcd16(uint16_t val, uint8_t *result) {
-
 
85
  char BCD_text[6]; // max 10 digits on uint32
-
 
86
  uint8_t i = 0;
-
 
87
 
-
 
88
  itoa(val, BCD_text, 10);
-
 
89
  while(BCD_text[i]) {
-
 
90
    result[i] = BCD_text[i]-'0';
-
 
91
    i++;
-
 
92
  }
-
 
93
  return i;
-
 
94
}
-
 
95
 
-
 
96
/*
-
 
97
 * Convert from a uint8 to BCD
-
 
98
 * Use like:
-
 
99
 * 	uint8_t[3] values; itobcd(ui8num, values);
-
 
100
 * 	values will be an array with BCD digits
-
 
101
 * 	returned value will be how many digits used
-
 
102
 */
-
 
103
uint8_t itobcd8(uint8_t val, uint8_t *result) {
-
 
104
  char BCD_text[3]; // max 10 digits on uint32
-
 
105
  uint8_t i = 0;
-
 
106
 
-
 
107
  itoa(val, BCD_text, 10);
-
 
108
  while(BCD_text[i]) {
-
 
109
    result[i] = BCD_text[i]-'0';
72
    i++;
110
    i++;
73
  }
111
  }
74
  return i;
112
  return i;
75
}
113
}
76
 
114