sachin95
Newbie level 3
hi,
i m new to pic programming.i used an example code in mikroC time calculator to make a 1 second interrupt. the problem is when i simulate it in protues, i can see that led blinking time is more than 1 second.why is that??
pls help
thanks.
this is the code
i m new to pic programming.i used an example code in mikroC time calculator to make a 1 second interrupt. the problem is when i simulate it in protues, i can see that led blinking time is more than 1 second.why is that??
pls help
thanks.
this is the code
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 //Timer interrupt: 25 ms //Desired Interrupt Time: 2.5 s //cnt value: 100 (2.5 s / 0.025 s) //MCU: PIC 16F887 //Internal module: Timer0 //Prescaler 1:256; TMR0 Preload = 61; Actual Interrupt Time = 24.96 ms unsigned cnt; // This is the counter variable which will extend desired period void InitTimer0(){ OPTION_REG = 0x87; // Prescaler 256 TMR0 = 61; INTCON = 0xA0; } void Interrupt(){ if (TMR0IF_bit){ cnt++; // Increment counter, this is the tweak we added in original Timer Calculator code TMR0IF_bit = 0; // Clear TMR0IF TMR0 = 61; // Prepare for next interrupt } } void main() { InitTimer0(); // Initialize Timer0 ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISB = 0; // PORTB is output PORTB = 0xFF; // Initialize PORTB cnt = 0; // Initialize cnt do { if (cnt >= 40) { // 1s PORTB = ~PORTB; // Toggle PORTB LEDs cnt = 0; // Reset cnt } } while(1); }
Last edited by a moderator: