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.

Problem in Timer2 of PIC16F877 using hi-tech C

Status
Not open for further replies.

ecaits

Member level 4
Member level 4
Joined
Jan 16, 2014
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
579
Dear Friends,

I am working on TImer 2 of PIC16F877.

Code is given below.


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
void main()
{
    TRISB0 = 0;
    RB0 = 0;
    inittimer2();
 
    while(1)
    {
    }
}
 
void inittimer2(void)
{   
    TMR2 = 0x00;
    T2CON = 0x75;  // Prescaler 4, Postscaler 
    TMR2IF = 0;
    TMR2IE = 1;
    PR2 = 0xFF;
    
}
 
void interrupt ISR(void)
{
    if(TMR2IF)
    {
        RB0=~RB0;
        TMR2IF=0;
    }
}



But this code is not working.
Can anybody suggest what may be the problem???
 
Last edited by a moderator:

GIE ( Global interrupt enable )must be enabled
 

As allready said in previous post,
if you add PEIE et GIE bit, your code (interrupt) is working
Code:
  Init_Timer2() ;
  PEIE_bit=1;
  GIE_bit=1;

but if your FOSC or Quartz value..
is too high you can't see blinking of the led...

blinking detection ok at 10Mhz ,even not very evident
At 20Mhz not sure..
at 4MHz must be evident.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top