00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include "mscbemb.h"
00018
00019 #ifdef _HUMSEN_
00020 #include "Devices/Humidity_sensor.h"
00021 #define humsense 1
00022 #endif
00023
00024 #ifdef _ADT7486A_
00025 #include "Devices/ADT7486A_tsensor.h"
00026 #endif
00027
00028 float avge(float temperature, char chan, int idx);
00029
00030
00031 extern unsigned long _systime;
00032
00033 char code node_name[] = "GENERIC310_SST";
00034 char idata svn_rev_code[] = "$Rev: 1096 $";
00035
00036
00037 #define SST_LINE 1
00038
00039
00040 unsigned char idata _n_sub_addr = 1;
00041 extern SYS_INFO sys_info;
00042 unsigned char ADT7486A_addrArray[] = {0x48, 0x4a};
00043
00044 #ifdef _HUMSEN_
00045
00046 unsigned long xdata currentTime=0;
00047 unsigned char xdata status, i1=0, i2=0, i3=0, i4=0;
00048 float xdata humidity, htemperature, atemp[4][30];
00049 unsigned int xdata rSHTtemp1, rSHThumi1, tcnt[4];
00050 unsigned char xdata FCSorig1, FCSdevi1;
00051 #endif
00052
00053
00054
00055
00056
00057 struct
00058 {
00059 unsigned char status;
00060 unsigned char error;
00061 float internal[2];
00062 char ncount;
00063 float temp[8];
00064 float SHTtemp;
00065 float SHThumid;
00066 unsigned int rSHTtemp;
00067 unsigned int rSHThumid;
00068 unsigned char FCSorig;
00069 unsigned char FCSdevi;
00070 float ext01off, ext02off, ext11off, ext12off;
00071 } xdata user_data;
00072
00073 MSCB_INFO_VAR code vars[] = {
00074 1, UNIT_BYTE, 0, 0, 0, "Status", &user_data.status,
00075 1, UNIT_BYTE, 0, 0, 0, "ERROR", &user_data.error,
00076 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "IntTemp1", &user_data.internal[0],
00077 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "IntTemp2", &user_data.internal[1],
00078
00079 1, UNIT_BYTE, 0, 0, 0, "ncount", &user_data.ncount,
00080
00081 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp1", &user_data.temp[0],
00082 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp2", &user_data.temp[1],
00083 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp3", &user_data.temp[2],
00084 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp4", &user_data.temp[3],
00085
00086
00087 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "AvgTemp1", &user_data.temp[4],
00088 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "AvgTemp2", &user_data.temp[5],
00089 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "AvgTemp3", &user_data.temp[6],
00090 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "AvgTemp4", &user_data.temp[7],
00091 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "SHTtemp", &user_data.SHTtemp,
00092 4, UNIT_PERCENT, 0, 0, MSCBF_FLOAT, "RHumid", &user_data.SHThumid,
00093
00094 2, UNIT_BYTE, 0, 0, 0, "rSHTtemp", &user_data.rSHTtemp,
00095 2, UNIT_BYTE, 0, 0, 0, "rSHThumi", &user_data.rSHThumid,
00096 1, UNIT_BYTE, 0, 0, 0, "FCSorig", &user_data.FCSorig,
00097 1, UNIT_BYTE, 0, 0, 0, "FCSdevi", &user_data.FCSdevi,
00098 4, UNIT_BYTE, 0, 0, MSCBF_FLOAT, "ext01off", &user_data.ext01off,
00099 4, UNIT_BYTE, 0, 0, MSCBF_FLOAT, "ext02off", &user_data.ext02off,
00100 4, UNIT_BYTE, 0, 0, MSCBF_FLOAT, "ext11off", &user_data.ext11off,
00101 4, UNIT_BYTE, 0, 0, MSCBF_FLOAT, "ext12off", &user_data.ext12off,
00102 0
00103 };
00104
00105 MSCB_INFO_VAR *variables = vars;
00106
00107 char flag = 0;
00108
00109
00110
00111
00112
00113
00114
00115
00116 #define P1_DATA P1
00117 sbit LED_GREEN = LED_1;
00118 sbit LED_RED = LED_0;
00119 sbit SST = MSCB_SST1;
00120
00121 sbit P1_0 = P1 ^ 0;
00122 sbit P1_1 = P1 ^ 1;
00123 sbit P1_2 = P1 ^ 2;
00124 sbit RH_VCC = P1 ^ 2;
00125 sbit P1_3 = P1 ^ 3;
00126 sbit P1_4 = P1 ^ 4;
00127 sbit RH_GND = P1 ^ 4;
00128 sbit P1_5 = P1 ^ 5;
00129 sbit P1_6 = P1 ^ 6;
00130 sbit P1_7 = P1 ^ 7;
00131
00132 sbit P2_0 = P2 ^ 0;
00133 sbit P2_1 = P2 ^ 1;
00134 sbit P2_2 = P2 ^ 2;
00135 sbit P2_3 = P2 ^ 3;
00136 sbit P2_4 = P2 ^ 4;
00137 sbit P2_5 = P2 ^ 5;
00138 sbit P0_1 = P0 ^ 1;
00139 sbit P0_2 = P0 ^ 2;
00140
00141 sbit P1_OEn = P0 ^ 7;
00142 sbit P2_OEn = P3 ^ 4;
00143
00144
00145 void user_write(unsigned char index) reentrant;
00146
00147
00148
00149 void user_init(unsigned char init)
00150 {
00151 idata char i, j;
00152 char xdata add;
00153
00154
00155 if (init) {
00156 user_data.status = 0;
00157 user_data.error = 0x0;
00158 user_data.SHTtemp = 0;
00159 user_data.SHThumid = 0;
00160 user_data.rSHTtemp = 0;
00161 user_data.rSHThumid = 0;
00162 user_data.FCSorig = 0;
00163 user_data.FCSdevi = 0;
00164 user_data.ext01off =0;
00165 user_data.ext02off =0;
00166 user_data.ext11off =0;
00167 user_data.ext12off =0;
00168 user_data.ncount = 10;
00169
00170
00171 }
00172
00173
00174 for (i=0;i<4;i++) {
00175 if (svn_rev_code[6+i] < 48) {
00176 svn_rev_code[6+i] = '0';
00177 }
00178 }
00179 sys_info.svn_revision = (svn_rev_code[6]-'0')*1000+
00180 (svn_rev_code[7]-'0')*100+
00181 (svn_rev_code[8]-'0')*10+
00182 (svn_rev_code[9]-'0');
00183 add = cur_sub_addr();
00184
00185
00186 P0MDIN = 0xFF;
00187 P1MDIN = 0xFF;
00188 P2MDIN = 0x3F;
00189 P3MDIN = 0xFF;
00190
00191
00192 P0MDOUT = 0x90;
00193
00194 P2MDOUT = 0x3F;
00195 P3MDOUT = 0x18;
00196
00197
00198 REF0CN = 0x00;
00199
00200
00201 P1_OEn = 0;
00202 P2_OEn = 0;
00203
00204
00205 CPT1CN = 0x80;
00206
00207 CPT1MX = 0x33;
00208
00209
00210
00211 CPT1MD = 0x02;
00212
00213
00214
00215
00216 P2MDOUT &= 0x3F;
00217 P2MDIN &= 0x3F;
00218
00219 #ifdef _ADT7486A_
00220
00221
00222 ADT7486A_Init(SST_LINE);
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 if (user_data.ncount > 30) user_data.ncount = 30;
00243 for (j=0;j<4;j++)
00244 for (i=0;i<30;i++) atemp[j][i] = -500;
00245 #endif
00246
00247
00248
00249
00250 #ifdef _HUMSEN_
00251 P1MDOUT |= 0x15;
00252 RH_VCC = 1;
00253 RH_GND = 0;
00254
00255 HumiSensor_Init(humsense);
00256
00257 user_data.SHTtemp = 0;
00258 user_data.SHThumid = 0;
00259 #endif
00260
00261 memset (&user_data.internal[0], 0, sizeof(user_data.internal));
00262 memset (&user_data.temp[0], 0, sizeof(user_data.temp));
00263 LED_RED = 0;
00264 }
00265
00266
00267 void user_write(unsigned char index) reentrant
00268 {
00269 led_blink(0, 2, 250);
00270 if(index == 0) flag = 1;
00271
00272 return;
00273 }
00274
00275
00276
00277 unsigned char user_read(unsigned char index)
00278 {
00279 if(index);
00280
00281 return 0;
00282 }
00283
00284
00285
00286 unsigned char user_func(unsigned char *data_in, unsigned char *data_out)
00287 {
00288
00289 data_out[0] = data_in[0];
00290 data_out[1] = data_in[1];
00291 return 2;
00292 }
00293
00294
00295 float avge(float temperature, char chan, int idx) {
00296 int l, divider;
00297 float sumtemp;
00298
00299 atemp[chan][idx++] = temperature;
00300 sumtemp =0;
00301 for (divider=0,l=0;l<user_data.ncount;l++) {
00302 if (atemp[chan][l] != -500.f) {
00303 sumtemp += atemp[chan][l];
00304 divider++;
00305 }
00306 }
00307 return (sumtemp / divider);
00308 }
00309
00310
00311 void user_loop(void)
00312 {
00313 char i;
00314 float xdata humidity, temperature, avgetemp;
00315 unsigned char status;
00316
00317 user_data.status += 1;
00318
00319 #ifdef _ADT7486A_
00320
00321
00322 for (i=0;i<2;i++) {
00323 if(!ADT7486A_Cmd(ADT7486A_addrArray[i], GetIntTemp, SST_LINE, &temperature)){
00324 DISABLE_INTERRUPTS;
00325 user_data.internal[i] = temperature;
00326 ENABLE_INTERRUPTS;
00327 }
00328 }
00329
00330 if(!ADT7486A_Cmd(ADT7486A_addrArray[0], GetExt1Temp, SST_LINE, &temperature)){
00331 i1 %= user_data.ncount;
00332 avgetemp = avge(temperature, 0, i1);
00333 i1++;
00334 DISABLE_INTERRUPTS;
00335 user_data.temp[0] = temperature + user_data.ext01off;
00336 user_data.temp[0+4] = avgetemp;
00337 ENABLE_INTERRUPTS;
00338 }
00339 if(!ADT7486A_Cmd(ADT7486A_addrArray[0], GetExt2Temp, SST_LINE, &temperature)){
00340 i2 %= user_data.ncount; avgetemp = avge(temperature, 1, i2); i2++;
00341 DISABLE_INTERRUPTS;
00342 user_data.temp[1] = temperature + user_data.ext02off;
00343 user_data.temp[1+4] = avgetemp;
00344 ENABLE_INTERRUPTS;
00345 }
00346 if(!ADT7486A_Cmd(ADT7486A_addrArray[1], GetExt1Temp, SST_LINE, &temperature)){
00347 i3 %= user_data.ncount; avgetemp = avge(temperature, 2, i3); i3++;
00348 DISABLE_INTERRUPTS;
00349 user_data.temp[2] = temperature + user_data.ext11off;
00350 user_data.temp[2+4] = avgetemp;
00351 ENABLE_INTERRUPTS;
00352 }
00353 if(!ADT7486A_Cmd(ADT7486A_addrArray[1], GetExt2Temp, SST_LINE, &temperature)){
00354 i4 %= user_data.ncount; avgetemp = avge(temperature, 3, i4); i4++;
00355 DISABLE_INTERRUPTS;
00356 user_data.temp[3] = temperature + user_data.ext12off;
00357 user_data.temp[3+4] = avgetemp;
00358 ENABLE_INTERRUPTS;
00359 }
00360 #endif
00361
00362 #ifdef _HUMSEN_
00363
00364
00365
00366 if ((uptime() - currentTime) > 1)
00367 {
00368 status = HumidSensor_Cmd (&rSHThumi1
00369 ,&rSHTtemp1
00370 ,&humidity
00371 ,&htemperature
00372 ,&FCSorig1
00373 ,&FCSdevi1
00374 ,humsense);
00375 if (status == DONE){
00376 DISABLE_INTERRUPTS;
00377 user_data.SHThumid = humidity;
00378 user_data.SHTtemp = htemperature;
00379 user_data.FCSorig = FCSorig1;
00380 user_data.FCSdevi = FCSdevi1;
00381 ENABLE_INTERRUPTS;
00382 }
00383 currentTime = uptime();
00384 }
00385 #endif
00386 delay_ms(200);
00387 led_blink(1, 1, 100);
00388 }