• AVR Freaks

Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840

Author
rikpardun
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2012/08/22 09:12:40
  • Location: 0
  • Status: offline
2012/08/23 08:46:37 (permalink)
0

Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840

Good afternoon all,
I am an engineer but mostly work more on the hardware side and rarely bring up stuff from scratch (We have guys for that but I want to learn so here we go).
 
I have a very simple PIC design which does nothing but sit there and look pretty.  A pickit3 and a brand new installation of MPLAB X and MPLAB XC8 V1.1.
Following the instructions in the PIC C Lesson 1 Basic Digital IO, I followed the example for the MPLAB X design and set up a new program for the PIC12F629.  Copied his source example and hit the clean and build button.  It does compile but has two items that it complains about.
1.  Unexpected token on the __Config line and
2.  Occasionally an issue with the TRISIO but I cant get the error right now so maybe that is nothing.
Is this normal?  Does it mean anything?
 
Now on to the more important part of this.  I want to get his to work for my 12F1840 chip and it says that to see which symbols I should use in the config i should consult the appropriate include file (pic12F629.H or pic12F1840.h).  The problem is, I don't see any of these tokens or symbols any where in the .h file.  I am using the XC8 library which would be located at C:\Program Files\Microchip\xc8\v1.10\include\ 
Can someone explain to me exactly what and where I am looking so that I can go to the 1840 and try to modify it to work with that?
 
It is better if I learn how to find this stuff myself but as a kickstart, if anyone has code that compiles for the 12F1840 using MPLAB X and XC8, that would be a great learning tool.  Right now I am fighting with the fact that I have a new IDE, a new library, a new chip, and a new programmer (me) and any one or all of them could be the cause for error here.  I know were I am putting my money though :)
 
Also, I am including the schematic of the circuit.  At some point I will try to plug the programmer on this board and program it.  If you see any errors here please please please point them out.  The datasheet was schetchy on the programming setup.  Once you are comfortable with it, I am sure it makes perfect sense but right now, I am not sure of anything.
Any other tips on getting some baseline code going here would be greatly appreciated.
 
Best Regards
 

Attached Image(s)

#1

