Author Topic: Help! How to program PIC microcontrollers using MPlab X IDE?  (Read 16956 times)

0 Members and 1 Guest are viewing this topic.

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Help! How to program PIC microcontrollers using MPlab X IDE?
« on: March 20, 2017, 09:45:53 am »
hello everyone,
UPDATE:
if anybody have any questions on this topic they can ask it in this thread.
-------------------------------------------------------------------------------------
I have been trying to program PIC16F77 ; see datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/30325b.pdf

I'm programming this device using a pickit3 and XC8 compiler toolchain in Mplab X IDE, and so far I'm not able to make the PIC do anything, not even blinking LEDs or reading inputs from a switch...

this is a picture of the code in the Main.c file and below it is what i saw at the output window:
« Last Edit: March 31, 2017, 04:23:28 am by ali6x944 »
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #1 on: March 20, 2017, 10:41:38 am »
It says that the IDE can't connect to the programmer.

Did you try running the MPLABX Driver switching tool?

It should have been installed along with the IDE.

If no shortcut exists you can find it:
C:\Program Files (x86)\Microchip\MPLABX\v3.XX\Switcher

Where 3.XX is the version of the IDE installed.

Inside there will be a 32 or 64 bit folder, and inside there will be a file called MPDDSwitch64.exe (or 32 depending on version).

Note, this only applies if you have both MPLABX and MPLAB IDE installed.
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #2 on: March 20, 2017, 10:58:50 am »
It says that the IDE can't connect to the programmer.

Did you try running the MPLABX Driver switching tool?

It should have been installed along with the IDE.

If no shortcut exists you can find it:
C:\Program Files (x86)\Microchip\MPLABX\v3.XX\Switcher

Where 3.XX is the version of the IDE installed.

Inside there will be a 32 or 64 bit folder, and inside there will be a file called MPDDSwitch64.exe (or 32 depending on version).

Note, this only applies if you have both MPLABX and MPLAB IDE installed.
is it this; see picture below:
also what should i do with it?
 

Offline jmag999

  • Contributor
  • Posts: 41
  • Country: us
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #3 on: March 20, 2017, 11:22:49 am »
It looks like you have both the IDE and IPE open at the same time.  Try closing the MPLAB IPE as it may be connected to the debugger.
 
The following users thanked this post: ali6x944

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13728
  • Country: gb
    • Mike's Electric Stuff
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #4 on: March 20, 2017, 11:26:24 am »
I don't think the driver switcher is needed for PICKit 3
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #5 on: March 20, 2017, 11:38:35 am »
It looks like you have both the IDE and IPE open at the same time.  Try closing the MPLAB IPE as it may be connected to the debugger.
I closed Both the IDE & IPE
NOTE: 
that was to open the switcher.
« Last Edit: March 20, 2017, 11:48:12 am by ali6x944 »
 

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #6 on: March 20, 2017, 12:03:23 pm »
did i make a mistake in the code?
i have to say I'm  a newbie in the PIC microcontollers stuff, but i would really want to know how to use them... :)
« Last Edit: March 20, 2017, 12:13:25 pm by ali6x944 »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12852
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #7 on: March 20, 2017, 01:19:42 pm »
You haven't configured the oscillator, and your _XTAL_FREQ #define indicates you probably are attempting to use a 32.768KHz watch crystal, so I'd bet the oscillator isn't running.  See datasheet FIGURE 12-3: RC OSCILLATOR MODE
and try it with a 100pF capacitor and a 10K resistor, which should get it runing at approximately 2MHz.   Once you have satisfied yourself that you can run code on it, you can reconfigure it for LP mode and try the watch crystal again, in the FIGURE 12-1: CRYSTAL/CERAMIC RESONATOR OPERATION (HS, XT OR LP OSC CONFIGURATION) circuit.

To get the configuration right use the MPLAB  X wizard: View and Set Configuration Bits.
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #8 on: March 20, 2017, 01:38:35 pm »
You haven't configured the oscillator, and your _XTAL_FREQ #define indicates you probably are attempting to use a 32.768KHz watch crystal, so I'd bet the oscillator isn't running.  See datasheet FIGURE 12-3: RC OSCILLATOR MODE
and try it with a 100pF capacitor and a 10K resistor, which should get it runing at approximately 2MHz.   Once you have satisfied yourself that you can run code on it, you can reconfigure it for LP mode and try the watch crystal again, in the FIGURE 12-1: CRYSTAL/CERAMIC RESONATOR OPERATION (HS, XT OR LP OSC CONFIGURATION) circuit.

To get the configuration right use the MPLAB  X wizard: View and Set Configuration Bits.
see picture below:
 

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #9 on: March 20, 2017, 01:41:36 pm »
 I will change it to a RC oscillator, as u suggested...
just give me a few minutes...
 

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #10 on: March 20, 2017, 01:51:24 pm »
i have changed it but still the code out of the config bit did not change.
see picture:
 

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #11 on: March 20, 2017, 01:57:21 pm »
i will remove the #define _XTAL_FREQ 32768...
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13728
  • Country: gb
    • Mike's Electric Stuff
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #12 on: March 20, 2017, 01:58:06 pm »
From memory I think on that part there is no internal RC osc, so if you config as RC you need to add an external RC.

