Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Timer0 interrupts on PIC18F4620

Status
Not open for further replies.

NNX

Newbie level 3
Joined
May 18, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
USA
Activity points
1,327
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/



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:

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 ]

Also see

http://www.edutek.ltd.uk/Binaries/Datasheets/Micro/PICDeviceConfig.pdf
**broken link removed**
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top