nayakajit87
Member level 5
I am using PIC16F886 4mhz crystal Timer1 interrupt with 1ms . i am trying to build timer application.
When top display == bottom display the process should stop. Top display Set value Bottom Display shows process value.
I would like to replace Dissect_2 function since currently i am passing argument as integer. So display update as whole integer but i am looking for function it update digit by digit.
I am looking for C function so that if my Sec paramter reaches 59s the update value should be 1min ,59s should start update again in 0. when it reaches 59S it should update 1m-2M the process continue tell it reaches 2M 10S in below code Tpvalue=0210 means bottom display will stop at 0210
When top display == bottom display the process should stop. Top display Set value Bottom Display shows process value.
Top display set usually in time format if value 0210 means if LED_SS==0 02Sec 10ms LED_MS==0 02Min 10S LED_HM==0 02H 10Min
I would like to replace Dissect_2 function since currently i am passing argument as integer. So display update as whole integer but i am looking for function it update digit by digit.
I am looking for C function so that if my Sec paramter reaches 59s the update value should be 1min ,59s should start update again in 0. when it reaches 59S it should update 1m-2M the process continue tell it reaches 2M 10S in below code Tpvalue=0210 means bottom display will stop at 0210
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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 #include <htc.h> #include <stdio.h> #include <math.h> #include "delay.h" #define _XTAL_FREQ 4000000 __CONFIG(FOSC_HS & WDTE_ON& PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & DEBUG_OFF&MCLRE_ON &BOREN_ON&FCMEN_ON &WRT_OFF); #define RLY_DRV1 RB4 #define PRG_EN RA4 #define DISPCLK RB5 #define DISPDATA RB6 #define STROBE RB7 #define RESET RB1 unsigned char Main_Flag=0; unsigned char j=0; unsigned int Bottom_Value=0; unsigned int Top_Display=1234; struct { unsigned RUNMODE :1; unsigned PRGMODE :1; unsigned KeyLock_RESET1 :1; unsigned KeyLock_SELECT1 :1; unsigned KeyLock_ADVANCE :1; unsigned BLINKFLAG :1; unsigned BLINKFLAG1 :1; unsigned FLASHFLAG :1; unsigned KeyTEST_PRESS :1; unsigned MANUAL_RESET :1; unsigned AUTO_RESET :1; } bits; unsigned char Dec_pt=1; unsigned char SETPRESS=0; unsigned char DgtSel=2; unsigned int Debounce=0; unsigned char LEDBuffer_1[8]; unsigned int Hour,Min,Sec,Msec; unsigned char Counter=0; unsigned char Digit[4] = {0,0,0,0}; const unsigned char DISPTABLE[28] = {0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09,0x11,0x83,0x31, //0 //1 //2 //3 //4 //5 //6 //7 //8 //9 //A //U //P 0xD1,0xE3,0x89,0x63,0xE1,0xF5,0xC1,0x61,0x71,0xF3,0xFD,0xD5,0x85,0xFF,0X43 }; //h //L //Y //C //t //r //b //E //F //I //- //n //d //blank //G unsigned int OVOL=105; unsigned char UVOL=75,UCRT=30; unsigned char Sub_Pulse=1; unsigned char Sub_Time=1; unsigned char Sub_Relay=1; unsigned char Sub_HMS=1; unsigned char voltage=0; unsigned char DecimalTOP=0; unsigned char BLINKSEGMENT=0; unsigned char BLINKCOUNT=0; unsigned char BLINKFLAG=0; unsigned char i=0; unsigned char k=0; unsigned char l=0; unsigned char m=0; unsigned char BLINKCOUNT1=0; unsigned char BLINKCOUNT2=0; unsigned char BLINKCOUNT3=0; unsigned char BLINKCOUNT4=0; unsigned char Blink_Count=1; unsigned char Converted_Value; unsigned int Top_Value=0; unsigned char EEPROM_Write_Flag=0; unsigned char EEPROM_Read_Flag=1; unsigned int Result; //======================================================================================= // Sub Menu Change //======================================================================================= void SubMenu(unsigned char Chr5, unsigned char Chr6, unsigned char Chr7, unsigned char Chr8) { LEDBuffer_1[0] = DISPTABLE[Chr5]; LEDBuffer_1[1] = DISPTABLE[Chr6]; LEDBuffer_1[2] = DISPTABLE[Chr7]; LEDBuffer_1[3] = DISPTABLE[Chr8]; } //======================================================================================= // Main Menu Change //======================================================================================= void Main_Menu(unsigned char Chr1, unsigned char Chr2, unsigned char Chr3, unsigned char Chr4) { LEDBuffer_1[4] = DISPTABLE[Chr1]; LEDBuffer_1[5] = DISPTABLE[Chr2]; LEDBuffer_1[6] = DISPTABLE[Chr3]; LEDBuffer_1[7] = DISPTABLE[Chr4]; } //*************************************************************************************** // Whole number broken into individual digits and converted to its LED 7 segment value. // Called from timer interrupt. //*************************************************************************************** void Dissect(unsigned int Value) { // Spliting of process value in digits form unsigned char a,Temp; for(a = 8; a >= 5 ; a--) { Temp = Value%10; Value = Value/10; LEDBuffer_1[a-1] = DISPTABLE[Temp]; } } //************************************************************************************ // Whole number broken into individual digits and converted to its LED 7 segment value. // called outside timer interrupt. //************************************************************************************ void Dissect_2(unsigned int Value) { // Spliting of process value in digits form unsigned char a,Temp; for(a = 4; a >= 1 ; a--) { Temp = Value%10; Value = Value/10; LEDBuffer_1[a-1] = DISPTABLE[Temp]; } } //=========================================================================================== // Serially transmitt display data. //=========================================================================================== void ShiftData(unsigned char Data) { unsigned char i; STROBE = 0; DISPCLK = 0; DISPDATA = 0; for(i = 0; i < 8; i++) { if(Data & 0x01) DISPDATA = 1; else DISPDATA = 0; DISPCLK = 1; asm("nop"); asm("nop"); DISPCLK = 0; Data = Data >> 1; } asm("nop"); asm("nop"); STROBE = 0; DISPCLK = 0; DISPDATA = 0; } //=========================================================================================== // Enable strobe after data transmission //=========================================================================================== void EnableStrobe() { STROBE = 1; asm("nop"); asm("nop"); STROBE = 0; DISPCLK = 0; DISPDATA = 0; } //=========================================================================================== // Display Driving Routine //=========================================================================================== void Display() { switch(DgtSel) { case 1: ShiftData(LEDBuffer_1[4]); //display changed for dold ShiftData(0x80); EnableStrobe(); DgtSel = 2; break; case 2: ShiftData(LEDBuffer_1[5]); ShiftData(0x40); EnableStrobe(); DgtSel = 3; break; case 3: ShiftData(LEDBuffer_1[6]); ShiftData(0x20); EnableStrobe(); DgtSel = 4; break; case 4: Dec_pt=0; ShiftData(LEDBuffer_1[7]); ShiftData(0x10); EnableStrobe(); DgtSel = 5; break; //************************************************************************************************ case 5: ShiftData(LEDBuffer_1[0]); ShiftData(0x08); EnableStrobe(); DgtSel = 6; break; case 6: ShiftData(LEDBuffer_1[1]); ShiftData(0x04); EnableStrobe(); DgtSel = 7; break; case 7: ShiftData(LEDBuffer_1[2]); ShiftData(0x02); EnableStrobe(); DgtSel = 8; break; case 8: ShiftData(LEDBuffer_1[3]); ShiftData(0x01); EnableStrobe(); DgtSel = 1; break; default: break; } if(Blink_Count==1) { Dec_pt=1; //LEDBuffer_1[1]=LEDBuffer_1[1]&0X01; if(BLINKFLAG == 1 && DgtSel == BLINKSEGMENT) { BLINKCOUNT1++; if( BLINKCOUNT1>20) LEDBuffer_1[0] = DISPTABLE[26]; BLINKCOUNT1++; if(BLINKCOUNT1==50) { BLINKCOUNT1=0; LEDBuffer_1[0] = DISPTABLE[j]; } } } if(Blink_Count==2) { if(BLINKFLAG == 1 && DgtSel == BLINKSEGMENT) { BLINKCOUNT2++; if( BLINKCOUNT2>20) LEDBuffer_1[1] = DISPTABLE[26]; BLINKCOUNT2++; if(BLINKCOUNT2==50) { BLINKCOUNT2=0; LEDBuffer_1[1] = DISPTABLE[k]; } } } if(Blink_Count==3) { Dec_pt=1; if(BLINKFLAG == 1 && DgtSel == BLINKSEGMENT) { BLINKCOUNT3++; if( BLINKCOUNT3>20) LEDBuffer_1[2] = DISPTABLE[26]; BLINKCOUNT3++; if(BLINKCOUNT3==50) { BLINKCOUNT3=0; LEDBuffer_1[2] = DISPTABLE[l]; } } } if(Blink_Count==4) { if(BLINKFLAG == 1 && DgtSel == BLINKSEGMENT) { BLINKCOUNT4++; if( BLINKCOUNT4>20) LEDBuffer_1[3] = DISPTABLE[26]; BLINKCOUNT4++; if(BLINKCOUNT4==50) { BLINKCOUNT4=0; LEDBuffer_1[3] = DISPTABLE[m]; } } } } //******************************************************************************************** //// RUN_RESET FUNCTION //******************************************************************************************** void PRG_RUN_RESET() { Bottom_Value=0; } //********************************************************************************************** //// RESET KEY pressed //********************************************************************************************** void Key_CHK_RESET() { if(!RESET && !bits.KeyLock_RESET1) { // CHECK IF SELECT IS PRESSED Debounce++; if(Debounce > 10) { Debounce = 0; bits.KeyLock_RESET1 = 1; PRG_RUN_RESET(); } } else if(RESET && bits.KeyLock_RESET1) { bits.KeyLock_RESET1 = 0; Debounce = 0; } } //========================================================================== // Timer Interrupt - 5mSec //========================================================================== void interrupt isr(void) { asm("clrwdt"); if (TMR1IF) { TMR1IF = 0; // TMR1H = 0x3C; // TMR1L = 0xB0;100ms TMR1H = 0xFE; TMR1L = 0x0C;// timer interrupt for 1ms if(Top_Display>Bottom_Value) { Bottom_Value++; } else if(Top_Display==Bottom_Value) { } Display(); } } //=========================================================================== // Main program starts here. //=========================================================================== void main(void) { unsigned char value; unsigned char conter = 0; InitController(); while(1) { if(PRG_EN==1) { if(Main_Flag==1) { Main_Menu(5,17,18,17); if(Sub_Pulse==1) { SubMenu(12,14,5,20); } else if(Sub_Pulse==2) { SubMenu(16,0,24,17); } else if(Sub_Pulse==3) { SubMenu(24,0,5,17); } else { Sub_Pulse=0; } } Main_Flag=0; Process_PRG_MODE(); } else { Main_Flag=1; Process_RUN_MODE(); } } } //************************************************************************************************** // InitController //************************************************************************************************** void InitController() { PORTA = 0b00000000; TRISA = 0b00111000; TRISB =0b00001111; PORTB = 0b00000000; TRISC = 0X00; PORTC = 0b00000000; WREN=0; WDTCON = 0b00010111; INTEDG = 0; //falling edge INTF = 0; INTE = 1; WPUB = 0b00000000; ANSEL = 0b00000000; ADCON0 = 0b00000000; ANSELH = 0b00000000; ADDEN = 0; PIE1=0b00000001; PIR1=0x01; INTCON = 0xC0; T1CON=0X11; TMR1IE = 1; PEIE = 1; GIE = 1; LED_SS=0; } //************************************************************************************************** //RUN mode Selection //************************************************************************************************** void Process_RUN_MODE() { //Display_Faults(12,18,27,26,18,11,24,26); if(EEPROM_Read_Flag==1) { READ_EPROM(); EEPROM_Read_Flag=0; } Key_CHK_RESET(); if(LED_SS==0) { Dissect(Top_Display); Dissect_2(Bottom_Value); } else if(LED_MS==0) { Dissect(Top_Display); Dissect_2(Bottom_Value); } else if (LED_HM==0) { Dissect(Top_Display); Dissect_2(Bottom_Value); } }
Last edited by a moderator: