View previous topic :: View next topic |
Author |
Message |
Guest
|
Help with PIC12F509 |
Posted: Thu Jun 04, 2009 9:28 am |
|
|
Code: |
#include<12f509.h>
#fuses INTRC, NOWDT, MCLR
#use delay(clock=4MHz)
#use fast_io(b)
// * GPIO PORT DEFINITIONS *****************************************************
#define ON PIN_B1 // (Input, discrete)
#define OFF PIN_B2 // (Input, discrete)
#define PUMP PIN_B4 // (Output)
// *****************************************************************************
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
void main(void) {
set_tris_b(0b00001111);
set_options(0xC0);
output_high(PUMP);
output_high(PIN_B5);
}
|
I can't seem to get this simple code to do anything. I have a relay on B4 and a relay on B5 both buffered with an NPN transistor. Can't get either outputs to come on and I've checked it with a scope. It remains low. I've also had a while(TRUE) loop around the output functions but removed it in a feeble attempt to make the PIC do something. I've tried 3 PICs now so I am sure the devices are good and they program/verify fine.
I'm using CCS version 4.050 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 04, 2009 11:21 am |
|
|
1. Strip your program down so it's more simple, as shown below.
2. Make sure that you have a pull-up resistor on the MCLR pin.
Use 10K for the ICD2, or 47K for the ICD-U40.
3. Remove all external circuits that might be interfering with the pin i/o.
Only the Vdd, Vss and MCLR pins should have external connections for
this test.
Code: | #include<12F509.h>
#fuses INTRC, NOWDT, MCLR
#use delay(clock=4000000)
#define PUMP PIN_B4
//============================
void main(void)
{
output_high(PUMP);
output_high(PIN_B5);
while(1); // Prevent PIC from going to sleep
} |
|
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Thu Jun 04, 2009 12:03 pm |
|
|
What PCM stated, also, take a look at the file: EX_8PIN.C in your \PICC\EXAMPLES directory. _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
Guest
|
Problem fixed (sort of) |
Posted: Fri Jun 05, 2009 7:49 am |
|
|
Thanks for the pointers guys but it turns out that it would never work regardless of what I do. The problem appears to be in the ccsloader program that I just downloaded from CCS. It's broken. I loaded the exact same code with the old ICD-U40 program and it works fine. I like the look and layout of the new ccsloader program but all that is irrelevant if it can't properly program the chip. Also there is another irritating bug in it that when you select the chip sometimes it will still say there is no target device defined. |
|
|
|