繁体   English   中英

pic24f的引脚上无输出

[英]No output on pins in pic24f

我无法让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

默认情况下,B4引脚为模拟引脚。 通过清除ANSB寄存器bit4将其配置为数字

注意:尽管清除DID位不能解决问题。 转移到另一个引脚(功能较少)确实如此。 因此,我(fossum)假设这至少在某种程度上是正确的答案。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM