Rev Author Line No. Line
1709 kakl 1 ///////////////////////////////////////////////////////////////////////////
2 //// Dallas Touch Driver ////
3 //// ////
4 //// ////
5 //// data = touch_read_bit() Reads one bit from a touch device ////
6 //// ////
7 //// data = touch_read_BYTE() Reads one byte from a touch device. ////
8 //// ////
9 //// ok = touch_write_bit(data) Writes one bit to a touch device ////
10 //// and returns true if all went ok. ////
11 //// A false indicates a collision with ////
12 //// another device. ////
13 //// ////
14 //// ok = touch_write_byte(data) Writes one byte to a touch device ////
15 //// and returns true if all went ok. ////
16 //// A false indicates a collision with ////
17 //// another device. ////
18 //// ////
19 //// present = touch_present() Issues a reset and returns true ////
20 //// if the touch device is there. ////
21 //// ////
22 //// reset_pulse() Issues a reset and waits for a ////
23 //// present pulse. ////
24 //// ////
25 ///////////////////////////////////////////////////////////////////////////
26 //// (C) Copyright 1996,2010 Custom Computer Services ////
27 //// This source code may only be used by licensed users of the CCS C ////
28 //// compiler. This source code may only be distributed to other ////
29 //// licensed users of the CCS C compiler. No other use, reproduction ////
30 //// or distribution is permitted without written permission. ////
31 //// Derivative programs created using this software in object code ////
32 //// form are not restricted in any way. ////
33 ///////////////////////////////////////////////////////////////////////////
34  
35 #ifndef TOUCH_C
36 #define TOUCH_C
37  
38 #ifndef TOUCH_PIN
39 #define TOUCH_PIN PIN_B0
40 #endif
41  
42 #define TOUCH_PIN_LOW() output_drive(TOUCH_PIN); output_low(TOUCH_PIN)
43 #define TOUCH_PIN_HIGH() output_drive(TOUCH_PIN); output_high(TOUCH_PIN)
44 #define TOUCH_PIN_FLOAT() output_float(TOUCH_PIN)
45 #define TOUCH_PIN_READ() input_state(TOUCH_PIN)
46  
47 /////////////////////////////
48 //// ////
49 //// Function Prototypes ////
50 //// ////
51 /////////////////////////////
52  
53 /*
54 int1 touch_read_bit()
55 This will read back a bit from the DS1993
56 PARAMS: none
57 RETURNS: A bit from the DS1993
58 */
59 int1 touch_read_bit();
60  
61 /*
62 BYTE touch_read_byte()
63 This will read back a byte from the DS1993
64 PARAMS: none
65 RETURNS: A byte from the DS1993
66 */
67 BYTE touch_read_byte();
68  
69 /*
70 BOOLEAN touch_write_bit(int1 data)
71 This will write a bit to the DS1993
72 PARAMS: The bit to write
73 RETURNS: True if completed successfully, false if otherwise
74 */
75 BOOLEAN touch_write_bit(int1 data);
76  
77 /*
78 BOOLEAN touch_write_byte(BYTE data)
79 This will write a byte to the DS1993
80 PARAMS: The byte to write
81 RETURNS: True if completed successfully, false if otherwise
82 */
83 BOOLEAN touch_write_byte(BYTE data);
84  
85 /*
86 BOOLEAN touch_present()
87 This will evaluate whether or not there is a touch present on the DS1993
88 PARAMS: none
89 RETURNS: True if a touch is present, false if otherwise
90 */
91 BOOLEAN touch_present();
92  
93 /*
94 void reset_pulse()
95 This will send the DS1993 a reset pulse
96 PARAMS: none
97 RETURNS: none
98 */
99 void reset_pulse();
100  
101 //////////////////////////////////
102 //// ////
103 //// Function Implementations ////
104 //// ////
105 //////////////////////////////////
106  
107 /*
108 int1 touch_read_bit()
109 This will read back a bit from the DS1993
110 PARAMS: none
111 RETURNS: A bit from the DS1993
112 */
113 int1 touch_read_bit()
114 {
115 int1 data;
116  
117 TOUCH_PIN_LOW();
118 delay_us(14);
119 TOUCH_PIN_FLOAT();
120 delay_us(5);
121 data = TOUCH_PIN_READ();
122 delay_us(100);
123 toggle_dome();
124  
125 return data;
126 }
127  
128 /*
129 BYTE touch_read_byte()
130 This will read back a byte from the DS1993
131 PARAMS: none
132 RETURNS: A byte from the DS1993
133 */
134 BYTE touch_read_byte()
135 {
136 BYTE i,data;
137  
138 for(i=1; i <= 8; ++i)
139 shift_right(&data, 1, touch_read_bit());
140  
141 return data;
142 }
143  
144 /*
145 BOOLEAN touch_write_bit(int1 data)
146 This will write a bit to the DS1993
147 PARAMS: The bit to write
148 RETURNS: True if completed successfully, false if otherwise
149 */
150 BOOLEAN touch_write_bit(int1 data)
151 {
152 TOUCH_PIN_LOW();
153 delay_us(10);
154 if(data)
155 {
156 TOUCH_PIN_HIGH();
157 delay_us(10);
158 if(!TOUCH_PIN_READ())
159 return FALSE;
160 }
161 else
162 {
163 TOUCH_PIN_LOW();
164 delay_us(10);
165 if(TOUCH_PIN_READ())
166 return FALSE;
167 }
168 delay_us(50);
169 TOUCH_PIN_HIGH();
170 toggle_dome();
171 delay_us(50);
172 return TRUE;
173 }
174  
175 /*
176 BOOLEAN touch_write_byte(BYTE data)
177 This will write a byte to the DS1993
178 PARAMS: The byte to write
179 RETURNS: True if completed successfully, false if otherwise
180 */
181 BOOLEAN touch_write_byte(BYTE data)
182 {
183 BYTE i;
184  
185 for(i=1; i<=8; ++i)
186 if(!touch_write_bit(shift_right(&data, 1, 0)))
187 return FALSE;
188  
189 return TRUE;
190 }
191  
192 /*
193 BOOLEAN touch_present()
194 This will evaluate whether or not there is a touch present on the DS1993
195 PARAMS: none
196 RETURNS: True if a touch is present, false if otherwise
197 */
198 BOOLEAN touch_present()
199 {
200 BOOLEAN present;
201 TOUCH_PIN_LOW();
202 toggle_dome();
203 delay_us(100);
204 toggle_dome();
205 delay_us(100);
206 toggle_dome();
207 delay_us(100);
208 toggle_dome();
209 delay_us(100);
210 toggle_dome();
211 delay_us(100);
212 toggle_dome();
213 TOUCH_PIN_FLOAT();
214 delay_us(5);
215  
216 if(!TOUCH_PIN_READ())
217 return FALSE;
218  
219 delay_us(65);
220 toggle_dome();
221 present = !TOUCH_PIN_READ();
222 toggle_dome(); // Puvodne pauza 240us
223 delay_us(100);
224 toggle_dome();
225 delay_us(100);
226 toggle_dome();
227 delay_us(30);
228 toggle_dome();
229 return present;
230 }
231  
232 /*
233 void reset_pulse()
234 This will send the DS1993 a reset pulse
235 PARAMS: none
236 RETURNS: none
237 */
238 void reset_pulse()
239 {
240 TOUCH_PIN_LOW();
241 toggle_dome();
242 delay_us(100);
243 toggle_dome();
244 delay_us(100);
245 toggle_dome();
246 delay_us(100);
247 toggle_dome();
248 delay_us(100);
249 toggle_dome();
250 delay_us(100);
251 toggle_dome();
252 TOUCH_PIN_FLOAT();
253 delay_us(5);
254 while(!touch_present());
255 }
256  
257  
258 #endif