17th August 2010 10:42 PM
PIC12F675 MPLAB High Tech C Compiler
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.
17th August 2010 10:59 PM
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...
18th August 2010 07:13 PM
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.
__CONFIG(INTIO & WDTEN & MCLRDIS & BORDIS & UNPROTECT & PWRTEN);
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);
GPIO = 0x00;//(1<<4);
Last edited by wuchy143; 18th August 2010 at 07:16 PM.
19th August 2010 02:40 AM
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.
Originally Posted by wuchy143
Last edited by BeeBop; 19th August 2010 at 02:42 AM.
Reason: added line
19th August 2010 04:53 AM
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.
Last edited by Pommie; 19th August 2010 at 04:54 AM.
Electronic Circuits |
Page Time: 0.06314 seconds Memory: 7,382 KB Queries: 16 Templates: 0