MPLAB 上的 LED 闪烁不工作?

发布于 2024-12-14 09:38:56 字数 2964 浏览 2 评论 0原文

我正在使用 MPLAB 对我的新微芯片板进行编程,并使用 pickit3 代码对其进行编程

// Include the necessary device header file
#include <p18f8722.h>



#pragma config OSC = HSPLL, //OSCS = OFF // HS-PLL Enabled, Internal External Osc. Switch Over OFF Disabled
#pragma config PWRT = OFF // Power Up Timer: OFF Disabled
//#pragma config BOR = OFF, BORV = 25 // Brown Out Reset: OFF, Brown Out Voltage: OFF Disabled
#pragma config WDT = OFF, WDTPS = 128 // Watchdog Timer: OFF Disabled, Watchdog Postscaler: 1:128
//#pragma config CCP2MUX = OFF // CCP2 Mux: OFF Disabled (RB3)
//#pragma config STVR = OFF // Stack Overflow Reset: OFF Disabled
#pragma config LVP = OFF // Low Voltage ICSP:OFF Disabled
#pragma config DEBUG = ON // Background Debugger Enable: OFF Disabled
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // Code Protection Block 0-3: OFF Disabled
#pragma config CPB = OFF // Boot Block Code Protection: OFF Disabled
#pragma config CPD = OFF // Data EEPROM Code Protection: OFF Disabled
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // Write Protection Block 0-3: OFF Disabled
#pragma config WRTB = OFF // Boot Block Write Protection: OFF Disabled
#pragma config WRTC = ON // Configuration Register Write Protection: OFF Disabled
#pragma config WRTD = OFF // Data EEPROM Write Protection: OFF Disabled
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // Table Read Protection Block 0-3: OFF Disabled
#pragma config EBTRB = OFF // Boot Block Table Read Protection: OFF Disabled




// Function prototypes
void delay1(void);

// Main code section. Execution starts here.
void main(void){
 // First some setup code for the LED
 // The LED will be driven by port D, bit 0, driving the anode, cathode to ground

 // First we should clear the port D, bit 0 data latch
 LATDbits.LATD0=0;

 // We need to set port D, bit 0 as an output
 // Using TRISDbits instead of TRISD allows isolating a single bit leaving the other bits unchanged
 TRISDbits.TRISD1=0; // 0 = output, 1 = input

 // Set port D, bit 0 to off (driving the LED anode, cathode to ground)
 PORTDbits.RD1=0;

 // LED blinking loop that never ends since '1' never changes
 while(1){
 PORTDbits.RD1=1; // turn the LED on
 delay1(); // call the delay function
 PORTDbits.RD1=0; // turn the LED off
 delay1(); // call the delay function
 }
 // end of main, but we will never get this far (endless loop)
}

// Start of our functions
void delay1(void){
 /*
 It is important to note that all variable declarations need to be placed before any code in
 a function or the build will fail. 
 */
 // declare a long integer and set it to zero
 long int loop1=0;

 // count from zero to 30,000 then continue on
 // Lower than 30000 for a faster blink, higher for a slower blink.
 for(loop1=0;loop1<=30000;loop1++){


 }
 // The loop is done and execution has moved past the loop
}

该代码没有执行任何操作,它在高科技 C 编译器上完美编译,但没有按预期运行, 也许问题出在配置位上?知道如何解决这个问题吗?

am using MPLAB to program my new microchip board and programming it programming it using pickit3

code:

// Include the necessary device header file
#include <p18f8722.h>



#pragma config OSC = HSPLL, //OSCS = OFF // HS-PLL Enabled, Internal External Osc. Switch Over OFF Disabled
#pragma config PWRT = OFF // Power Up Timer: OFF Disabled
//#pragma config BOR = OFF, BORV = 25 // Brown Out Reset: OFF, Brown Out Voltage: OFF Disabled
#pragma config WDT = OFF, WDTPS = 128 // Watchdog Timer: OFF Disabled, Watchdog Postscaler: 1:128
//#pragma config CCP2MUX = OFF // CCP2 Mux: OFF Disabled (RB3)
//#pragma config STVR = OFF // Stack Overflow Reset: OFF Disabled
#pragma config LVP = OFF // Low Voltage ICSP:OFF Disabled
#pragma config DEBUG = ON // Background Debugger Enable: OFF Disabled
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // Code Protection Block 0-3: OFF Disabled
#pragma config CPB = OFF // Boot Block Code Protection: OFF Disabled
#pragma config CPD = OFF // Data EEPROM Code Protection: OFF Disabled
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // Write Protection Block 0-3: OFF Disabled
#pragma config WRTB = OFF // Boot Block Write Protection: OFF Disabled
#pragma config WRTC = ON // Configuration Register Write Protection: OFF Disabled
#pragma config WRTD = OFF // Data EEPROM Write Protection: OFF Disabled
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // Table Read Protection Block 0-3: OFF Disabled
#pragma config EBTRB = OFF // Boot Block Table Read Protection: OFF Disabled




// Function prototypes
void delay1(void);

// Main code section. Execution starts here.
void main(void){
 // First some setup code for the LED
 // The LED will be driven by port D, bit 0, driving the anode, cathode to ground

 // First we should clear the port D, bit 0 data latch
 LATDbits.LATD0=0;

 // We need to set port D, bit 0 as an output
 // Using TRISDbits instead of TRISD allows isolating a single bit leaving the other bits unchanged
 TRISDbits.TRISD1=0; // 0 = output, 1 = input

 // Set port D, bit 0 to off (driving the LED anode, cathode to ground)
 PORTDbits.RD1=0;

 // LED blinking loop that never ends since '1' never changes
 while(1){
 PORTDbits.RD1=1; // turn the LED on
 delay1(); // call the delay function
 PORTDbits.RD1=0; // turn the LED off
 delay1(); // call the delay function
 }
 // end of main, but we will never get this far (endless loop)
}

// Start of our functions
void delay1(void){
 /*
 It is important to note that all variable declarations need to be placed before any code in
 a function or the build will fail. 
 */
 // declare a long integer and set it to zero
 long int loop1=0;

 // count from zero to 30,000 then continue on
 // Lower than 30000 for a faster blink, higher for a slower blink.
 for(loop1=0;loop1<=30000;loop1++){


 }
 // The loop is done and execution has moved past the loop
}

this code didn't do anything , it compiled perfectly on high tech C compiler but it didn't workout as it was expected ,
maybe the problem is in the configuration bit ? any idea how to solve this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

來不及說愛妳 2024-12-21 09:38:56

从控制器和端口来看,我猜测您使用的是 PIC18 Explorer 板。如果是这样,请验证跳线 JP1 是否就位。使用板载 LED 时必须安装到位。

如果不是这块板,那么您是否使用了错误的端口?例如,我随 pickit 收到的“低引脚数”演示板的 LED 位于端口 C,而不是 D。

Judging by the controller and port, I am guessing that you are using the PIC18 Explorer board. If so, please verify that jumper JP1 is in place. This must be in place when using the onboard LED's.

If it is not this board, then could you be using the wrong port? For instance, the "low pin count" demo board I received with my pickit has the LED's on port C, not D.

没有伤那来痛 2024-12-21 09:38:56

检查该引脚是否也具有模拟功能 (ANx)。

如果是这种情况,模拟是默认设置,您无法驱动引脚。您应该首先将其设置为数字模式。

Check if that pin also has an analog capability (ANx).

If it's the case, analog is the default setting and you cannot drive the pin. You should set it in digital mode first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文