Timer2 of PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by ecaits, Jun 12, 2014.

  1. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    Dear Friends,

    I am working on TImer 2 of PIC16F877.

    Code is given below.

    Code ( (Unknown Language)):
    1.  
    2. void main()
    3. {
    4.     TRISB0 = 0;
    5.     RB0 = 0;
    6.     inittimer2();
    7.  
    8.     while(1)
    9.     {
    10.     }
    11. }
    12.  
    13. void inittimer2(void)
    14. {  
    15.     TMR2 = 0x00;
    16.     T2CON = 0x75;  // Prescaler 4, Postscaler
    17.     TMR2IF = 0;
    18.     TMR2IE = 1;
    19.     PR2 = 0xFF;
    20.    
    21. }
    22.  
    23. void interrupt ISR(void)
    24. {
    25.     if(TMR2IF)
    26.     {
    27.         RB0=~RB0;
    28.         TMR2IF=0;
    29.     }
    30. }
    31.  
    But this code is not working.
    Can anybody suggest what may be the problem???
     
    Last edited by a moderator: Jun 12, 2014
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Can you suggest what "not working" means?
     
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I don't see GIE nor PEIE (see INTCON register, page 24 of the datasheet) being set - these are required to use interrupts and use peripheral interrupts.

    Please put your code between some code tags ([ code]//code goes here[/code ] - without the spaces), as this allows the code to be formatted nicer by the forum software.
     
    ErnieM likes this.
Loading...