+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Member level 5
    Points: 1,473, Level: 8

    Join Date
    Mar 2010
    Location
    Pakistan
    Posts
    83
    Helped
    1 / 1
    Points
    1,473
    Level
    8

    PIC16F84A code with HI-TECH C Compiler

    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;
        }
    }

    •   AltAdvertisement

        
       

  2. #2
    Full Member level 5
    Points: 3,560, Level: 14
    Achievements:
    7 years registered

    Join Date
    Feb 2007
    Location
    33 N, 73 E
    Posts
    255
    Helped
    37 / 37
    Points
    3,560
    Level
    14

    Re: PIC16F84A code with HI-TECH C Compiler

    where are the configurations bits?



    •   AltAdvertisement

        
       

  3. #3
    Member level 5
    Points: 1,473, Level: 8

    Join Date
    Mar 2010
    Location
    Pakistan
    Posts
    83
    Helped
    1 / 1
    Points
    1,473
    Level
    8

    Re: PIC16F84A code with HI-TECH C Compiler

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

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



    •   AltAdvertisement

        
       

  4. #4
    Full Member level 2
    Points: 2,666, Level: 12

    Join Date
    Mar 2006
    Posts
    135
    Helped
    13 / 13
    Points
    2,666
    Level
    12

    Re: PIC16F84A code with HI-TECH C Compiler

    Quote Originally Posted by zia.newversion View Post
    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;
        }
    }
    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.



--[[ ]]--