PIC Development Board with PK3

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Today I got PIC development board and just waiting for microcontroller

IMG_20200902_154114.jpg
 
Last edited by a moderator:

jpanhalt

Joined Jan 18, 2008
11,087
Some people plug the PICKit 3 directly into the board. NOTE: The pinout our your board will not allow that, unless the pinout you your clone is different than standard, which is:
1599135387921.png

MCLR and GND as are PGD and PGC on your development board are reversed. That will cause a problem.
 

jpanhalt

Joined Jan 18, 2008
11,087
Be sure the connecting wires are short. You may also need a capacitor between VCC and GND. When I used a genuine PK3, it needed 10 uF for a 12F1840 to program reliably.
 

trebla

Joined Jun 29, 2019
542
I see two electrolytic capacitors on the board, hopefully they do as intended. I have got issues with programming if supply capacitor is bigger than 100-200uF.
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
@JohnInTX & @trebla

I have written program to blink LED and its working fine

Hardware - PIC18F45K80. OS - windows 10
I am using MPLABX 5.40 and XC8 2.30.

C:
/*
 * File:   blink.c
 * Author: Embedded System
 */
#define _XTAL_FREQ 2000000
#include <xc.h>

// PIC18F45K80 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)

// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)

// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)

// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)

// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)

// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

void main(void) {
   TRISB = 0; //RB as Output Port
  
  while(1)
  {
    RB7 = 1;  // LED ON
    __delay_ms(1000); //  Delay
    RB7 = 0;  // LED OFF
    __delay_ms(1000); //  Delay
  } 
    return ;
}
I don't have idea How to use PK3 to debug program ?
 

JohnInTX

Joined Jun 26, 2012
4,787
I don't have idea How to use PK3 to debug program ?
What have you tried?
Debugging in MPLABX is similar to what you did with Keil 8051. Set breakpoints to run to a point, inspect registers, variables, step code line by line. PICkit 3 (if it conforms to Microchip specs) is the interface between MPLABX and your board. It's all described in Chapter 4 of the MPLABX manual.
MPLABX PDF Manual:
https://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en556757
PICkit 3:
https://www.microchip.com/Developmenttools/ProductDetails/PG164130

Study Study.
 
Last edited:

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
What have you tried?
I have debug code but I am not sure how much delay I am getting at line __delay_ms(1000); // Delay
C:
/*
 * File:   blink.c
 * Author: Embedded System
 *
 */
#define _XTAL_FREQ 2000000
#include <xc.h>

// PIC18F45K80 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)

// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)

// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)

// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)

// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)

// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)

// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)

// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

void main(void) {
   TRISB = 0; //RB as Output Port
  
  while(1)
  {
    RB7 = 1;  // LED ON
    __delay_ms(1000); //  Delay
    RB7 = 0;  // LED OFF
    __delay_ms(1000); //  Delay
  }
    
    
    return ;
}
Does line __delay_ms(1000); gives 200ms delay ?

1600822602558.png
 

jpanhalt

Joined Jan 18, 2008
11,087
The Microchip tools I use allow simulation (no hardware needed) and debugging with hardware (hardware required).

The former operating frequency is set in the simulator and one gets a report of both calculated elapsed time and calculated instruction cycles (Tcys) between whatever points in the program one chooses. If you set that simulator to the actual oscillator frequency, then the simulator times and observed times are pretty close.

Hardware debugging is similar, except the MCU's oscillator is used.

If what you (Djsarakar) are doing allows both modes, you need to know which mode. Since you say simulation I am assuming the former. Does your simulator allow setting the simulation frequency? That is not the speed with which it steps through the program; it's the effective speed of the MCU being simulated.

As an aside, with 16F midrange devices, I have found software simulation times to be quite accurate. Last week, however, I came across this thread on the Microchip forums: https://www.microchip.com/forums/m1152516.aspx
GeorgePauley (posts #'s 5 and 10) provided information about errors in simulation of which I was not aware. I mention that in case you try to compare hardware Tcy's to simulator values and find a mismatch.
 

JohnInTX

Joined Jun 26, 2012
4,787
Looks right.
1 cycle = 200ns is consistent with a 20MHz oscillator.
You programmed a 1 second delay and that's what you are getting.

EDIT: Interesting discussion on the MCHIP boards re: dsSPIC33. I've found the 18F sim to be accurate. But the hardware is always the final arbiter.
 
Top