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

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power detected ( 4.32V)
PIC16F684 found (Rev 0x4)
PICkit 2 Ready

As you can see from the schematic, I have LED's on RC0, RC1, RC2, and RC3.
 

Attachments

Last edited:

MrChips

Joined Oct 2, 2009
30,824
Good.
Now we have to look at the Low Pin Count Demo Board User's Guide for guidance.
Install jumpers JP1 to JP4.
These will connect RC0 to RC3 to the four LEDs.

So we have to change the code from TRISB to TRISC
and PORTB to PORTC.

Since I don't have my PICkit2 here with me I have to guess what you have to do to get it running.

Build the code.
Then the RUN arrow should become available.
The LEDs should count up - I don't know how fast.

You will also have to set the Configuration bits - the important one is the Oscillator Selection Bits.

After the #include <htc.h> line at the top, add

__CONFIG( INTCLK & WDTDIS & PWRTDIS & BODIS & LVPDIS & UNPROTECT & FCMDIS);
 
Last edited:

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Here's the code. The build failed with a whole string of errors.

Rich (BB code):
#include <htc.h>
/*
 * Demo program
 *
 * Flashes LEDs on Port C, responds to switch press
 * on RA1. Usable on PICDEM board.
 *
 * Copyright (C)1997 HI-TECH Software.
 * Freely distributable.
 */
/*#define BUTTON RC1 //bit 1 of PORTC
main(void)
{
 unsigned char i, j;
 TRISC = 0;  /* all bits output */
 j = 0;
 for(;;) {
  PORTC = 0x00;  /* turn all on */
  for(i = 100 ; --i ;)
   continue;
  PORTC = ~j;  /* output value of j */
  for(i = 100 ; --i ;)
   continue;
  if(BUTTON == 0)  /* if switch pressed, increment */
   j++;
 }
}
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Back to your initial post - did you want to learn PicBasic Pro specifically, or are you just trying to pick up any language?

With your background in Pic Axe, PBP should be pretty easy to pick up.

C is also a good choice; a little harder to learn, but you will find a lot more support here with C. You can also use it with other brands of microcontrollers.

I can help you get started with PBP if you want to go that way, and it looks like Mr Chips is getting you going with C.
I downloaded the trial version of PBP3 and tried to get started on my own, but failed. I would still like to try it out, but all the preliminaries get in the way of trying to write code. I would appreciate your help. It would be good to be able to try C and PBP3, and see which one (if either) I can learn.
 

MrChips

Joined Oct 2, 2009
30,824
Not a problem.
The errors have to do with the use of /* for commenting.
/* */ cannot be nested.

We will reinstall the code relating to the BUTTON.
We will use the SW1 switch which is connected to RA3. You will have to install jumper JP5.
Change the statement to

#define BUTTON RA3
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
It's all Greek to me. :) Is it close?

Rich (BB code):
#include <htc.h>
__CONFIG( INTCLK & WDTDIS & PWRTDIS & BODIS & LVPDIS & UNPROTECT & FCMDIS); 
/*
 * Demo program
 *
 * Flashes LEDs on Port C, responds to switch press
 * on RA1. Usable on PICDEM board.
 *
 * Copyright (C)1997 HI-TECH Software.
 * Freely distributable.
 */
#define BUTTON RA3 //bit 1 of PORTC
main(void)
{
 unsigned char i, j;
 TRISC = 0;  /* all bits output */
 j = 0;
 for(;;) {
  PORTC = 0x00;  /* turn all on */
  for(i = 100 ; --i ;)
   continue;
  PORTC = ~j;  /* output value of j */
  for(i = 100 ; --i ;)
   continue;
  if(BUTTON == 0)  /* if switch pressed, increment */
   j++;
 }
}
Here is the result of the build.

Build C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.c for device 16F684
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe
Make: The target "C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 "C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.c" -q --chip=16F684 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" -oled.c.cof -mled.c.map --summary=default --output=default led.p1 --chip=16F684 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
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! **********
 

