gonzalezteins
Newbie level 3
Dear all,
I am working ona project where i sense temp using PT-100, voltage comparator conditions the voltage to be between cmos limits. Following this adc 0804 converts A to D, and feeds to the micro-controller. the following is the cade, working fine! but i cannot understand a particular part:
---------- Post added at 18:07 ---------- Previous post was at 18:06 ----------
it is kinda urgent, will be immensely grateful to you for your help thanks!
---------- Post added at 18:14 ---------- Previous post was at 18:07 ----------
Rt = R0 * (1 + A* t )
A = 3.9083 X 10 ^-3
r5, r8, r6 are 2700Ω and r7 is 100Ω
I am working ona project where i sense temp using PT-100, voltage comparator conditions the voltage to be between cmos limits. Following this adc 0804 converts A to D, and feeds to the micro-controller. the following is the cade, working fine! but i cannot understand a particular part:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 #include <At89x52.h> #include "lcd.h" #include "keypad.h" #include "delay.h" //================================================================= = #define adc_port P2 //ADC Port #define rd P0_6 //Read signal #define wr P0_5 //Write signal #define cs P0_7 //Chip Select #define intr P0_4 //INTR signal //================================================================= #define RELAY P0_3 #define UNDERTEMP P0_0 #define OVERTEMP P0_1 //================================================================= #define TEMP_LOW_LIMIT 0x00 #define TEMP_HIGH_LIMIT 0x01 //================================================================= void conv(); //Start of conversion function void read(); //Read ADC function void delay1(unsigned int a); void delay_100us(unsigned int a); //0.1 ms unsigned int enter_val(unsigned char mode); int key_get(void); //================================================================= unsigned char adc_val; unsigned int display_number=0; //================================================================= //Main function void main() { unsigned long temp1,temp2; unsigned long a1; unsigned int low_limit,high_limit,high_alarm_limit; float c,d,e,f,b,a,g,h; P0=0x00; P1=0xFF; P2=0xFF; RELAY=1 ; // relay off UNDERTEMP=0; //0=sound off OVERTEMP=0; //1=sound OFF LCD_INIT(); LCD_CLEAR(); LCD_STRING("TEMP CONTROLLED"); LCD_CMD(PUTLINE2); LCD_STRING(" FAN "); delay_100us(10000); delay_100us(10000); delay_100us(10000); delay_100us(10000); LCD_CLEAR(); LCD_STRING("CURRENT TEMP"); high_alarm_limit = 130; high_limit=120; while(1) //Forever loop { LCD_CMD(PUTLINE2); conv(); //Start conversion read(); //Read ADC a=5*adc_val; b=a/255; //can't understand from here [B][I]c= 8.4375 + b; d= c*1500; e = 149-c; f = d/e; g= (f-100); //stright line equation h =g/0.22; h=h+10;[/I][/B] //can't understand till here LCD_DisplayNum(h,3); LCD_STRING(" DEG C"); delay1(10); if(key_get()!=0) { switch(key) { case mode_key: LCD_CLEAR(); LCD_STRING(" TEMP LIMIT SET "); LCD_CMD(PUTLINE2); LCD_STRING("MODE "); delay_100us(20000); delay_100us(20000); LCD_CLEAR(); LCD_STRING("TEMP LOW LIMIT?"); LCD_CMD(PUTLINE2); low_limit = enter_val(TEMP_LOW_LIMIT); LCD_CLEAR(); LCD_STRING("TEMP HIGH LIMIT?"); LCD_CMD(PUTLINE2); high_limit = enter_val(TEMP_HIGH_LIMIT); LCD_CLEAR(); LCD_STRING("Low Limit:"); LCD_DisplayNum(low_limit,3); delay_100us(10000); delay_100us(10000); delay_100us(10000); delay_100us(10000); LCD_CLEAR(); LCD_STRING("High Limit:"); LCD_DisplayNum(high_limit,3); delay_100us(10000); delay_100us(10000); delay_100us(10000); delay_100us(10000); LCD_CLEAR(); LCD_STRING("CURRENT TEMP"); break; break; case start_key: LCD_CLEAR(); LCD_STRING("Low Limit:"); LCD_DisplayNum(low_limit,3); delay_100us(10000); delay_100us(10000); delay_100us(10000); delay_100us(10000); LCD_CLEAR(); LCD_STRING("High Limit:"); LCD_DisplayNum(high_limit,3); delay_100us(10000); delay_100us(10000); delay_100us(10000); delay_100us(10000); LCD_CLEAR(); LCD_STRING("CURRENT TEMP"); OVERTEMP=0; break; } } if(h >=high_limit) { RELAY=0;//off { if(h >=high_alarm_limit) UNDERTEMP=1; //OFF OVERTEMP=1; //ON } } else if(h <=low_limit) { RELAY=1; //OFF UNDERTEMP=0; //ON OVERTEMP=0; //OFF } } } // Function for A-D conversion void conv() { cs = 0; //Make CS low wr = 0; //Make WR low wr = 1; //Make WR high cs = 1; //Make CS high while(intr); //Wait for INTR to go low } //Function to read digital values to 89S52 void read() { cs = 0; //Make CS low rd = 0; //Make RD low adc_val = adc_port; //Read ADC port rd = 1; //Make RD high cs = 1; //Make CS high } //Delay function void delay1(unsigned int a) { unsigned int b; for(;a>0;a--) { for(b=0;b<1000;b++) { a--; a++; } } } //Function for setting values of the upper and lower limit using up and down keys. unsigned int enter_val(unsigned char mode) { unsigned int start_num=0; unsigned int end_num; unsigned int return_value; bit num_complete=0; if(mode==TEMP_LOW_LIMIT) end_num=500; if(mode==TEMP_HIGH_LIMIT) end_num=500; display_number=0; LCD_DisplayNum(display_number,3); while(num_complete==0) { while(key_get()==0); switch(key) { case start_key: num_complete=1; return_value=display_number; break; case up_key: if(display_number==end_num)display_number=0; else displ ay_number = display_number +5 ; LCD_CMD(PUTLINE2); LCD_DisplayNum(display_number,3); break; case down_key: if(display_number==start_num)display_number=end_num; else display_number = display_number - 5; LCD_CMD(PUTLINE2); LCD_DisplayNum(display_number,3); break; case mode_key: return 100; break; } } return return_value; } //Function to check which key is pressed out of the 4 at a given point of time. int key_get(void) { if(start==0) { key=start_key; do{delay_100us(100);}while(start==0); delay_100us(500); //return key } else if(mode==0) { key=mode_key; do{delay_100us(100);}while(mode==0); delay_100us(500); //return key; } else if(up==0) { key=up_key; do{delay_100us(100);}while(up==0); delay_100us(500); //return key; } else if(down==0) { key=down_key; do{delay_100us(100);}while(down==0); delay_100us(500); //return key; } else key=0; //return 0 return key; }
---------- Post added at 18:07 ---------- Previous post was at 18:06 ----------
it is kinda urgent, will be immensely grateful to you for your help thanks!
---------- Post added at 18:14 ---------- Previous post was at 18:07 ----------
Rt = R0 * (1 + A* t )
A = 3.9083 X 10 ^-3
r5, r8, r6 are 2700Ω and r7 is 100Ω