romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
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 #include<pic.h> __CONFIG(WDTDIS & UNPROTECT); void main() { unsigned int x; TRISA2 = 0; PORTA = 0; while(1) { RA2 = 0; for(x=0; x<1000; x++); RA2 = 1; for(x=0; x<1000; x++); } }
__CONFIG(0x3F3A);
---------- Post added at 12:46 ---------- Previous post was at 12:44 ----------
In MPLAB, click configure >> configuration bits
There you can get the value according to your need.
I think this will work in your case.
__CONFIG(0x3F2A);
in high tech C there is inbuild delay routines...
---------- Post added at 15:52 ---------- Previous post was at 15:49 ----------
use
#define _XTAL_FREQ 20e6
(if 20MHz or edit that accordingly)
Now
Use
__delay_ms( );
Or
__delay_us( );
OPTION_REG = 0b0111; // prescale by 256
as I understand
PSA is assigned to timer0
PS2,PS1,PS0 is set to high to have a value of 256(according in the table)..
but why use this notation 1:256 ?? what does it mean?
what exactly the function of prescaler?
TOCS = 1 or 0 //clock source select bit.
does it mean if I set this to high I will need an external oscillator?
void interrupt timer0_isr(void)
{
if(reload == 0)
{
// effect a change on PORTB whenever our desired period is reached.
// Note this timing will contain a margin of error.
reload = RELOADS + 1;
seconds++;
PORTB++; // effect a change on PORTB
}
reload--;
T0IF = 0;
}
main()
{
// initialize timer 0;
OPTION_REG = 0b0111; // prescale by 256
T0CS = 0; // select internal clock
T0IE = 1; // enable timer interrupt
GIE = 1; // enable global interrupts
TRISB = 0; // output changes on LED
for(;;)
continue; // let interrupt do its job
}
hi ckshivaram, I understand now but needs more clarification about the theory..The CPU clock speed is the oscillator speed divided by four
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?