8 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 19185
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/23 17:16:27 (permalink)
    0
    You Need a decoupling cap.
    I usually add a diode to the resistor on the MCLR pin.  (stop VPP from getting on Vcc).
    MPLab X is known to complain about good code.  If the compiler is happy ignore the IDE.
    #2
    meikled
    Super Member
    • Total Posts : 556
    • Reward points : 0
    • Joined: 2006/01/11 20:12:06
    • Location: Sydney, Australia
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/26 05:47:39 (permalink)
    0
    rikpardun

    Now on to the more important part of this.  I want to get his to work for my 12F1840 chip and it says that to see which symbols I should use in the config i should consult the appropriate include file (pic12F629.H or pic12F1840.h).  The problem is, I don't see any of these tokens or symbols any where in the .h file.  I am using the XC8 library which would be located at C:\Program Files\Microchip\xc8\v1.10\include\ 
    Can someone explain to me exactly what and where I am looking so that I can go to the 1840 and try to modify it to work with that?


     
    Ah, it seems that my C tutorials are out of date, and I hadn't realised it!  Thanks for pointing this out.  Although, I'd just revised all of them, in the last couple of months, for XC8.  But I missed that the __CONFIG() symbols are no longer defined in the .h files...
    It seems that Microchip have not yet caught up with their own changes, either!  The manual for XC8 v1.10 still states, on page 313: 16-bit masks have been defined to describe each programmable attribute available on each device. These masks can be found in the chip-specific header files included via <xc.h>.  But this isn't true any more!
     
    You now need to consult "pic_chipinfo.html", in the docs folder. 
     
    It also seems that Microchip are steering everyone to the C18-style "#pragma config" way, instead of the "__CONFIG()" macros shown in the tutorials.  __CONFIG() still works though.
     
    Looks like I'd better go back and update lessons again...
     

    post edited by meikled - 2012/08/26 05:50:07
    #3
    meikled
    Super Member
    • Total Posts : 556
    • Reward points : 0
    • Joined: 2006/01/11 20:12:06
    • Location: Sydney, Australia
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/29 06:07:53 (permalink)
    0
    I've now updated "lesson 1" of both the baseline and mid-range C tutorials, to mention that "#pragma config" is now preferred to the legacy "__CONFIG" macro, and that the processor configuration symbols are now documented in "pic_chipinfo.html".
     
    I'm not going to go through and change all the existing code to use configuration pragmas, but I'll use them in upcoming tutorials.
     
    Keeping up with all these changes isn't easy! 
     
     
    #4
    sjb741
    Super Member
    • Total Posts : 858
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/30 01:11:25 (permalink)
    0
    It takes ages to keep altering existing code to new style. We have 'CCI' to worry about too. As a plus, two compilers (XC8, XC16) with hopefully lots in common and none of the C18 ram/rom wierd stuff.
     
    Once C18, C30 & co bite the dust perhaps the USB framework can be trimmed down by removing all those #ifdefs.
     
    Now if only they could make the 'managed stack' option work for PIC18 and variadic macros..
    post edited by sjb741 - 2012/08/30 01:15:48
    #5
    rikpardun
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2012/08/22 09:12:40
    • Location: 0
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/30 05:54:08 (permalink)
    0
    This was great information and took care of all the stuff I was seeing.  I implemented the changes myself and then also tried out the code that you fixed in the first examples and both compiled fine.  I do have one question though....
     
    For a device like the 12F1840, they list several configuration registers.  Would you do something like this:
    #pragma config1 CPD=OFF, BOREN=OFF....
    #pragma config2 PLLEN=OFF, WRT=OFF...
    or is it  still done under config as in the 629 example?  I haven't tried to get those to work yet as I still can't get the 629 to work. 
     
    I might have to post this under a separate header but it is still part of my attempt to get the most basic circuit to compile starter code and program the device.
    So I converted my design by replacing the 1840 with a 626 chip just to eliminate that as a possible error.  I think they are drop in compatible.  I should check that again really closely though just to make sure.  Anyway, the mid starter code compiles like it should.  In the MPLAB X options I have the right chip selected and it sees the Pickit3 device.  I assume it is the right serial number, I don't know about firmware, the file that it is calling out is PK3FW_012720.jam.  The problem is that when I go to "Make and program device" I get the output that I have included at the very bottom of this message.  The most important being the last line:
     
    Connecting to programmer...
    The programmer could not be started: Could not connect to tool hardware: PICkit3PlatformTool, com.microchip.mplab.mdbcore.PICKit3Tool.PICkit3DbgToolManager
     
    The PicKit3 is the one that came with the DV164139 Low Pin Count USB Development Kit.  I did have the tools loaded on this computer at one time but I don't think I ever actually got to the point of try to program something so I can't say with any certainty that this setup every worked with the old MPLAB 8.  That was all removed from this machine though before I loaded MPLAB X if any of that matters.
    So my current question to you or anyone reading this is what indications should I get on the PicKit3 (leds or ?) Do I even need to be connected to a target device?  I assume I would get some sort of error if I wasn't but I would expect that it would be able to find the programmer.  I am trying to half split this and determine if it is an IDE/operating systems (Win XP) issue, a Pickit3 issue, or my target circuit issue.  This gets harder since I have never ever in my life seen what this setup would look like if it actually worked properly.
     
    ANY tidbits of wisdom would be hugely appreciated.
     
    Rik
     
     
     
     
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory `C:/Documents and Settings/Owner/MPLABXProjects/MC_L1-Turn_on_LED-HTC.X'
    make  -f nbproject/Makefile-default.mk dist/default/production/MC_L1-Turn_on_LED-HTC.X.production.hex
    make[2]: Entering directory `C:/Documents and Settings/Owner/MPLABXProjects/MC_L1-Turn_on_LED-HTC.X'
    "C:\Program Files\Microchip\xc8\v1.10\bin\xc8.exe" --pass1  --chip=12F629 -Q -G --asmlist  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"  -obuild/default/production/newfile.p1  newfile.c
    "C:\Program Files\Microchip\xc8\v1.10\bin\xc8.exe"  --chip=12F629 -G --asmlist -mdist/default/production/MC_L1-Turn_on_LED-HTC.X.production.map  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,+speed,-space,-debug,9 --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"   -odist/default/production/MC_L1-Turn_on_LED-HTC.X.production.cof  build/default/production/newfile.p1    
    Microchip MPLAB XC8 C Compiler (Free Mode)  V1.10
    Copyright (C) 2012 Microchip Technology Inc.
    (1273) Omniscient Code Generation not available in Free mode (warning)

    Memory Summary:
        Program space        used     Eh (    14) of   400h words   (  1.4%)
        Data space           used     2h (     2) of    40h bytes   (  3.1%)
        EEPROM space         used     0h (     0) of    80h bytes   (  0.0%)
        Configuration bits   used     1h (     1) of     1h word    (100.0%)
        ID Location space    used     2h (     2) of     4h bytes   ( 50.0%)


    Running this compiler in PRO mode, with Omniscient Code Generation enabled,
    produces code which is typically 40% smaller than in Free mode.
    See http://microchip.com for more information.

    make[2]: Leaving directory `C:/Documents and Settings/Owner/MPLABXProjects/MC_L1-Turn_on_LED-HTC.X'
    make[1]: Leaving directory `C:/Documents and Settings/Owner/MPLABXProjects/MC_L1-Turn_on_LED-HTC.X'

    BUILD SUCCESSFUL (total time: 2s)
    Loading code from C:/Documents and Settings/Owner/MPLABXProjects/MC_L1-Turn_on_LED-HTC.X/dist/default/production/MC_L1-Turn_on_LED-HTC.X.production.hex...
    Loading symbols from C:/Documents and Settings/Owner/MPLABXProjects/MC_L1-Turn_on_LED-HTC.X/dist/default/production/MC_L1-Turn_on_LED-HTC.X.production.cof...
    Loading completed
    Connecting to programmer...
    The programmer could not be started: Could not connect to tool hardware: PICkit3PlatformTool, com.microchip.mplab.mdbcore.PICKit3Tool.PICkit3DbgToolManager
    #6
    sjb741
    Super Member
    • Total Posts : 858
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/31 01:43:16 (permalink)
    0
    I do not know MPLABX, only MPLAB. But in MPLAB at least there are menu headings Programmer and Debugger. Once PicKit3 is selected (say as debugger) then there are the Settings to check out, particularly 'Power', 'Status' and 'Limitations'. There is also a 'Reconnect' option on this menu.

    Connecting a Pickit3 (without MPLAB running) gives

        Power, Active, Status all lit
        After  4 seconds, Status goes off.

    Now, with MPLAB running -

        Status goes Red,Green

    A dialog box pops up
    Caution- Check that the device selected in MPLAB IDE (PIC12F886) is the same one that is
    physically attached to the debug tool.Selecting a 5V when a 3.3 V device is connected can
    result in damage to the device when the debugger checks the device id.
     
    If you unsure, choose "Cancel" or better ensure no PIC chip is connected.
     
    Then:
    PICkit 3 detected
    Connecting to PICkit 3...
    Running self test...
    Self test completed
    Firmware Suite Version...... 01.27.20
    Firmware type......................Midrange
    PICkit 3 Connected.
    Device ID Revision = 00000002

    Here is the setup
     
     
     
     

    Attached Image(s)

    #7
    sjb741
    Super Member
    • Total Posts : 858
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re:Getting started with the MPLAB X, the Gooligum tutorial and a PIC12F1840 2012/08/31 01:44:24 (permalink)
    0
    BTW: It took ages to post this - my text was always rejected. It seems that using single quotes is disliked by the parser.
    #8
    rikpardun
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2012/08/22 09:12:40
    • Location: 0
    • Status: offline
    solved, thank you! 2012/08/31 18:36:34 (permalink)
    0
    Thanks for the help you guys.  It looks like this is now solved.  The root problem was that the Pickit 3 didn't have a new enough version of firmware for MPLAB X to be able to connect to it and update it, although it could still see it and recognize the serial number.  Loading MPLAB 8.7x was able to though and it updated the firmware like it should.  I then re-opened in MPLAB X and downloaded the code into the chip and it worked fine.  Well it says it worked.  I haven't actually made the chip do anything yet but it looks good so far.  And for anyone reading this, the schematic I originally posted had pins 5 and 6 swapped.  And it does actually have bypass caps on there, they were just not shown.  I will post a thorough post Tuesday when I am back on my work machine but hopefully this solution helps someone else.
     
    Again, thanks for the assistance guys.
     
    Rik
    #9
    Jump to:
    © 2021 APG vNext Commercial Version 4.5