sanjiv365
Newbie level 5
View attachment Nuvoton rev1.rar this is my code unable compile on the keil
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?MCP3302_READ?MAIN
*** ERROR L107: ADDRESS SPACE OVERFLOW
SPACE: DATA
SEGMENT: _DATA_GROUP_
LENGTH: 001CH
Program Size: data=120.1 xdata=0 code=4393
Target not created.
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 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 #include <n79e855a.H> #include <stdio.h> #include <string.h> sbit SET = P1^0; sbit INC = P1^1; sbit LED = P3^7; sbit CLK = P1^4; sbit DOUT = P1^5; sbit DIN = P1^6; sbit CS = P1^7; code const unsigned int presetValues[] = {5,10,15,20,25,30,40,50,60,70,80,90,100,125,150,175,200,225, 250,275,300,325,350,375,400,425,450,475,500,525,550,575,600, 625,650,675,700,725,750,775,800,825,850,875,900,925,950,975,1000}; char mask[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; char mask_dp[] = {0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF}; unsigned int setValue = 0, i = 0; char myFlags = 0; char setFlag = 0; char incrementOrDisplayToggleFlag = 0; char blink = 0; double adcValue = 0.0, fTen = 10.0, fHundred = 100.0, fThousand = 1000.0, prevAdcValue = 0.0; char display[4] = {0, 0, 0, 0}; char ten = 10, hundred = 100, blinkCount = 0, counter = 0; unsigned int thousand = 1000; char select = 0; int sprintf (char *buffer, const char *fmtstr, double s); void Delay_us(unsigned int us_count); void Delay_ms(unsigned int ms_count); void Display(void); void Display2(double s); void Delay_us(unsigned int us_count) { while(us_count!=0) { us_count--; } } void Delay_ms(unsigned int ms_count) { while(ms_count!=0) { Delay_us(112); //delay_us is called to generate 1ms delay ms_count--; } } void InitTimer1() { TMOD = 0x10; TL1 = 0x00; TH1 = 0xEE; TR1 = 1; ET1 = 1; EA = 1; } void InitTimer0() { TMOD |= 0x01; TL0 = 0xFE; TH0 = 0x4B; TR0 = 1; ET0 = 1; } void timer0_ISR (void) interrupt 1 { if(TF0) { if(++counter == 8) { TR1 = ~TR1; if(TR1 == 0) { P3 = (P3 & 0xF0); blinkCount++; if(blinkCount == 4) { blinkCount = 0; TR0 = 0; TL1 = 0x00; TH1 = 0xEE; TF1 = 0; incrementOrDisplayToggleFlag = ~incrementOrDisplayToggleFlag; TR1 = 1; } } counter = 0; } TL0 = 0xFE; TH0 = 0x4B; TF0 = 0; } } void timer1_ISR (void) interrupt 3 { if(TF1) { //Enter your code here P3 = P3 & 0xF0; switch(select) { case 0: P2 = display[0]; P3 = (P3 & 0xF0) | 0x08; break; case 1: P2 = display[1]; P3 = (P3 & 0xF0) | 0x04; break; case 2: P2 = display[2]; P3 = (P3 & 0xF0) | 0x02; break; case 3: P2 = display[3]; P3 = (P3 & 0xF0) | 0x01; break; }; select++; if(select == 4) { select = 0; } if(incrementOrDisplayToggleFlag) { if((setValue >= 0) && (setValue < ten)) { if(select == 1)select = 0; } else if((setValue >= ten) && (setValue < hundred)) { if(select == 2)select = 0; } else if((setValue >= hundred) && (setValue < thousand)) { if(select == 3)select = 0; } } TL1 = 0x00; TH1 = 0xEE; TF1 = 0; } } void Display1() { if((setValue >= 0) && (setValue < ten)) { display[0] = mask[setValue]; } else if((setValue >= ten) && (setValue < hundred)) { display[0] = mask[setValue % ten]; display[1] = mask[setValue / ten]; } else if((setValue >= hundred) && (setValue < thousand)) { display[0] = mask[setValue % ten]; display[1] = mask[((setValue / ten) % ten)]; display[2] = mask[setValue / hundred]; } else if(setValue >= thousand) { display[0] = mask[setValue % ten]; display[1] = mask[((setValue / ten) % ten)]; display[2] = mask[((setValue / hundred) % ten)]; display[3] = mask[setValue / thousand]; } } void Display2(double s) { unsigned int befDec = 0, aftDec = 0; befDec = s; aftDec = (s - befDec) * 100; if((adcValue >= 0.0) && (adcValue < 1.0)) { display[3] = mask_dp[0]; display[2] = mask[aftDec / hundred]; display[1] = mask[(aftDec / ten) % ten]; display[0] = mask[aftDec % ten]; } else if((adcValue >= 1.0) && (adcValue < fTen)) { display[3] = mask_dp[befDec]; display[2] = mask[aftDec / hundred]; display[1] = mask[(aftDec / ten) % ten]; display[0] = mask[aftDec % ten]; } else if((adcValue >= fTen) && (adcValue < fHundred)) { display[3] = mask[befDec / ten]; display[2] = mask_dp[befDec % ten]; display[1] = mask[aftDec / hundred]; display[0] = mask[(aftDec / ten) % ten]; } else if((adcValue >= fHundred) && (adcValue < fThousand)) { display[3] = mask[befDec / hundred]; display[2] = mask[(befDec / ten) % ten]; display[1] = mask_dp[befDec % ten]; display[0] = mask[aftDec / 100]; } else if(adcValue >= fThousand) { display[3] = mask[befDec / thousand]; display[2] = mask[(befDec / hundred) % ten]; display[1] = mask[(befDec / ten) % ten]; display[0] = mask_dp[befDec % ten]; } } double MCP3302_Read() { char i = 0; unsigned int adcVal = 0, mask = 0x800; CS = 1; Delay_us(5); CS = 0; Delay_us(5); CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); DOUT = 1; CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); DOUT = 0; CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); for(i = 0; i < 12; i++) { adcVal >>= 1; if(DIN) { adcVal = adcVal | mask; } CLK = 1; Delay_us(5); CLK = 0; Delay_us(5); } CS = 1; return (double)(adcVal & 0x0FFF); } void main() { P0 = 0x00; P1 = 0x43; P2 = 0x00; P3 = 0x00; Delay_ms(200); InitTimer1(); while(1) { adcValue = MCP3302_Read(); if(!SET) { Delay_ms(50); while(!SET); setFlag = ~setFlag; if(setFlag == 0){ InitTimer0(); blinkCount = 0; Display1(); Delay_ms(3000); incrementOrDisplayToggleFlag = 0; } } if(setFlag) { if(!INC) { Delay_ms(50); while(!INC); setValue = presetValues[i++]; if(i == 49)i = 0; } incrementOrDisplayToggleFlag = 1; Display1(); } else if(!setFlag) { if(!INC) { Delay_ms(50); while(!INC); incrementOrDisplayToggleFlag = ~incrementOrDisplayToggleFlag; } } if(incrementOrDisplayToggleFlag) Display1(); else if(!incrementOrDisplayToggleFlag) Display2(adcValue); if(adcValue > setValue)LED = 1; else LED = 0; } }