Mar 25, 2012 #1 B bimalkamal Member level 1 Joined Nov 27, 2011 Messages 32 Helped 1 Reputation 2 Reaction score 1 Trophy points 1,288 Activity points 1,529 Please anyone tell me how many times in a minute the LEds of PORTB will blink? Or the delay time the mydelay() will create. 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 void mydelay(); void main() { OPTION_REG = 0x87; // Assign prescaler to TMR0 TRISB = 0; // PORTB is output PORTB = 0xFF; // Initialize PORTB TMR0 = 0; // Timer0 initial value while(1) { PORTB = ~PORTB; mydelay(); } } void mydelay() { unsigned int n=0; INTCON.TMR0IE=1; do{ while(!INTCON.TMR0IF); n++; if(n==76) { TMR0IE_bit=0; n=0; INTCON.TMR0IF=0; break; } }while(1); } ---------- Post added at 00:21 ---------- Previous post was at 00:16 ---------- Crystal=20Mhz
Please anyone tell me how many times in a minute the LEds of PORTB will blink? Or the delay time the mydelay() will create. 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 void mydelay(); void main() { OPTION_REG = 0x87; // Assign prescaler to TMR0 TRISB = 0; // PORTB is output PORTB = 0xFF; // Initialize PORTB TMR0 = 0; // Timer0 initial value while(1) { PORTB = ~PORTB; mydelay(); } } void mydelay() { unsigned int n=0; INTCON.TMR0IE=1; do{ while(!INTCON.TMR0IF); n++; if(n==76) { TMR0IE_bit=0; n=0; INTCON.TMR0IF=0; break; } }while(1); } ---------- Post added at 00:21 ---------- Previous post was at 00:16 ---------- Crystal=20Mhz
Mar 25, 2012 #2 andre_luis Super Moderator Staff member Joined Nov 7, 2006 Messages 9,605 Helped 1,190 Reputation 2,399 Reaction score 1,212 Trophy points 1,403 Location Brazil Activity points 55,727 You can achieve a precise answer by some simulation tools. Take in mind that not only Scaler and Pre-scaler are accounted, but also amount of instructions processed before timer register reload. +++
You can achieve a precise answer by some simulation tools. Take in mind that not only Scaler and Pre-scaler are accounted, but also amount of instructions processed before timer register reload. +++