[SOLVED] PIC16F84A code with HI-TECH C Compiler

Status
Not open for further replies.

zia.newversion

Member level 5
Joined
Mar 28, 2010
Messages
83
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Pakistan
Activity points
2,188
Why shouldn't this code work?

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
#include <htc.h>
 
void main (void)
{
    TRISA   =   0x00;
    TRISB   =   0x00;
    PORTA   =   0x00;
    PORTB   =   0x00;
    OPTION  =   0x07;
 
    RBPU    =   0;
    T0IE    =   1;
    INTEDG  =   1;
    GIE     =   0;
 
    while(1)
    CLRWDT();
}
 
static void interrupt ISR()
{
    if(T0IF && T0IE)
    {
        T0IF    = 0;
        PORTA   = ~PORTA;
    }
}

 

0x3FF4
OSC=LP
WDT=ON
PWRTE=ON
CDP=OFF

But I can't imagine how that's important.
 


First off, your GIE should be 1 in the main. WHen GIE =0, global interrupt is off. Second, check your if conditions (if(T0IF && T0IE)). normally, its only the flag that needs to be checked. then you set the enable line inside the code and reset the flag as well. Third, i think (not sure on this), the main program should make sure it will run as continuous loop to as to allow interrupt to trigger whenever the flag is set. Also check your TMRO registers. it seems its not included in your initialization. Hope this helps.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…