hsk_libs-dev  163:b63ae088cc97
High Speed Karlsruhe XC878 library collection
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
hsk_icm7228.h
Go to the documentation of this file.
1 /** \file
2  * HSK ICM7228 8-Digit LED Display Decoder Driver generator
3  *
4  * This file is a code generating facility, that offers preprocessor macros
5  * that produce code for the Intersil ICM7228 display decoder.
6  *
7  * Generating code in this fashion avoids the hard coding of I/O registers
8  * and bits and even allows the use of multiple ICM7228 ICs.
9  *
10  * @see Intersil ICM7228 Data Sheet: <a href="contrib/ICM7228.pdf">ICM7228.pdf</a>
11  * @author kami
12  */
13 
14 #ifndef _HSK_ICM7228_H_
15 #define _HSK_ICM7228_H_
16 
17 #include <string.h> /* memset() */
18 
19 /**
20  * Generate an ICM7228 driver instance.
21  *
22  * This creates functions to use a connect ICM7228 IC.
23  * - void <prefix>_init(void)
24  * - Initialize the buffer and I/O register bits
25  * - void <prefix>_refresh(void)
26  * - Commit buffered data to the 7 segment displays
27  * - void <prefix>_writeString(char * str, ubyte pos, ubyte len)
28  * - Wrapper around hsk_icm7228_writeString()
29  * - void <prefix>_writeDec(uword value, char power, ubyte pos, ubyte len)
30  * - Wrapper around hsk_icm7228_writeDec()
31  * - void <prefix>_writeHex(uword value, char power, ubyte pos, ubyte len)
32  * - Wrapper around hsk_icm7228_writeHex()
33  *
34  * @param prefix
35  * A prefix for the names of generated functions
36  * @param regData
37  * The register that is connected to the data input
38  * @param regMode
39  * The register that is connected to the mode pin
40  * @param bitMode
41  * The bit of the regMode register that is connected to the mode pin
42  * @param regWrite
43  * The register that is connected to the write pin
44  * @param bitWrite
45  * The bit of the regWrite register that is connected to the write pin
46  */
47 #define ICM7228_FACTORY(prefix, regData, regMode, bitMode, regWrite, bitWrite) \
48  \
49  /**
50  * Buffer for display driver at I/O port regData.
51  *
52  * @see ICM7228_FACTORY
53  */\
54  ubyte xdata prefix##_buffer[8]; \
55  \
56  /**
57  * Set up buffer and ports for display driver at I/O port regData.
58  *
59  * @see ICM7228_FACTORY
60  */\
61  void prefix##_init(void) { \
62  memset(prefix##_buffer, 0, sizeof(prefix##_buffer)); \
63  \
64  regMode##_DIR |= 1 << bitMode; \
65  regWrite##_DIR |= 1 << bitWrite; \
66  regData##_DIR = -1; \
67  } \
68  \
69  /**
70  * Reflesh displays at I/O port regData with the buffered data.
71  *
72  * @see ICM7228_FACTORY
73  */\
74  void prefix##_refresh(void) { \
75  ubyte i; \
76  \
77  /* Select write to control register. */ \
78  regMode##_DATA |= 1 << bitMode; \
79  \
80  /* Write to control register. */ \
81  regData##_DATA = 0xB0; /* Control Word */ \
82  regWrite##_DATA &= ~(1 << bitWrite); \
83  regWrite##_DATA |= 1 << bitWrite; \
84  \
85  /* Select write to display ram. */ \
86  regMode##_DATA &= ~(1 << bitMode); \
87  \
88  for (i = 0; i < 8; i++) { \
89  regData##_DATA = prefix##_buffer[i]; \
90  regWrite##_DATA &= ~(1 << bitWrite); \
91  regWrite##_DATA |= 1 << bitWrite; \
92  } \
93  } \
94  \
95  /**
96  * Write an ASCII encoded string into \ref prefix##_buffer.
97  *
98  * @param str
99  * The buffer to read the ASCII string from
100  * @param pos
101  * The position in the buffer to write the encoded string to
102  * @param len
103  * The target length of the encoded string
104  * @see ICM7228_FACTORY
105  * @see hsk_icm7228_writeString
106  */\
107  void prefix##_writeString(const char * const str, \
108  const ubyte pos, const ubyte len) { \
109  hsk_icm7228_writeString(prefix##_buffer, str, pos, len); \
110  } \
111  \
112  /**
113  * Write a decimal number into \ref prefix##_buffer.
114  *
115  * @param value
116  * The number to encode
117  * @param power
118  * The 10 base power of the number to encode
119  * @param pos
120  * The target position in the buffer
121  * @param len
122  * The number of digits available to encode the number
123  * @see ICM7228_FACTORY
124  * @see hsk_icm7228_writeDec
125  */\
126  void prefix##_writeDec(const uword value, const char power, \
127  const ubyte pos, const ubyte len) {\
128  hsk_icm7228_writeDec(prefix##_buffer, value, power, pos, len); \
129  } \
130  \
131  /**
132  * Write a hexadecimal number into \ref prefix##_buffer.
133  *
134  * @param value
135  * The number to encode
136  * @param power
137  * The 16 base power of the number to encode
138  * @param pos
139  * The target position in the buffer
140  * @param len
141  * The number of digits available to encode the number
142  * @see ICM7228_FACTORY
143  * @see hsk_icm7228_writeHex
144  */\
145  void prefix##_writeHex(const uword value, const char power, \
146  const ubyte pos, const ubyte len) {\
147  hsk_icm7228_writeHex(prefix##_buffer, value, power, pos, len); \
148  } \
149  \
150  /**
151  * Illuminate a number of segments in \ref prefix##_buffer.
152  * @param segments
153  * The number of segments to illuminate
154  * @param pos
155  * The target position in the buffer
156  * @param len
157  * The number of digits available to encode the number
158  * @see ICM7228_FACTORY
159  * @see hsk_icm7228_illuminate
160  */\
161  void prefix##_illuminate(const ubyte segments, const ubyte pos, \
162  const ubyte len) {\
163  hsk_icm7228_illuminate(prefix##_buffer, segments, pos, len); \
164  } \
165 
166 /**
167  * Convert an ASCII string to 7 segment encoding and store it in an xdata
168  * buffer.
169  *
170  * This function is usually invoked through the <prefix>_writeString()
171  * function created by ICM7228_FACTORY.
172  *
173  * The function will write into the buffer until it has been filled with len
174  * characters or it encounters a 0 character reading from str.
175  * If the character '.' is encountered it is merged with the previous
176  * character, unless that character is a '.' itself. Thus a single dot does
177  * not use additional buffer space. The 7 character string "foo ..." would
178  * result in 6 encoded bytes. Thus the proper len value for that string would
179  * be 6.
180  *
181  * @param buffer
182  * The target buffer for the encoded string
183  * @param str
184  * The buffer to read the ASCII string from
185  * @param pos
186  * The position in the buffer to write the encoded string to
187  * @param len
188  * The target length of the encoded string
189  */
190 void hsk_icm7228_writeString(ubyte xdata * const buffer, \
191  const char * str, ubyte pos, ubyte len);
192 
193 /**
194  * Write a 7 segment encoded, right aligned decimal number into an xdata
195  * buffer.
196  *
197  * The power parameter controlls the placing of the '.' by 10 to the power.
198  * E.g. value = 12, power = -1 and len = 3 would result in the encoding of
199  * " 1.2". If power = 0, no dot is drawn. If the power is positive (typically
200  * 1), the resulting string would be filled with '0' characters.
201  * I.e. the previous example with power = 1 would result in an encoding of
202  * "012".
203  *
204  * @param buffer
205  * The target buffer for the encoded string
206  * @param value
207  * The number to encode
208  * @param power
209  * The 10 base power of the number to encode
210  * @param pos
211  * The target position in the buffer
212  * @param len
213  * The number of digits available to encode the number
214  */
215 void hsk_icm7228_writeDec(ubyte xdata * const buffer, uword value,
216  char power, const ubyte pos, ubyte len);
217 
218 /**
219  * Write a 7 segment encoded, right aligned hexadecimal number into an xdata
220  * buffer.
221  *
222  * The power parameter controlls the placing of the '.' by 16 to the power.
223  * E.g. value = 0x1A, power = -1 and len = 3 would result in the encoding of
224  * " 1.A". If power = 0, no dot is drawn. If the power is positive (typically
225  * 1), the resulting string would be filled with '0' characters.
226  * I.e. the previous example with power = 1 would result in an encoding of
227  * "01A".
228  *
229  * @param buffer
230  * The target buffer for the encoded string
231  * @param value
232  * The number to encode
233  * @param power
234  * The 16 base power of the number to encode
235  * @param pos
236  * The target position in the buffer
237  * @param len
238  * The number of digits available to encode the number
239  */
240 void hsk_icm7228_writeHex(ubyte xdata * const buffer, uword value,
241  char power, const ubyte pos, ubyte len);
242 
243 /**
244  * Illumante the given number of segments.
245  *
246  * @param buffer
247  * The target buffer for the encoded string
248  * @param segments
249  * The number of segments to illuminate
250  * @param pos
251  * The target position in the buffer
252  * @param len
253  * The number of digits available to encode the number
254  */
255 void hsk_icm7228_illuminate(ubyte xdata * const buffer,
256  ubyte segments, ubyte pos, ubyte len);
257 
258 #endif /* _HSK_ICM7228_H_ */
259