ahmed osama
Full Member level 6
- Joined
- Jul 18, 2004
- Messages
- 352
- Helped
- 2
- Reputation
- 4
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- Cairo, Egypt, Egypt
- Activity points
- 2,652
i have a Strange Problem with Timer1 on 18F4550 using PICKIT3 (internal CLock 8 Mhz after OscCon 100 became 1Mhz)
the following code working so fine as there is a led turned on at the starting ( PORTDbits.RD2 = 1 and after 30 sec , the timer1 will turn it off , it worked so fine but in cond. that while(1) must have inside it delay(); anything else the if cond. inside the timer1 ISR doesn't work at all
i tried the following
nothing makes the code run so well except when i use
sorry i am some how new to PIC programming so kindly help me
i also clear all mem , config bits ,....
i also cleared the project and rebuild it
the following code working so fine as there is a led turned on at the starting ( PORTDbits.RD2 = 1 and after 30 sec , the timer1 will turn it off , it worked so fine but in cond. that while(1) must have inside it delay(); anything else the if cond. inside the timer1 ISR doesn't work at all
i tried the following
Code:
while(1) { }
while(1);
while(1) { temp (); } //temp is just empty func.
for (1;;);
nothing makes the code run so well except when i use
Code:
while(1)
{
delay(); // !!!!!!
}
sorry i am some how new to PIC programming so kindly help me
i also clear all mem , config bits ,....
i also cleared the project and rebuild it
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 #include<p18f4550.h> #include<timers.h> void high_ISR (void); void timer1_isr(void); #pragma interrupt high_ISR //is already high void high_ISR (void) { _asm goto timer1_isr _endasm } void delay(void); int x; void timer1_isr(void) { x=x+1; if (x == 3750) { PORTDbits.RD2 = 0; x=0; } PIR1bits.TMR1IF = 0; //Reset Timer1 interrupt flag WriteTimer1(0xFC17); // Give new start value to the timer1 INTCONbits.GIEH =1; } void main(void) { x=0; INTCONbits.GIEH =1; TRISDbits.TRISD2 = 0; // set RB0 PORTDbits.RD2 = 1; // ON RB0 RCONbits.IPEN = 1; //Enable priority levels on interrupts RCONbits.SBOREN = 0; //Disable BOR IPR1bits.TMR1IP = 1; //Timer1 interrupt priority high PIE1bits.TMR1IE = 1; //Timer1 interrupt enable OpenTimer1( TIMER_INT_ON & // Interrupt enabled T1_16BIT_RW & //set timer1 as one 16-bit registers T1_SOURCE_INT & //choose internal clock source (TOSC) T1_PS_1_2 & // Prescale Value: 1:2 T1_OSC1EN_OFF & //Disable Timer1 oscillator T1_SYNC_EXT_OFF //Don’t sync external clock input ); WriteTimer1(0xFC17); // set start value of timer, while(1) { delay(); // must delay func. and thing else the if cond. in the timer1 isr doesn't work } } void delay(void) { int f, k; for(f=0; f < 1000 ; f++) for(k=0; k< 2 ; k++ ) { } }
Last edited by a moderator: