00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <stdio.h>
00013 #include <math.h>
00014 #include "mscbemb.h"
00015 #include "temp36.h"
00016
00017 #ifdef _ADT7486A_
00018 #include "Devices/ADT7486A_tsensor.h"
00019 #endif
00020
00021 #ifdef _ExtEEPROM_
00022 #include "Devices/ExtEEPROM.h"
00023 #endif
00024
00025 #ifdef _HUMSEN_
00026 #include "Devices/Humidity_sensor.h"
00027 #endif
00028
00029 #ifdef _LTC2600_
00030 #include "Devices/LTC2600_dac.h"
00031 #endif
00032
00033 #ifdef _ADC_INTERNAL_
00034 #include "Devices/adc_internal.h"
00035 #endif
00036
00037
00038 unsigned char idata _n_sub_addr = 1;
00039
00040
00041
00042 char code node_name[] = "temp36";
00043 char idata svn_rev_code[] = "$Rev: 1180 $";
00044
00045
00046 bit EEP_CTR_Flag;
00047 bit LTC2600_Flag;
00048 bit REF_Flag;
00049
00050
00051 int xdata * eep_address;
00052 static unsigned char tcounter;
00053 static unsigned char xdata eeprom_flag=CLEAR;
00054 unsigned char xdata eeprom_wstatus, eeprom_rstatus;
00055 unsigned int xdata eeptemp_addr;
00056 unsigned char xdata * eeptemp_source;
00057 unsigned char xdata eep_request;
00058
00059
00060 unsigned char xdata status;
00061 float xdata humidity, htemperature;
00062 unsigned int xdata rSHTtemp1, rSHThumi1, rSHTtemp2, rSHThumi2;
00063 unsigned char xdata FCSorig1, FCSdevi1, FCSorig2, FCSdevi2;
00064
00065
00066 unsigned char xdata cavg=0;
00067 unsigned char idata channel, avgcount, numavg=0;
00068 float xdata average;
00069 float xdata temperature;
00070
00071 #ifdef _LTC2600_
00072
00073 unsigned char xdata DACIndex;
00074 unsigned char xdata LTC2600_LOAD[] = {LTC2600_LOAD_A,LTC2600_LOAD_B
00075 ,LTC2600_LOAD_C,LTC2600_LOAD_D
00076 ,LTC2600_LOAD_E,LTC2600_LOAD_F
00077 ,LTC2600_LOAD_G,LTC2600_LOAD_H};
00078 #endif
00079
00080
00081 extern SYS_INFO sys_info;
00082
00083
00084
00085
00086 MSCB_INFO_VAR code vars[] = {
00087 4, UNIT_BYTE, 0, 0, 0, "SerialN", &user_data.SerialN,
00088 2, UNIT_BYTE, 0, 0, 0, "Error", &user_data.error,
00089 1, UNIT_BYTE, 0, 0, 0, "Control", &user_data.control,
00090 1, UNIT_BYTE, 0, 0, 0, "Status", &user_data.status,
00091 1, UNIT_BYTE, 0, 0, 0, "EEPage", &user_data.eepage,
00092 2, UNIT_BYTE, 0, 0, 0, "Navge", &user_data.navge,
00093 1, UNIT_BYTE, 0, 0, 0, "TE01-08", &user_data.terror[0],
00094 1, UNIT_BYTE, 0, 0, 0, "TE09-16", &user_data.terror[1],
00095 1, UNIT_BYTE, 0, 0, 0, "TE17-24", &user_data.terror[2],
00096 1, UNIT_BYTE, 0, 0, 0, "TE25-32", &user_data.terror[3],
00097 1, UNIT_BYTE, 0, 0, 0, "TE33-36", &user_data.terror[4],
00098 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp01", &user_data.Temp[0],
00099 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp02", &user_data.Temp[1],
00100 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp03", &user_data.Temp[2],
00101 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp04", &user_data.Temp[3],
00102 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp05", &user_data.Temp[4],
00103 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp06", &user_data.Temp[5],
00104 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp07", &user_data.Temp[6],
00105 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp08", &user_data.Temp[7],
00106 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp09", &user_data.Temp[8],
00107 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp10", &user_data.Temp[9],
00108 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp11", &user_data.Temp[10],
00109 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp12", &user_data.Temp[11],
00110 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp13", &user_data.Temp[12],
00111 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp14", &user_data.Temp[13],
00112 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp15", &user_data.Temp[14],
00113 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp16", &user_data.Temp[15],
00114 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp17", &user_data.Temp[16],
00115 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp18", &user_data.Temp[17],
00116 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp19", &user_data.Temp[18],
00117 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp20", &user_data.Temp[19],
00118 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp21", &user_data.Temp[20],
00119 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp22", &user_data.Temp[21],
00120 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp23", &user_data.Temp[22],
00121 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp24", &user_data.Temp[23],
00122 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp25", &user_data.Temp[24],
00123 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp26", &user_data.Temp[25],
00124 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp27", &user_data.Temp[26],
00125 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp28", &user_data.Temp[27],
00126 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp29", &user_data.Temp[28],
00127 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp30", &user_data.Temp[29],
00128 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp31", &user_data.Temp[30],
00129 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp32", &user_data.Temp[31],
00130 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp33", &user_data.Temp[32],
00131 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp34", &user_data.Temp[33],
00132 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp35", &user_data.Temp[34],
00133 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Temp36", &user_data.Temp[35],
00134
00135 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "REF", &user_data.ref ,
00136
00137 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg01", &user_data.AT[0],
00138 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg02", &user_data.AT[1],
00139 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg03", &user_data.AT[2],
00140 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg04", &user_data.AT[3],
00141 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg05", &user_data.AT[4],
00142 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg06", &user_data.AT[5],
00143 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg07", &user_data.AT[6],
00144 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg08", &user_data.AT[7],
00145 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg09", &user_data.AT[8],
00146 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg10", &user_data.AT[9],
00147 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg11", &user_data.AT[10],
00148 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg12", &user_data.AT[11],
00149 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg13", &user_data.AT[12],
00150 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg14", &user_data.AT[13],
00151 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg15", &user_data.AT[14],
00152 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg16", &user_data.AT[15],
00153 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg17", &user_data.AT[16],
00154 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg18", &user_data.AT[17],
00155 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Tavg19", &user_data.AT[18],
00156 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg20", &user_data.AT[19],
00157 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg21", &user_data.AT[20],
00158 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg22", &user_data.AT[21],
00159 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg23", &user_data.AT[22],
00160 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg24", &user_data.AT[23],
00161 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg25", &user_data.AT[24],
00162 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg26", &user_data.AT[25],
00163 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg27", &user_data.AT[26],
00164 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg28", &user_data.AT[27],
00165 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg29", &user_data.AT[28],
00166 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg30", &user_data.AT[29],
00167 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg31", &user_data.AT[30],
00168 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg32", &user_data.AT[31],
00169 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg33", &user_data.AT[32],
00170 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg34", &user_data.AT[33],
00171 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg35", &user_data.AT[34],
00172 4, UNIT_CELSIUS, 0, 0, MSCBF_HIDDEN|MSCBF_FLOAT, "Tavg36", &user_data.AT[35],
00173
00174 4, UNIT_BYTE, 0, 0,MSCBF_HIDDEN,"eepValue", &user_data.eepValue,
00175 4, UNIT_BYTE, 0, 0,MSCBF_HIDDEN,"eeCtrSet", &user_data.eeCtrSet,
00176
00177 4, UNIT_CELSIUS, 0, 0,MSCBF_FLOAT, "SHTtemp", &user_data.SHTtemp1,
00178 4, 10, 0, 0,MSCBF_FLOAT, "SHThumi", &user_data.SHThumi1,
00179 4, UNIT_CELSIUS, 0, 0,MSCBF_FLOAT, "SHTtemp2", &user_data.SHTtemp2,
00180 4, 10, 0, 0,MSCBF_FLOAT, "SHThumi2", &user_data.SHThumi2,
00181
00182 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC0", &user_data.DAC[0],
00183 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC1", &user_data.DAC[1],
00184 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC2", &user_data.DAC[2],
00185 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC3", &user_data.DAC[3],
00186 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC4", &user_data.DAC[4],
00187 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC5", &user_data.DAC[5],
00188 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC6", &user_data.DAC[6],
00189 2, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "DAC7", &user_data.DAC[7],
00190
00191 0
00192 };
00193
00194 MSCB_INFO_VAR *variables = vars;
00195
00196
00197
00198
00199 void publishCtlCsr(void) {
00200 DISABLE_INTERRUPTS;
00201 user_data.control = rCTL;
00202 user_data.status = rCSR;
00203 ENABLE_INTERRUPTS;
00204 }
00205
00206
00207
00208 void publishErr(bit errbit) {
00209 DISABLE_INTERRUPTS;
00210 errbit = SET;
00211 user_data.error = rESR;
00212 ENABLE_INTERRUPTS;
00213 }
00214
00215
00216
00217 void publishAll() {
00218 user_data.control = rCTL;
00219 user_data.status = rCSR;
00220 user_data.error = rESR;
00221 ENABLE_INTERRUPTS;
00222 }
00223
00224
00225
00226 void autocalibration(float reference)
00227 {
00228 float buffer;
00229 int offset, i;
00230 for(i=0;i<18; i++){
00231
00232 buffer=reference-user_data.AT[2*i];
00233
00234 buffer*=4;
00235 offset=(int)(buffer*16);
00236 eepage.ext2offset[i]=offset;
00237
00238 buffer=reference-user_data.AT[2*i+1];
00239
00240 buffer*=4;
00241 offset=(int)(buffer*16);
00242 eepage.ext1offset[i]=offset;
00243 }
00244 return;
00245 }
00246
00247
00248
00249 int eepageAddrConvert(unsigned int index)
00250 {
00251 int add;
00252
00253 if(!(index%2))
00254 add = index/2 + 18 + EEP_RW_IDX;
00255
00256 else
00257 add = index/2 + EEP_RW_IDX;
00258 return add;
00259 }
00260
00261
00262 void user_init(unsigned char init)
00263 {
00264 unsigned char idata i;
00265
00266
00267 for (i=0;i<4;i++) {
00268 if (svn_rev_code[6+i] < 48) {
00269 svn_rev_code[6+i] = '0';
00270 }
00271 }
00272
00273 sys_info.svn_revision = (svn_rev_code[6]-'0')*1000+
00274 (svn_rev_code[7]-'0')*100+
00275 (svn_rev_code[8]-'0')*10+
00276 (svn_rev_code[9]-'0');
00277
00278 if(init) {}
00279
00280
00281
00282
00283 #ifdef _ExtEEPROM_
00284 SFRPAGE = CONFIG_PAGE;
00285 P2MDOUT |= 0x31;
00286 P2MDOUT &= 0xFB;
00287 ExtEEPROM_Init();
00288
00289
00290 ExtEEPROM_Read (WP_START_ADDR, (unsigned char xdata *)&eepage ,PAGE_SIZE);
00291 DISABLE_INTERRUPTS;
00292 user_data.SerialN = eepage.SerialN;
00293 ENABLE_INTERRUPTS;
00294
00295
00296 ExtEEPROM_Read (PageAddr[0] ,(unsigned char xdata *)&eepage ,PAGE_SIZE);
00297 DISABLE_INTERRUPTS;
00298 user_data.navge = eepage.navge;
00299 ENABLE_INTERRUPTS;
00300
00301 #endif
00302
00303
00304
00305 #ifdef _ADT7486A_
00306 SFRPAGE = CONFIG_PAGE;
00307 P0MDOUT |= 0x18;
00308 SFRPAGE = CPT1_PAGE;
00309 CPT1CN |= 0x80;
00310 CPT1MD = 0x03;
00311 SFRPAGE = CPT0_PAGE;
00312 CPT0CN |= 0x80;
00313 CPT0MD = 0x03;
00314
00315 ADT7486A_Init(SST_LINE1);
00316 ADT7486A_Init(SST_LINE2);
00317
00318
00319 for (channel=0;channel < 9; channel++){
00320
00321 ADT7486A_Cmd(ADT7486A_addrArray[channel]
00322 , SetExt2Offset
00323 , (eepage.ext2offset[channel]>>8)
00324 , eepage.ext2offset[channel]
00325 , SST_LINE1
00326 , &temperature);
00327 delay_us(100);
00328 }
00329 delay_us(300);
00330 for (channel=9;channel < 18; channel++){
00331
00332 ADT7486A_Cmd(ADT7486A_addrArray[channel-9]
00333 , SetExt2Offset
00334 , (eepage.ext2offset[channel]>>8)
00335 , eepage.ext2offset[channel]
00336 , SST_LINE2
00337 , &temperature);
00338 delay_us(100);
00339 }
00340 delay_us(300);
00341 for (channel=0;channel < 9; channel++){
00342
00343 ADT7486A_Cmd(ADT7486A_addrArray[channel]
00344 , SetExt1Offset
00345 , (eepage.ext1offset[channel]>>8)
00346 , eepage.ext1offset[channel]
00347 , SST_LINE1
00348 , &temperature);
00349 delay_us(100);
00350 }
00351 delay_us(300);
00352 for (channel=9;channel < 18; channel++){
00353
00354 ADT7486A_Cmd(ADT7486A_addrArray[channel-9]
00355 , SetExt1Offset
00356 , (eepage.ext1offset[channel]>>8)
00357 , eepage.ext1offset[channel]
00358 , SST_LINE2
00359 , &temperature);
00360 delay_us(100);
00361 }
00362 delay_us(300);
00363 #endif
00364
00365
00366 DISABLE_INTERRUPTS
00367 user_data.terror[0]=0;
00368 user_data.terror[1]=0;
00369 user_data.terror[2]=0;
00370 user_data.terror[3]=0;
00371 user_data.terror[4]=0;
00372 user_data.status=0;
00373 rCTL = user_data.control=0x4;
00374
00375
00376 user_data.SHTtemp1 = 0;
00377 user_data.SHThumi1 = 0;
00378 user_data.SHTtemp2 = 0;
00379 user_data.SHThumi2 = 0;
00380
00381 for (i=0; i<36;i ++)
00382 user_data.Temp[i] = 0.0;
00383 user_data.eepage=0;
00384 user_data.navge=20;
00385 for(i=0; i<36; i++)
00386 {
00387 user_data.AT[i]=0;
00388 }
00389
00390 user_data.ref=0;
00391
00392 ENABLE_INTERRUPTS
00393
00394 EEP_CTR_Flag = 0;
00395 rCSR=0;
00396
00397
00398 #ifdef _HUMSEN_
00399 SFRPAGE = CONFIG_PAGE;
00400 P1MDOUT |= 0x07;
00401 SHT_VDD1=1;
00402 SHT_GND1=0;
00403
00404 HumiSensor_Init(humsen1);
00405 #ifdef MORETHANONEHUM
00406 P3MDOUT |= 0x07;
00407 SHT_VDD2=1;
00408 SHT_GND2=0;
00409 HumiSensor_Init(humsen2);
00410 #endif
00411 #endif
00412
00413
00414 #ifdef _LTC2600_
00415 SFRPAGE = CONFIG_PAGE;
00416 P0MDOUT |= 0x80;
00417 P2MDOUT |= 0x30;
00418 LTC2600_Init();
00419 #endif
00420 }
00421
00422
00423 void user_write(unsigned char index) reentrant
00424 {
00425 if (index == IDXCTL) rCTL = user_data.control;
00426
00427 if (index == IDXEEP_CTL) EEP_CTR_Flag = SET;
00428
00429 #ifdef _LTC2600_
00430 if ((index >= First_DACIndex) && (index <= Last_DACIndex)) {
00431 DACIndex = (index - First_DACIndex);
00432
00433 LTC2600_Flag = SET;
00434 }
00435 #endif
00436
00437 if(index==IDXNAVG) {
00438 cavg = 0;
00439 numavg = 0;
00440 }
00441 }
00442
00443
00444 unsigned char user_read(unsigned char index)
00445 {
00446 if(index);
00447 return 0;
00448 }
00449
00450
00451 unsigned char user_func(unsigned char *data_in, unsigned char *data_out)
00452 {
00453
00454 data_out[0] = data_in[0];
00455 data_out[1] = data_in[1];
00456 return 2;
00457 }
00458
00459
00460
00461 void user_loop(void)
00462 {
00463
00464 #ifdef _ADT7486A_
00465
00466
00467 for (channel=0;channel < 9; channel++){
00468 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel]
00469 , GetExt2Temp
00470 , SST_LINE1
00471 , &temperature)){
00472
00473 DISABLE_INTERRUPTS;
00474 user_data.Temp[channel*2] = temperature;
00475 if(channel<4)
00476 user_data.terror[0] &= Terrorclear[2*channel];
00477 else if(channel<8)
00478 user_data.terror[1] &= Terrorclear[2*(channel-4)];
00479 else
00480 user_data.terror[2] &= Terrorclear[2*(channel-8)];
00481 ENABLE_INTERRUPTS;
00482 } else {
00483
00484 DISABLE_INTERRUPTS;
00485 if(channel<4)
00486 user_data.terror[0] |= Terrorset[2*channel];
00487 else if(channel<8)
00488 user_data.terror[1] |= Terrorset[2*(channel-4)];
00489 else
00490 user_data.terror[2] |= Terrorset[2*(channel-8)];
00491 ENABLE_INTERRUPTS;
00492 }
00493 }
00494
00495 yield();
00496
00497
00498
00499 for (channel=9;channel < 18; channel++){
00500 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel-9]
00501 , GetExt2Temp
00502 , SST_LINE2
00503 , &temperature)){
00504
00505 DISABLE_INTERRUPTS;
00506 user_data.Temp[channel*2] = temperature;
00507 if(channel<12)
00508 user_data.terror[2] &= Terrorclear[2*(channel-8)];
00509 else if(channel<16)
00510 user_data.terror[3] &= Terrorclear[2*(channel-12)];
00511 else
00512 user_data.terror[4] &= Terrorclear[2*(channel-16)];
00513 ENABLE_INTERRUPTS;
00514 }
00515 else{
00516 DISABLE_INTERRUPTS;
00517 if(channel<12)
00518 user_data.terror[2] |= Terrorset[2*(channel-8)];
00519 else if(channel<16)
00520 user_data.terror[3] |= Terrorset[2*(channel-12)];
00521 else
00522 user_data.terror[4] |= Terrorset[2*(channel-16)];
00523 ENABLE_INTERRUPTS;
00524 }
00525 }
00526
00527
00528 yield();
00529
00530
00531
00532 for (channel=0;channel < 9; channel++){
00533 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel]
00534 , GetExt1Temp
00535 , SST_LINE1
00536 , &temperature)){
00537 DISABLE_INTERRUPTS;
00538 user_data.Temp[(channel*2)+1] = temperature;
00539 if(channel<4)
00540 user_data.terror[0] &= Terrorclear[2*channel+1];
00541 else if(channel<8)
00542 user_data.terror[1] &= Terrorclear[2*(channel-4)+1];
00543 else
00544 user_data.terror[2] &= Terrorclear[2*(channel-8)+1];
00545 ENABLE_INTERRUPTS;
00546 }
00547 else{
00548 DISABLE_INTERRUPTS;
00549 if(channel<4)
00550 user_data.terror[0] |= Terrorset[2*channel+1];
00551 else if(channel<8)
00552 user_data.terror[1] |= Terrorset[2*(channel-4)+1];
00553 else
00554 user_data.terror[2] |= Terrorset[2*(channel-8)+1];
00555 ENABLE_INTERRUPTS;
00556 }
00557 }
00558
00559
00560 yield();
00561
00562
00563
00564 for (channel=9;channel < 18; channel++){
00565 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel-9]
00566 , GetExt1Temp
00567 , SST_LINE2
00568 , &temperature)){
00569 DISABLE_INTERRUPTS;
00570 user_data.Temp[(channel*2)+1] = temperature;
00571 if(channel<12)
00572 user_data.terror[2] &= Terrorclear[2*(channel-8)+1];
00573 else if(channel<16)
00574 user_data.terror[3] &= Terrorclear[2*(channel-12)+1];
00575 else
00576 user_data.terror[4] &= Terrorclear[2*(channel-16)+1];
00577 ENABLE_INTERRUPTS;
00578 }
00579 else{
00580 DISABLE_INTERRUPTS;
00581 if(channel<12)
00582 user_data.terror[2] |= Terrorset[2*(channel-8)+1];
00583 else if(channel<16)
00584 user_data.terror[3] |= Terrorset[2*(channel-12)+1];
00585 else
00586 user_data.terror[4] |= Terrorset[2*(channel-16)+1];
00587 ENABLE_INTERRUPTS;
00588 }
00589 }
00590
00591
00592 yield();
00593
00594
00595 if((user_data.navge <= TAVGMAX) && (user_data.navge != 0)) {
00596 if(cavg == user_data.navge)
00597 cavg=1;
00598 else {
00599 cavg++;
00600 if(numavg != user_data.navge) numavg=cavg;
00601 }
00602
00603 for(channel=0; channel<36; channel++) {
00604 Taverage[channel][(cavg-1)] = user_data.Temp[channel];
00605 average=0;
00606
00607 for(avgcount=0; avgcount<numavg; avgcount++)
00608 average+=Taverage[channel][avgcount];
00609 average/=numavg;
00610 DISABLE_INTERRUPTS;
00611 user_data.AT[channel]=average;
00612 ENABLE_INTERRUPTS;
00613 }
00614 }
00615 #endif
00616
00617 #ifdef _ExtEEPROM_
00618
00619
00620 if (EEP_CTR_Flag) {
00621
00622 if (user_data.eeCtrSet & EEP_CTRL_KEY) {
00623
00624 if( (int)(user_data.eeCtrSet & 0x000000ff) < TEMPOFF_LAST_INDX) {
00625
00626 eep_address = (int xdata *)&eepage + eepageAddrConvert((int)(user_data.eeCtrSet & 0x000000ff));
00627
00628 if (user_data.eeCtrSet & EEP_CTRL_WRITE){
00629 *eep_address = user_data.eepValue;
00630
00631 } else if (user_data.eeCtrSet & EEP_CTRL_READ) {
00632 DISABLE_INTERRUPTS;
00633 user_data.eepValue = *eep_address;
00634 ENABLE_INTERRUPTS;
00635 } else {
00636
00637 DISABLE_INTERRUPTS;
00638 user_data.eeCtrSet = EEP_CTRL_INVAL_REQ;
00639 ENABLE_INTERRUPTS;
00640 }
00641 } else {
00642 DISABLE_INTERRUPTS;
00643 user_data.eeCtrSet = EEP_CTRL_OFF_RANGE;
00644 ENABLE_INTERRUPTS;
00645 }
00646 } else {
00647
00648 DISABLE_INTERRUPTS;
00649 user_data.eeCtrSet = EEP_CTRL_INVAL_KEY;
00650 ENABLE_INTERRUPTS;
00651 }
00652 EEP_CTR_Flag = CLEAR;
00653 }
00654
00655
00656
00657
00658 if (CeeS) {
00659
00660 if (!eeprom_flag) {
00661 rCSR = user_data.status;
00662
00663
00664 eeptemp_addr = PageAddr[(unsigned char)(user_data.eepage & 0x07)];
00665
00666 eeptemp_source = (unsigned char xdata *)&eepage;
00667 }
00668
00669
00670 if (CeeClr) eep_request = CLEAR_EEPROM;
00671 else eep_request = WRITE_EEPROM;
00672
00673 status = ExtEEPROM_Write_Clear (eeptemp_addr
00674 , &eeptemp_source
00675 , PAGE_SIZE
00676 , eep_request
00677 , &eeprom_flag);
00678
00679 if (status == DONE) {
00680 SeeS = DONE;
00681 eeprom_flag = CLEAR;
00682
00683 user_data.eepage |= ((user_data.eepage & 0x07) << 5);
00684 } else {
00685 SeeS = FAILED;
00686 }
00687
00688 CeeS = CLEAR;
00689
00690 publishCtlCsr();
00691 }
00692
00693
00694
00695 if (CeeR) {
00696 rCSR = user_data.status;
00697
00698
00699 channel = ExtEEPROM_Read (PageAddr[(unsigned char)(user_data.eepage & 0x07)]
00700 , (unsigned char xdata *)&eepage, PAGE_SIZE);
00701
00702 if (channel == DONE) SeeR = DONE;
00703 else SeeR = FAILED;
00704
00705 CeeR = CLEAR;
00706 publishCtlCsr();
00707 }
00708 #endif
00709
00710
00711
00712 #ifdef _HUMSEN_
00713
00714 if(CHum){
00715 status = HumidSensor_Cmd (&rSHThumi1
00716 ,&rSHTtemp1
00717 ,&humidity
00718 ,&htemperature
00719 ,&FCSorig1
00720 ,&FCSdevi1
00721 ,humsen1);
00722 if (status == DONE) {
00723 DISABLE_INTERRUPTS;
00724 user_data.SHThumi1 = humidity;
00725 user_data.SHTtemp1 = htemperature;
00726 ENABLE_INTERRUPTS;
00727 }
00728
00729 #ifdef MORETHANONEHUM
00730 status = HumidSensor_Cmd (&rSHThumi2
00731 ,&rSHTtemp2
00732 ,&humidity
00733 ,&htemperature
00734 ,&FCSorig2
00735 ,&FCSdevi2
00736 ,humsen2);
00737 if (status == DONE) {
00738 DISABLE_INTERRUPTS;
00739 user_data.SHThumi2 = humidity;
00740 user_data.SHTtemp2 = htemperature;
00741 ENABLE_INTERRUPTS;
00742 }
00743 #endif // MORETHANONE
00744 }
00745
00746 #endif // HUMIDITY
00747
00748 #ifdef _LTC2600_
00749
00750 if(LTC2600_FLAG) {
00751 LTC2600_Cmd(WriteTo_Update,LTC2600_LOAD[DACIndex], user_data.DAC[DACIndex]);
00752 LTC2600_FLAG = CLEAR;
00753 }
00754 #endif
00755
00756 if(Cref) {
00757 autocalibration(user_data.ref);
00758 Sref = 1;
00759 Cref = 0;
00760 DISABLE_INTERRUPTS;
00761 user_data.status=rCSR;
00762 user_data.control=rCTL;
00763 ENABLE_INTERRUPTS;
00764 }
00765
00766 led_blink(0, 1, 150);
00767
00768 }