只能从PIC16的RCO端口读取一次

时间:2014-08-05 18:26:49

标签: c pic microchip

现在几天都在寻找答案。我正在尝试创建这个简单的验证程序,如果按下按钮,它会将RC0上的电压驱动到5伏,当按下按钮时,下拉电阻会将引脚拉低至0.问题是,代码只会在我第一次按下按钮时工作。之后它将不会进入if (RC0 == 1)循环。这是我的代码片段。我在这里缺少什么?

void main(void){
    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize I/O and Peripherals for application */
    InitApp();

    TRISB = 0x0F;         // turn on RB7 for use as output
    TRISC = 0xFF;         //  turn on RC0 for use as input
    ANSEL = 0b11101111;   //  use RC0 as digital input
    unsigned char time = 0;

    while (1) {
        //delay for 10 seconds
        if (PORTCbits.RC0 == 1) {
            while (time < 10) {
                /* TODO */
                RB7 = 1;
                __delay_ms(100);

                RB7 = 0;
                __delay_ms(100);
                time++;
            }
        }

        if (PORTCbits.RC0 == 0){ //This if statement will always execute when 
                                 //RC0 == 0, but will not execute when I push 
                                 //the button.  This really confuses me.  
                                 //Can RCO be given a value different than 1?
            __delay_ms(2000);
        }

        RB7 = 0;
        __delay_ms(500);
        RB7 = 1;
        __delay_ms(500);

    }

}

0 个答案:

没有答案