pic24f中的引脚无输出

时间:2014-02-02 03:28:23

标签: pic led mplab

我无法让我的pic24f04kl100打开LED。下面的代码尽可能简单,但仍然没有打开引脚6上的LED。

代码

#include <xc.h>

#define LED LATBbits.LATB4
#define LEDans ANSBbits.ANSB4
#define LEDtris TRISBbits.TRISB4

/* Setting up configuration bits */
_FOSCSEL(FNOSC_FRCPLL & IESO_OFF);  // FRC w/PLL and int./ext. switch disabled
_FOSC(POSCMD_XT & FCKSM_CSECMD);    // Pri. OSC XT mode and clk. switch on, fail-safe off
_FWDT(FWDTEN_OFF);                  // Watchdog timer off

void initialise();
void delay(int i);

void main() {                      // Main program loop
    initialise();                  // Intialise PIC
    while (1) {                    // Infinite loop
        LED = 1;                   // Set LED high
        LED = 0;                   // Set LED low
    }
}

void initialise() {                // Configures the PIC
    OSCCONbits.NOSC = 0b111;        // Fast RC Oscillator with Postscaler and PLL module
    delay(100);
    CLKDIVbits.RCDIV = 0b000;       // Set clock div 1:1
    delay(100);
    LEDans = 0;
    delay(100);
    LEDtris = 0;                    // Make LED an output
    delay(100);
    LED = 0;                        // Set LED low
}

void delay(int i) {
    while(i--);
}

PICkit 3输出

*****************************************************

Connecting to MPLAB PICkit 3...
Firmware Suite Version.....01.27.04
Firmware type..............dsPIC33F/24F/24H

Target detected
Device ID Revision = 0

The following memory area(s) will be programmed:
program memory: start address = 0x0, end address = 0x3ff
configuration memory

Programming...
Programming/Verify complete

2 个答案:

答案 0 :(得分:1)

默认情况下,B4引脚是模拟的。通过清零ANSB寄存器bit4

将其配置为数字

注意:虽然清除DID位不能解决问题。移动到另一个引脚(功能较少)。所以我(fossum)假设这至少在某种程度上是正确的答案。

答案 1 :(得分:0)

LED闪烁,但闪烁非常快,尝试在LED开启和LED关闭之间加一些延迟。

试试这个:

void main() { // Main program loop initialise(); // Intialise PIC while (1) { // Infinite loop LED = 1; // Set LED high delay(50000); //wait LED on time LED = 0; // Set LED low delay(50000); //wait LED off time } }