Hi! I have been looking around the internet the last few days trying to find a good example on how to use the timer0 interrupt on a PIC18f4620. I am using MPLAB 8.85 and the Hi tech C compiler version 9.80. The problem I'm running into is that the examples online are meant for the older version of the compiler. My compiler doesn't like __CONFIG but tells me to use __PROG_CONFIG. It will compile but the code doesn't work. Also, could somebody explain what is happening in the "chip settings"? I have no idea what is going on there. Is there a easier way to write those settings that is more understandable? Lastly, will those setting work for the 18F4620 when the code was meant for a 18f4520? Sorry if this is a bit confusing. I can hopefully clarify more if need be. Thanks!
#include <htc.h>//Chip Settings
__CONFIG(1,0x0200);
__CONFIG(2,0X1E1F);
__CONFIG(3,0X8100);
__CONFIG(4,0X00C1);
__CONFIG(5,0XC00F);unsignedchar counter=0;//Overflow countervoid main(){//Setup Timer0
T0PS0=1;//Prescaler is divide by 256
T0PS1=1;
T0PS2=1;
PSA=0;//Timer Clock Source is from Prescaler
T0CS=0;//Prescaler gets clock from FCPU (5MHz)
T08BIT=1;//8 BIT MODE
TMR0IE=1;//Enable TIMER0 Interrupt
PEIE=1;//Enable Peripheral Interrupt
GIE=1;//Enable INTs globally
TMR0ON=1;//Now start the timer!//Set RB1 as output because we have LED on it
TRISB&=0B11111101;while(1);//Sit Idle Timer will do every thing!}//Main Interrupt Service Routine (ISR)void interrupt ISR(){//Check if it is TMR0 Overflow ISRif(TMR0IE && TMR0IF){//TMR0 Overflow ISR
counter++;//Increment Over Flow Counterif(counter==76){//Toggle RB1 (LED)if(RB1==0)
RB1=1;else
RB1=0;
counter=0;//Reset Counter}//Clear Flag
TMR0IF=0;}}
Enter config bits, or, as they used to be called, config fuses. Back in the days when microcontrollers were program-once devices, you really did blow a fuse in order to program them. Today, most micros have flash memory that can be programmed tens of thousands of times, but there are still one-time-programmable (OTP) devices about.
In any case, there’s a bunch of “config words” that define how the micro is going to behave from the get-go. Let’s look at some of these options. We’ll choose the Microchip PIC18F2620 as an example, but while the names may change, you'll find similar sorts of options available for Atmel AVR micros as well. [See more http://embeddedadventures.com/pages/p/Tutorials/id/43 ]