Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00057
00058
00059
00060 #include <stdlib.h>
00061 #include "includes/mTouchCVD.h"
00062
00063 #if defined(CVD_DEBUG) && (CVD_DEBUG == 1)
00064
00065
00066
00068
00070 void mTouchCVD_Comm_Init(void);
00071
00073
00075 void send_Data(void);
00076
00078
00080 void put_Char (unsigned char);
00081 void str_Int (unsigned int);
00082 void str_Char (unsigned char);
00083
00084
00086
00087
00088
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00105 void mTouchCVD_Comm_Init(void)
00106 {
00107
00108 CVD_DEBUG_COMM_INIT();
00109 }
00110
00111
00113
00114
00115
00117
00121 void send_Data(void)
00122 {
00123 #if CVD_Software_Revision == 0002
00124
00125
00126 unsigned int btnMsk = 0;
00127 unsigned int bufMsk = 1;
00128 for (unsigned char i = 0; i < CVD_NUMBER_SENSORS; i++)
00129 {
00130 if (CVD_GetButtonState(i) < CVD_PRESSED)
00131 {
00132 btnMsk |= bufMsk;
00133 }
00134 bufMsk <<= 1;
00135 }
00136 btnMsk = ~btnMsk;
00137
00138 str_Int(btnMsk);
00139 #endif
00140
00141
00142 for (unsigned char i = 0; i < CVD_NUMBER_SENSORS; i++)
00143 {
00144 #if defined(CVD_DEBUG_OUTPUT_RAW)
00145 str_Int(CVDGetSensor(i));
00146 #endif
00147 #if defined(CVD_DEBUG_OUTPUT_AVG)
00148 str_Int(Average[i]);
00149 #endif
00150 }
00151
00152
00153 put_Char(0x0D);
00154 put_Char(0x0A);
00155 }
00156
00158
00159
00160
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00179 void str_Int(unsigned int i)
00180 {
00181 unsigned char ctr = 0;
00182
00183 #if defined(CVD_DEBUG_OUTPUT_HEX)
00184
00185
00186 ctr = (unsigned char)(i >> 12);
00187 if (ctr <= 9) { put_Char(ctr+0x30); } else { put_Char(ctr+0x37); }
00188 ctr = (unsigned char)(i >> 8) & 0x0F;
00189 if (ctr <= 9) { put_Char(ctr+0x30); } else { put_Char(ctr+0x37); }
00190 ctr = (unsigned char)(i >> 4) & 0x0F;
00191 if (ctr <= 9) { put_Char(ctr+0x30); } else { put_Char(ctr+0x37); }
00192 ctr = (unsigned char)(i & 0x0F);
00193 if (ctr <= 9) { put_Char(ctr+0x30); } else { put_Char(ctr+0x37); }
00194
00195 #else
00196
00197
00198 while (i >= 10000) { i -= 10000; ctr++; } put_Char(ctr+0x30); ctr=0;
00199 while (i >= 1000) { i -= 1000; ctr++; } put_Char(ctr+0x30); ctr=0;
00200 while (i >= 100) { i -= 100; ctr++; } put_Char(ctr+0x30); ctr=0;
00201 while (i >= 10) { i -= 10; ctr++; } put_Char(ctr+0x30); ctr=0;
00202 while (i >= 1) { i -= 1; ctr++; } put_Char(ctr+0x30);
00203
00204 #endif
00205
00206
00207
00208 put_Char(';');
00209 }
00210
00211
00218 void put_Char(unsigned char Dout)
00219 {
00220 #if defined(CVD_DEBUG_UART_ENABLED)
00221 while(CVD_DEBUG_COMM_TXIF == 0);
00222 CVD_DEBUG_COMM_TXREG = Dout;
00223 #else
00224 #define RS232__RATE CVD_DEBUG_SPEED
00225 #define RS232__PORT CVD_DEBUG_PIN
00226 #if (_XTAL_FREQ == 8000000)
00227 #if (RS232__RATE == 9600)
00228 #define RS232__DELAY 22
00229 #define RS232__DELAYCODE() for (j = RS232__DELAY; j > 0; j--) { NOP(); NOP(); NOP(); NOP(); NOP(); } NOP(); NOP(); NOP(); NOP();
00230 #elif (RS232__RATE == 56700)
00231 #define RS232__DELAY 3
00232 #define RS232__DELAYCODE() for (j = RS232__DELAY; j > 0; j--) { NOP(); NOP(); NOP(); } NOP();
00233 #elif (RS232__RATE == 115200)
00234 #define RS232__DELAY 1
00235 #define RS232__DELAYCODE() NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
00236 #else
00237 #error The chosen RS232 baud rate is not supported. Choose either 9600, 57600, or 115200.
00238 #endif
00239 #elif (_XTAL_FREQ == 4000000)
00240 #if (RS232__RATE == 9600)
00241 #define RS232__DELAY 10
00242 #define RS232__DELAYCODE() for (j = RS232__DELAY; j > 0; j--) { NOP(); NOP(); NOP(); NOP(); NOP(); } NOP(); NOP(); NOP();
00243 #elif (RS232__RATE == 56700)
00244 #define RS232__DELAY 1
00245 #define RS232__DELAYCODE() NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
00246 #elif (RS232__RATE == 115200)
00247 #error 115.2k baud rate is not available with a 4MHz oscillator. Choose 9600 or 57600, or move to a 8MHz oscillator.
00248 #else
00249 #error The chosen RS232 baud rate is not supported. Choose either 9600 or 57600.
00250 #endif
00251 #else
00252 #warning Current clock frequency is not a supported option for this version of RS232 code.
00253 #endif
00254
00255
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00272
00273
00274
00275 RS232__PORT = 0;
00276 if (!(Dout & 0x00)) { NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); }
00277 RS232__DELAYCODE();
00278
00279
00280 if (Dout & 0x01) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00281 if (!(Dout & 0x01)) { NOP(); NOP(); NOP(); NOP(); }
00282 RS232__DELAYCODE();
00283
00284
00285 if (Dout & 0x02) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00286 if (!(Dout & 0x02)) { NOP(); NOP(); NOP(); NOP(); }
00287 RS232__DELAYCODE();
00288
00289
00290 if (Dout & 0x04) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00291 if (!(Dout & 0x04)) { NOP(); NOP(); NOP(); NOP(); }
00292 RS232__DELAYCODE();
00293
00294
00295 if (Dout & 0x08) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00296 if (!(Dout & 0x08)) { NOP(); NOP(); NOP(); NOP(); }
00297 RS232__DELAYCODE();
00298
00299
00300 if (Dout & 0x10) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00301 if (!(Dout & 0x10)) { NOP(); NOP(); NOP(); NOP(); }
00302 RS232__DELAYCODE();
00303
00304
00305 if (Dout & 0x20) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00306 if (!(Dout & 0x20)) { NOP(); NOP(); NOP(); NOP(); }
00307 RS232__DELAYCODE();
00308
00309
00310 if (Dout & 0x40) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00311 if (!(Dout & 0x40)) { NOP(); NOP(); NOP(); NOP(); }
00312 RS232__DELAYCODE();
00313
00314
00315 if (Dout & 0x80) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00316 if (!(Dout & 0x80)) { NOP(); NOP(); NOP(); NOP(); }
00317 RS232__DELAYCODE();
00318
00319
00320
00321
00322 NOP(); NOP();
00323 if (Dout | 0xFF) { RS232__PORT = 1; } else { RS232__PORT = 0; }
00324 if (!(Dout | 0xFF)) { NOP(); NOP(); NOP(); NOP(); }
00325 RS232__DELAYCODE();
00326
00327
00328 RS232__PORT = 1;
00329
00330 #endif
00331 }
00332
00333 #endif