PIC16f877a comparator module

Status
Not open for further replies.

sarge

Full Member level 3
Joined
Dec 29, 2009
Messages
187
Helped
57
Reputation
114
Reaction score
56
Trophy points
1,308
Visit site
Activity points
2,170
Hi, i have some problems with comparator in PIC16f877a

My code
Code:
#include <htc.h>
#include <stdio.h>

#define _XTAL_FREQ 4000000

__CONFIG(WDTDIS & UNPROTECT & LVPDIS & HS & BOREN);

void main()
{
    CMCON = 0x02;
    ADCON0 = 0xFF;
    ADCON1 = 0xFF;
    TRISB1 = 0;
    TRISB2 = 0;
    TRISA0 = 1;
    TRISA3 = 1;
    RB1 = 0;
    RB2 = 1;


    GIE = 1;
    PEIE = 1;
    CMIE = 1;

    while(1)
    {
        
    }

}

void interrupt isr()
{
    if (CMIF)
    {
        RB2 = !RB2;
        CMCON = 0x02;
        CMIF = 0;
    }
}

This code works fine in proteus, but doesn't work in hardware. What is wrong here?
Compiler - Hi-tech PICC 9.71.
Thanks for advance.
 

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…