Lipton2
Newbie level 4
- Joined
- Jun 6, 2014
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 55
Hello guys!
I have been struggeling with this problem for hours now and i can't seem to get it fixed.
Maybe it is just is simple mistake, but i hope you can help me.
I am trying to make a simple interrupt with a PIC16F690 that blinks a LED every second.
As you can see i first declared all the INTCON en OPTION registers that were needed.
And since i have a default internal oscillator of 4Mhz I used a Fosc of 1 Mhz to calculate the count of overflows.
But when i program my device, instead of 1, all four LED's are on and they are not blinking.
What is wrong?
I hope you can help me!
Thanks in advance!
Oh btw, I use the XC8 compiler
I have been struggeling with this problem for hours now and i can't seem to get it fixed.
Maybe it is just is simple mistake, but i hope you can help me.
I am trying to make a simple interrupt with a PIC16F690 that blinks a LED every second.
As you can see i first declared all the INTCON en OPTION registers that were needed.
And since i have a default internal oscillator of 4Mhz I used a Fosc of 1 Mhz to calculate the count of overflows.
But when i program my device, instead of 1, all four LED's are on and they are not blinking.
What is wrong?
I hope you can help me!
Thanks in advance!
Oh btw, I use the XC8 compiler
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 #include <htc.h> #include <pic16f690.h> unsigned char counter=0;//Overflow counter //void interrupt ISR(void); void main() { //Setup Timer0 OPTION_REGbits.PS0=1; //Prescaler is divide by 256 OPTION_REGbits.PS1=1; OPTION_REGbits.PS0=1; OPTION_REGbits.PSA=0; //Timer Clock Source is from Prescaler OPTION_REGbits.T0CS=0; //Prescaler gets clock from FCPU (1MHz) INTCONbits.T0IE=1; //Enable TIMER0 Interrupt INTCONbits.T0IF=0; INTCONbits.PEIE=1; //Enable Peripheral Interrupt INTCONbits.GIE=1; //Enable INTs globally TRISC=0; while(1) { }; } //Main Interrupt Service Routine (ISR) void interrupt ISR () { //Check if it is TMR0 Overflow ISR if(INTCONbits.T0IE && INTCONbits.T0IF) { counter ++; if (counter == 15) { PORTCbits.RC0; counter = 0; } INTCONbits.T0IF=0; } }
Last edited by a moderator: