View previous topic :: View next topic |
Author |
Message |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
Just got my PIC C program in the mail! A few basic questions |
Posted: Tue Aug 11, 2009 10:00 pm |
|
|
So my boss just spent $500 on the C software compiler and the ICD-U64 programming unit, and he expects me to know how to use it. I'm a PICBASIC programmer, so getting used to C will take me some time, though with some past video game programming experience I'm picking it up rather quickly.
My problem is getting to know the software. I've read through the manual a few times, word for word. I've written the following program, and I want to program it to my PIC16F684 microcontroller chip, but the option to program the ICD chip is greyed out, as is the option for MACHX. I've installed everything correctly, as stated by the included instructions card that came with the software, including the drivers for my ICD unit. Any ideas as to why the program isn't letting me use the 'Program Chip' function?
Code: |
#include <16f684.h>
#device ICD=TRUE
#use delay (clock=20000000)
float x;
float y;
float z;
int input;
void main()
{
loop:
output_high (PIN_A1);
delay_ms( 100 );
output_low (PIN_A0);
delay_ms( 100 );
}
|
I opened the program, started a new source file, wrote the above code into the source file, compiled it with no errors, and then tried to 'Program Chip->ICD'. Am I missing something?
Thanks! |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
i think this will make |
Posted: Wed Aug 12, 2009 4:37 am |
|
|
crazy programing
When I was new to PIC C I faced the same problem.
Code: | #include <16f684.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT
#use delay (clock=20000000)
float x; // not required
float y; // not required
float z; // not required
int input; // not required
void main()
{
loop: // mentioned loop but forgot to add "goto"
output_high (PIN_A1); // declared here as A1
delay_ms( 100 );
output_low (PIN_A0); // declared here as A0 " then how A1 go off"
delay_ms( 100 );
goto loop;
}
|
You can try this too:
Code: |
#include <16f684.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT
#use delay (clock=20000000)
void main()
{
while(1)
{
output_high (PIN_A1);
delay_ms( 100 );
output_low (PIN_A1);
delay_ms( 100 );
}
} |
If you want to read an input then:
Code: |
#include <16f684.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT
#use delay (clock=20000000)
#define input PIN_A3
int input; // not required
void main()
{
while(TRUE){
if(input==1){
output_high (PIN_A1);
delay_ms( 100 );
output_low (PIN_A1);
delay_ms( 100 ); }
}
} |
Now it will be OK. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 12, 2009 10:46 am |
|
|
These sample programs that you posted will not work.
Quote: | #include <16f684.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT
#use delay (clock=20000000)
void main()
{
while(1)
{
output_high (PIN_A1);
delay_ms( 100 );
output_low (PIN_A1);
delay_ms( 100 );
}
} |
You did not specify an oscillator fuse. A 20 MHz crystal oscillator requires
the HS fuse. But if you don't specify a fuse, the compiler defaults to
using the RC fuse. That fuse won't work with a 20 MHz crystal.
Here are the fuses created by your program.
Quote: | Configuration Fuses:
Word 1: 3CF7 RC NOPROTECT NOBROWNOUT MCLR NOCPD NOWDT NOPUT IESO FCMEN |
It's good to answer questions, but you should make sure the answer is
accurate. Maybe wait until you have more experience with CCS.
--------------------
For a simple newbie program for the 16F684, it's easier to use the internal
oscillator. Then blink an LED (with 470 ohm series resistor) on pin C0.
Example:
Code: |
#include <16F684.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
//===========================
void main()
{
while(1)
{
output_high(PIN_C0);
delay_ms(500);
output_low(PIN_C0);
delay_ms(500);
}
} |
The BROWNOUT fuse is used in this program. This assumes your board
is running at +5 volts. If it's running at a lower voltage, then change the
fuse to NOBROWNOUT. |
|
|
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Thu Aug 13, 2009 6:09 pm |
|
|
Thanks for the replies! Now that I have a working test code, I need to still figure out why my program isn't allowing me to click "Program Chip".
Does "while(1)" replace "loop"? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Jim Hearne
Joined: 22 Dec 2003 Posts: 109 Location: West Sussex, UK
|
|
Posted: Fri Aug 14, 2009 6:40 am |
|
|
Was your programmer supplied with the newer ccsload software ?
Did you install it after the compiler ?
Make sure the links in options>tools are correct, they may still point to the older icd software.
Can you run the programmer software directly from the windows start menu ?
Jim |
|
|
|