1. Welcome to our site! Electro Tech is an online community (with over 100,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC12F675 MPLAB High Tech C Compiler

Discussion in 'Microcontrollers' started by wuchy143, Aug 17, 2010.

  1. wuchy143

    wuchy143 Member

    Joined:
    Feb 17, 2009
    Messages:
    420
    Likes:
    2
    Location:
    Manchester, NH, USA
    Perhaps I should go to the Microchip forum for this question but I like electrotech so here it goes...

    I'm learning how to program the PIC12F675 in C using The High Tech C Compiler. Scrounging the internet I was able to find the configuration script at the top of the C program which is entered before main(). My question is how do I know what that is for a specific microcontroller? Does it all depend on the given compiler? If it depends on the compiler how do most micro programmers figure that out? I will add I'm slightly a noob to micro programming. Basically how does everyone figure out what the need to put in the configuration script to make the PIC do what you want.

    Thanks

    -mike
  2. MikeMl

    MikeMl Well-Known Member

    Joined:
    Mar 17, 2009
    Messages:
    8,437
    Likes:
    244
    Location:
    Big Springs Ranch
    I do it by reading the specific PIC's data sheet. It will tell you what is configurable, and what the default configuration on power-up is. You only need to set those configuration bits which are opposite of the default settings...
  3. wuchy143

    wuchy143 Member

    Joined:
    Feb 17, 2009
    Messages:
    420
    Likes:
    2
    Location:
    Manchester, NH, USA
    Thanks Mike

    I found the configuration bits info in the datasheet which was helpful. They don't match up exactly but you can figure out what they are with a little intuition.

    I'm able to program the PIC12F675 once but then after that I can't program it again. It being a flash device I"m a little confused. Here is my code. I have a feeling my configuration bits are incorrect locking it or something. I have gone through a handfull of chips and now it's time to figure out what's wrong. I have the 10k pullup on mclr and a bypass cap so I don't think it's my hardware. Below is code to toggle the ports.


    #include <htc.h>

    __CONFIG(INTIO & WDTEN & MCLRDIS & BORDIS & UNPROTECT & PWRTEN);

    void main()
    {

    STATUS = 0b00000000; // Initializing Bank 0
    CMCON = 0x07; // Digital I/O

    STATUS = 0b00100000; // Initializing Bank 1
    WPU = 0b00110111;
    ANSEL = 0; // Digital I/O
    TRISIO = 0x00;
    STATUS = 0x00;
    GPIO = 0x3F;//(1<<4);
    _delay(50);
    GPIO = 0x00;//(1<<4);
    _delay(50);


    while(1);

    }
    Last edited: Aug 18, 2010
  4. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,280
    Likes:
    23
    Location:
    Vancouver Canada
    The trouble you are having is because you used the internal oscillator with master clear disabled; the programmer can not put the chip into programming mode. I know with the limited number of pins on this chip that is tempting, but you may want to keep your master clear until your program is working the way you want, then go ahead and use it as a gpio.

    Edit: You may be able to do an erase, then program it.

    Last edited: Aug 18, 2010
  5. Pommie

    Pommie Well-Known Member

    Joined:
    Mar 18, 2005
    Messages:
    9,060
    Likes:
    206
    Location:
    Brisbane Australia
    ONLINE
    If you are using a pickit2, you can erase them by doing the following,

    Place a good chip in the socket.
    Do a blank check to make the pickit see the chip.
    Swap to a bad chip.
    Erase bad chip.

    This works because the pickit2 thinks a good chip is present.

    Edit, there is a way to do it with a JDM but it requires a hardware mod.

    Mike.
    Last edited: Aug 18, 2010