1

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コンパイラで完全にコンパイルされましたが、期待どおりに動作しませんでした。問題は構成ビットにあるのでしょうか。これを解決する方法はありますか?

4

2 に答える 2

0

コントローラーとポートから判断すると、PIC18 Explorer ボードを使用していると思われます。その場合、ジャンパ JP1 が所定の位置にあることを確認してください。これは、オンボード LED を使用する場合に配置する必要があります。

このボードでない場合は、間違ったポートを使用している可能性がありますか? たとえば、ピキットと一緒に受け取った「ピン数の少ない」デモ ボードには、ポート D ではなくポート C に LED があります。

于 2011-11-07T15:32:50.593 に答える