MrChips

Joined Oct 2, 2009
30,824
Looks good. We'll explain later. Let's get it running first.

Later whatsthatsmell has offered to get you going on PBP3 as well - wouldn't hurt.
 

MrChips

Joined Oct 2, 2009
30,824
OK. Remove the __CONFIG statement.

Run this first. If the code does not run by default we will change the Configuration bits manually via:

Configure, Configuration Bits...
Uncheck Configuration Bits set in code

select INTOSC
WDT disabled
PWRT disabled
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
I removed the config statement. Now what?

Build C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.c for device 16F684
Using driver C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe
Make: The target "C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.p1" is out of date.
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 "C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.c" -q --chip=16F684 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" -oled.c.cof -mled.c.map --summary=default --output=default led.p1 --chip=16F684 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
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)
Memory Summary:
Program space used 32h ( 50) of 800h words ( 2.4%)
Data space used 5h ( 5) of 80h bytes ( 3.9%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Configuration bits used 0h ( 0) of 1h word ( 0.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)

Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Lite mode.
See http://microchip.htsoft.com/portal/pic_pro for more information.
Loaded C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\HI-TECH C Playtime Projects\led.c.cof.
********** Build successful! **********
 

MrChips

Joined Oct 2, 2009
30,824
No, you're not ignorant, just new to the game. (btw, I only started doing this about a month ago).

Did you select Debugger, Select Tool, PICkit2.
Build (Black square or F10)
Run (Right Arrow on the top control bar or F9)
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Resetting
Programming Target (5/2/2012 9:46:01 PM)
PIC16F684 found (Rev 0x4)
Erasing Target
Programming Program Memory (0x0 - 0x3)
Programming Program Memory (0x6CC - 0x6FF)
Verifying Program Memory (0x0 - 0x3)
Verifying Program Memory (0x6CC - 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,824
Ignore the error message. Are the LEDs changing when you press SW1?
Do you have JP1 to JP5 installed?

If not, we still have a couple more things to attend to.
 

MrChips

Joined Oct 2, 2009
30,824
OK. Three things to attend to.
We will do one at a time so we have some idea as to what still needs to be done.
RA3 is shared with MCLR. We will skip the use of SW1 as BUTTON.
Comment out the two lines of code that has the word BUTTON.
Do not use /* for comments. Use // at the start of the line.

Try this first.

After that we will set the Configuration bits.

Then we will switch from Debugger to Programmer.

If this still does not work we will have to wait until tomorrow when I will get my PICkit2 and a PIC chip.
 

Thread Starter

tracecom

Joined Apr 16, 2010
3,944
Rich (BB code):
#include <htc.h>
/*
 * Demo program
 *
 * Flashes LEDs on Port C, responds to switch press
 * on RA1. Usable on PICDEM board.
 *
 * Copyright (C)1997 HI-TECH Software.
 * Freely distributable.
 */
//#define BUTTON RA3 //bit 1 of PORTC
main(void)
{
 unsigned char i, j;
 TRISC = 0;  /* all bits output */
 j = 0;
 for(;;) {
  PORTC = 0x00;  /* turn all on */
  for(i = 100 ; --i ;)
   continue;
  PORTC = ~j;  /* output value of j */
  for(i = 100 ; --i ;)
   continue;
  //if(BUTTON == 0)  /* if switch pressed, increment */
   j++;
 }
}
I saw all 4 LEDs flash once as the PIC was being programmed, but that's all. Actually, I think I have seen this flash before.

ETA: I realize that all things get clearer with practice, but this whole process seems outrageously complex.
 

MrChips

Joined Oct 2, 2009
30,824
Here is a simpler piece of code to try:

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

void main(void)
{
   TRISC = 0;
   PORTC = 0x0F;
  while(1);
}
(perhaps later if all else fails).
 

MrChips

Joined Oct 2, 2009
30,824
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
 
Top