NNX
Newbie level 3

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!
This is the example code I'm working with from:
https://extremeelectronics.co.in/mi...o-pic18s-timers-pic-microcontroller-tutorial/
This is the example code I'm working with from:
https://extremeelectronics.co.in/mi...o-pic18s-timers-pic-microcontroller-tutorial/
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 #include <htc.h> //Chip Settings __CONFIG(1,0x0200); __CONFIG(2,0X1E1F); __CONFIG(3,0X8100); __CONFIG(4,0X00C1); __CONFIG(5,0XC00F); unsigned char counter=0;//Overflow counter void 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 ISR if(TMR0IE && TMR0IF) { //TMR0 Overflow ISR counter++; //Increment Over Flow Counter if(counter==76) { //Toggle RB1 (LED) if(RB1==0) RB1=1; else RB1=0; counter=0; //Reset Counter } //Clear Flag TMR0IF=0; } }
Last edited by a moderator: