1
\$\begingroup\$

I received my PicKit4 and some uCs. Since my only PDIP package is a PIC18F4680 I want to test the programmer and MPLAB IDE with it. I set the board following this tutorial. I loaded an template project (pic18_c_template) and configured the properties for my uC.

Since I was not able to find the grid view to set the datapin (like in the video), I wanted to configure a digital pin as a blinking LED. I found some example code for the right registers.

******************************************************************************/
/* Files to Include */
/******************************************************************************/

#if defined(__XC)
    #include <xc.h> /* XC8 General Include File */
#elif defined(HI_TECH_C)
    #include <htc.h> /* HiTech General Include File */
#elif defined(__18CXX)
    #include <p18cxxx.h> /* C18 General Include File */
#endif

#if defined(__XC) || defined(HI_TECH_C)

#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */

#endif

#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */

/******************************************************************************/
/* User Global Variable Declaration */
/******************************************************************************/

/* i.e. uint8_t <variable_name>; */

/******************************************************************************/
/* Main Program */
/******************************************************************************/



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

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

    /* TODO <INSERT USER APPLICATION CODE HERE> */

    TRISB0 = 0;

    while(1) {
        RB0 = 1;
        _delay(1000); // 1 Second Delay
        RB0 = 0; // LED OFF
        _delay(1000); // 1 Second Delay
    }

}

Uploading the program was apparently no problem

[\[code\]Connecting to MPLAB PICkit 4...

Currently loaded versions:
Application version............00.05.41
Boot version...................01.00.00
Script version.................00.03.33
Script build number............0540a22e50
PICkit 4 is supplying power to the target (3.30 volts).
Target device PIC18F4680 found.
Device Revision Id = 0x7

Calculating memory ranges for operation...

Erasing...

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

Programming/Verify complete\[/code\]]

but the load on RB0 (pin 33) is not blinking. My guess is that I need to connect an oscillator to time the delay, but shouldnt the LED blink regardless? (At least in some intervals).

Also the programmers led strip is yellow, which means 'programming'. But shoudnt the program process be completed?

\$\endgroup\$
1
\$\begingroup\$

Have a look at your configuration bits. (could be done in MPLABX)
You had to activate the internal oszillator (FOSC-Bits)

#pragma config OSC = IRCIO6

You also had to select the Pins as digital (default state is analog)

ADCON1 = 0x3F;
\$\endgroup\$
6
  • \$\begingroup\$ This might be it. I still keep digging through the datasheet and the available registers. I will also try to install the 'Code configurator' and there the registers and Pins should be more visible. Sadly the MPlab IDE has no direct reference to the Pins and registervalues. Usually I open the header files of the projects configuration used by the compiler. \$\endgroup\$ – v3xX Dec 17 '19 at 7:36
  • \$\begingroup\$ MCC is pretty easy to use. You can do all your configuration there. But your code should work with the internal oscillator switched on. \$\endgroup\$ – Mike Dec 17 '19 at 12:47
  • \$\begingroup\$ Thanks for the effort everyone. I will try it when I get back to the lab \$\endgroup\$ – v3xX Dec 17 '19 at 13:16
  • \$\begingroup\$ IRCIO6 gives an 'unnown configuration' error. I cannot find this register in the datasheet. I also tried INTIO1 (internal oscillator p.25) -> 'unknown register' \$\endgroup\$ – v3xX Dec 17 '19 at 20:02
  • \$\begingroup\$ With the help of @mike i was able to find the right register value looking in the register configurator > #pragma config OSC = IRCIO67 selects the internal oscillator. My LED now lights up but doesnt seem to implement the desired delay (Pin RB0 is always HIGH). No timeout occurs. \$\endgroup\$ – v3xX Dec 17 '19 at 20:26
1
\$\begingroup\$

You need to use LATBbits.LATB0 instead of B0.

while(1) {
    LATBbits.LATB0 = 1;
    _delay(1000); // 1 Second Delay
    LATBbits.LATB0 = 0; // LED OFF
    _delay(1000); // 1 Second Delay
}
\$\endgroup\$
1
  • \$\begingroup\$ Still nothing. I also connected both Vss and Vdd, which I missed. My osci confirms that all pins are of low (except the supply and pin1) \$\endgroup\$ – v3xX Dec 16 '19 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.