• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help Please. 16f887 can't read input

Status
Not open for further replies.

jkashiwada

New Member
Hi,

I'm having so much trouble with reading input on my 16f887. I have the following code and fuses...I run it and it just does not turn on the LED even when the pin is given a high.

INTOSC, WDT_OFF, PWRTE_ON, MCLRE_ON, CP_OFF, CPD_OFF, BOR_OFF, IESO_OFF, FCMEN_OFF, LVP_OFF, DEBUG_OFF

Code:
 void main() {
    ANSELH = 0;  //Turn off analog
    ANSEL = 0;

    PORTD = 0; // Clear PORT D
    PORTB = 0; // Clear PORT B
    
    TRISD = 0; // make PORT D output
    TRISB = 0xff; // Make PORT B input


    
    while (1) {
       if (PORTB,7==1) {    // check if RB7 is high
          PORTD = 0X01;     // if yes, turn on RD0
       }else{
          PORTD = 0;        // else turn off RD0
       }
    }
    
}
Please help!
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top