PBP3, PICkit2, MPLAB IDE v8.83, MCSX, and I am baffled.

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Running Target
PICkit 2 Ready
Resetting
Programming Target (5/2/2012 10:20:43 PM)
PIC16F684 found (Rev 0x4)
Erasing Target
Programming Program Memory (0x0 - 0x3)
Programming Program Memory (0x6D4 - 0x6FF)
Verifying Program Memory (0x0 - 0x3)
Verifying Program Memory (0x6D4 - 0x6FF)
Programming Debug Executive (0x-700 - 0x7FF)
Verifying Debug Executive (0x700 - 0x7FF)
Programming Debug Vector
Verifying Debug Vector
Programming Configuration Memory
Verifying Configuration Memory
PK2Error0028: Unable to enter debug mode
NOTE: This device requires an ICD Header for debug. See "Header Specification" DS51292.
PICkit 2 Ready
Running Target
PICkit 2 Ready
 

MrChips

Joined Oct 2, 2009
30,806
What do the LEDs do?

If not lit then the code in post #39 is designed to make the LEDs come on and stay on.

If this does not work.

Go to the main menu bar and select Programmer.
Select Programmer, PICkit 2

Build and RUN

If the LEDs do not stay on then we will have to leave it for another time.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
What do the LEDs do?
Nothing

If this does not work.

Go to the main menu bar and select Programmer.
Select Programmer, PICkit 2

Build and RUN

If the LEDs do not stay on then we will have to leave it for another time.
This time the LEDs lit and stayed on, but I didn't find a RUN button, so I had to change the Programmer settings to auto run after a successful program.

Thanks for your help, but I am afraid this is beyond me. I have no idea what we did, and couldn't do it again if my life depended on it. And if it took this long just to get LEDs to light, how long would it take to implement some meaningful function? (That's just a rhetorical question, BTW.) I have so many questions about what was done and why, I don't know where to start. And as far as writing code, we spent so much time on the process, I have no idea what any of the code means.

Thanks again.
 

MrChips

Joined Oct 2, 2009
30,806
Don't be discouraged by the initial effort. This is just part of the learning curve. When you have the correct steps in place you will be able to focus on the programming part.

I will explain the steps another time.

Here is one last piece of code before I sign off.

Rich (BB code):
#include <htc.h>

#define DELAY  200000

void main(void)
{
   TRISC = 0;
   while(1)
    {
       PORTC = 0;
       _delay(DELAY);
       PORTC = 0x0F;
       _delay(DELAY);
    }
}
This code should make all four LEDs flash together.
Change the delay time DELAY to different values (in microseconds) to slow down or speed up the flash rate.
 

t06afre

Joined May 11, 2009
5,934
OK. We need to get the MCU clock set up.
Go to Configure at the top menu bar.
Configuration bits...
uncheck the Configuration Bits set in code
In the Setting column
select INTOSC
WDT disable
PWRT disable
Program memory code protection is disabled
Data memory code protection is disabled
BOR disabled
Internal External Switchover mode is disabled
Fail-Safe Clock Monitor is disabled
Build and Run again
For the beginner I also recommend disabling the MCLR function. So that this pin function as a normal input. Set the MCLRE field to pin function digital IO. One more thing to not think about. But the PICKIT will stil take control over this pin.
 

MrChips

Joined Oct 2, 2009
30,806
So, looking over what we did and were not doing right, the most important thing that was preventing the MCU from not running was not selecting the internal oscillator properly.
This we did manually by selecting INTOSC or INTOSCIO in the Configuration Bits setting.

Why the __CONFIG( ) statement did not work, I am not sure. Seems to work fine on my installation. (I am programming a PIC16F887).

Here are your errors for reference:
Rich (BB code):
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error   [800] led.c.as; 45. undefined symbol "FCMDIS"
Error   [800] led.c.as; 45. undefined symbol "UNPROTECT"
Error   [800] led.c.as; 45. undefined symbol "LVPDIS"
Error   [800] led.c.as; 45. undefined symbol "BODIS"
Error   [800] led.c.as; 45. undefined symbol "PWRTDIS"
Error   [800] led.c.as; 45. undefined symbol "WDTDIS"
Error   [800] led.c.as; 45. undefined symbol "INTCLK"
********** Build failed! **********
Also, good that you have found how to set Debugger Settings and Programmer Settings.

Enable:

Connect on Startup
Program after a successful build
Run after a successful program

will give you one-click build-program-run.
 

MrChips

Joined Oct 2, 2009
30,806
The next thing you can try is:

Rich (BB code):
#include <htc.h>  

#define DELAY  200000

char count;

void main(void) 
{ 
   TRISC = 0;
   count = 0;
   while(1)     
    {        
       PORTC = count++; 
       _delay(DELAY); 
    } 
}
Learning C programming:
You can either go to a beginner's tutorial on C on the internet
or you can ask any questions about any part of the code shown above. No question is too trivial.
 

stahta01

Joined Jun 9, 2011
133
Rich (BB code):
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
Error   [800] led.c.as; 45. undefined symbol "FCMDIS"
Error   [800] led.c.as; 45. undefined symbol "UNPROTECT"
Error   [800] led.c.as; 45. undefined symbol "LVPDIS"
Error   [800] led.c.as; 45. undefined symbol "BODIS"
Error   [800] led.c.as; 45. undefined symbol "PWRTDIS"
Error   [800] led.c.as; 45. undefined symbol "WDTDIS"
Error   [800] led.c.as; 45. undefined symbol "INTCLK"
********** Build failed! **********
It is likely some of the above errors will go away if _LEGACY_HEADERS is added before the htc.h include.
Rich (BB code):
#define _LEGACY_HEADERS
#include <htc.h>
Rich (BB code):
Used values from pic16f887.h and legacy/pic16f887.h
old value   old name    new value   new name
0x37FF      FCMDIS      0xF7FF      FCMEN_OFF
0x3FFF      UNPROTECT   0xFFFF      CP_OFF
0x2FFF      LVPDIS      0xEFFF      LVP_OFF
            BODIS
0x3FFF      PWRTDIS     0xFFFF      PWRTE_OFF
0x3FF7      WDTDIS      0xFFF7      WDTE_OFF
0x3FFD      INTCLK      0xFFFD      FOSC_INTRC_CLKOUT
Tim S.
 
Last edited:
Top