Any reason you're using such an old part?

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #13 on: March 20, 2017, 02:18:04 pm »
From memory I think on that part there is no internal RC osc, so if you config as RC you need to add an external RC.

Any reason you're using such an old part?


true, it probly dose not have an internal RC type oscillator despite  it saying in 5.0 TIMER0 MODULE the following:
The Timer0 module timer/counter has the following
features:
• 8-bit timer/counter
• Readable and writable
• 8-bit software programmable prescaler
Internal or external clock select
• Interrupt on overflow from FFh to 00h
• Edge select for external clock
   

i think there is no relation with whither the chip has an internal oscillator or not,  however this is rather confusing  :-//
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12852
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #14 on: March 20, 2017, 02:19:56 pm »
If setting the oscillator in the CONFIG wizard didn't generate a matching #pragma config line, its probably a bug and you should add:
Code: [Select]
#pragma config FOSC = LPmanually to your program if you want to use the watch crystal.
IIRC it will default to ext. RC mode, but you should still add a line for it, if you are using it:
Code: [Select]
#pragma config FOSC = RC
It will do sweet F.A if you don't provide external oscillator components as per fig 12-1, 12-2 or 12-3 with corresponding FOSC setting,  and also a pullup to Vdd on /MCLR - 10K is a good choice.
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #15 on: March 20, 2017, 02:33:41 pm »
Any reason you're using such an old part?
It is one of the cheapest and powerful chips in the one of the few electronics in the eastern province...
 

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #16 on: March 20, 2017, 03:22:42 pm »
i add it give me a couple of minuets to test the circuit...
see code below:
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13728
  • Country: gb
    • Mike's Electric Stuff
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #17 on: March 20, 2017, 03:30:31 pm »
You need to fix that programmer issue before even looking at code issues.
Try a reboot.

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: ali6x944

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7725
  • Country: ca
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #18 on: March 20, 2017, 03:59:58 pm »
I don't think his PC is even seeing the PICkit3 programmer.  Are you sure your PICkit3 is directly connected to your PC's USB 2.0 Port?  No USB extension cable, no USB hub.
 
The following users thanked this post: ali6x944

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13728
  • Country: gb
    • Mike's Electric Stuff
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #19 on: March 20, 2017, 04:01:47 pm »
I don't think his PC is even seeing the PICkit3 programmer.  Are you sure your PICkit3 is directly connected to your PC's USB 2.0 Port?  No USB extension cable, no USB hub.
Does it appear in Device manager?
Does it work with MPLABX IPE ?
I've seen issues with PICKit3 on hubs

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #20 on: March 20, 2017, 04:30:31 pm »
I don't think his PC is even seeing the PICkit3 programmer.  Are you sure your PICkit3 is directly connected to your PC's USB 2.0 Port?  No USB extension cable, no USB hub.
Does it appear in Device manager?
Does it work with MPLABX IPE ?
I've seen issues with PICKit3 on hubs


well it works in the IPE, but i can not see it in the device manager...
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13728
  • Country: gb
    • Mike's Electric Stuff
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #21 on: March 20, 2017, 04:34:19 pm »
That confirms that the hardware and connection to chip is OK.
Looks like some sort of USB driver issue stopping MPLABX talking to it.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: ali6x944

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 825
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #22 on: March 20, 2017, 04:35:55 pm »
BlinkLed Dashboard - click Refresh Debug Tool Status (second icon down) - will show various pickit3 info if connected
or click Project Properties icon (first one) - if pickit3 listed with no serial number- not connected
(also make sure project set to use the pickit3)

It looks like it has been connected properly at one time, otherwise there would be no pickit3 serial number listed.
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: sa
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #23 on: March 20, 2017, 04:52:57 pm »
BlinkLed Dashboard - click Refresh Debug Tool Status (second icon down) - will show various pickit3 info if connected
or click Project Properties icon (first one) - if pickit3 listed with no serial number- not connected
(also make sure project set to use the pickit3)

It looks like it has been connected properly at one time, otherwise there would be no pickit3 serial number listed.

see what i saw:
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 825
Re: Help! How to program PIC microcontrollers using MPlab X IDE?
« Reply #24 on: March 20, 2017, 05:36:54 pm »
If pickit3 serial# is listed in project properties, it is seen by MPLABX (you can verify- disconnect pickit3, open project properties- pickit3 will be listed with no serial#).

Your previous errors indicate MPLABX is not communicating with the pickit3, but also note there is a setting in the project properties for the pickit3 to provide power to your circuit- if you are using the pickit3 to provide power and have not enabled that setting, MPLABX will communicate with the pickit3 ok but the pickit3 will complain that it can't talk to the chip (which does not appear to be happening to you, yet )

I would disconnect the pickit3 connections on the 6pin header, then try to program- it will fail of course, but you should see communications happening between MPLABX and pickit3. (I'm not sure what, if anything could go wrong  if connecting the pins incorrectly, but this would eliminate that possibility).

You may need to Google 'PICkit3PlatformTool' (part of your error message)- I'm sure you are not the first with this error.
« Last Edit: March 20, 2017, 06:55:04 pm by cv007 »
 
The following users thanked this post: ali6x944


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf