+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Newbie level 3
    Points: 476, Level: 4

    Join Date
    May 2012
    Location
    USA
    Posts
    4
    Helped
    0 / 0
    Points
    476
    Level
    4

    Timer0 interrupts on PIC18F4620

    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:

    http://extremeelectronics.co.in/micr...ller-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 alexan_e; 18th May 2012 at 18:22. Reason: added SYNTAX tags

    •   Alt18th May 2012, 18:01

      advertising

        
       

  2. #2
    Advanced Member level 3
    Points: 4,828, Level: 16
    papunblg's Avatar
    Join Date
    Oct 2010
    Location
    Kolkata India
    Posts
    726
    Helped
    172 / 172
    Points
    4,828
    Level
    16
    Blog Entries
    9

    Re: Timer0 interrupts on PIC18F4620

    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/Da...viceConfig.pdf
    http://www.mikroe.com/eng/chapters/v...crocontroller/
    Rajsekhar Nag
    -------------..--------
    Knowledge Grows When Shared


    1 members found this post helpful.

--[[ ]]--