View previous topic :: View next topic |
Author |
Message |
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
Help getting started |
Posted: Tue Jan 09, 2007 2:31 pm |
|
|
I'm trying to successfully program my first PIC chip (I have a background as mainly a Windows programmer with a bit of messing around with BASIC Stamps).
A quick side question before I get into the meat of my conundrum:
The 12c672.h file lists the fuses that it supports, but I'm having trouble finding documentation on exactly what those fuses relate to. For example, if I search in the CCS help file I can't find info on what exactly 'HS' relates to. Is their some documentation on these fuse settings?
Ok, here's the main issue:
I have a PIC12C672 that I'm trying to have flash a LED on & off (as a "hello world" program) and it isn't working. One thing I'm not clear about, is the the pin constants. 12C672.H specifies them as PIN_A0 through PIN_A5, but the PIC12C67x datasheet lists them as GP_0 through GP_5. I'm assuming that GP_0 == PIN_A0... is that correct?
Here's my code:
Code: |
#if defined(__PCM__)
#include <12C672.h>
#use delay(clock=10 mhz)
void main() {
while (TRUE) {
output_high(PIN_A0);
delay_ms(1500);
output_low(PIN_A0);
delay_ms(1500);
}
}
|
Thanks for any help! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
BOB_SANTANA
Joined: 16 Oct 2006 Posts: 110 Location: HOVE, EAST SUSSEX
|
|
Posted: Tue Jan 09, 2007 3:03 pm |
|
|
I Think you need to set your fuses
As a beginer to programming in C (Just like me:)
i personnally would start by using a flash pic like 16F877 as most ofthe example programs are written for those them when you get up and running start using which ever pic you like below is and example for fuse setting for 16F877.
Also remember that there are little things like Tris setting which defines
the direction of your port pins to either inputs or outputs
Code: |
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
|
_________________ BOB_Santana |
|
|
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
|
Posted: Tue Jan 09, 2007 3:35 pm |
|
|
Bob, you're certainly right about some of those compiler options... now that I know what they're about (thanks PCM Programmer!), the NOPROTECT seems particularly important.
I would like, however, to figure out how to program the 12C672s since that's what I have on-hand, and whatever is wrong with the program I posted must be pretty minor. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Jan 09, 2007 3:55 pm |
|
|
Quote: |
I would like, however, to figure out how to program the 12C672s since that's what I have on-hand,
|
I assume you have a 12C672 windowed with ceramic JW package.
Humberto |
|
|
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
|
Posted: Tue Jan 09, 2007 4:38 pm |
|
|
Well, it is windowed... I'm not sure what a ceramic JW package is.
I did find a little online tutorial for doing a blinking LED at:
http://www.gvu.gatech.edu/ccg/resources/pic/#ss50
The tutorial uses a 16F84 and I have a 16F84A, so I just just slurped over his code (changing the clock speed to be 2mhz). The main difference between what I was coding and this is example was a couple of compiler directives that Bob seems to have been referring to
#use fast_io(B)
#define IRX_B_TRIS 0b00110000
The ex_sqw.c didn't use any I/O directives, which led me to believe they weren't necessary.
Looking at the hardware that the blinking LED tutorial has, it looks like I don't have mine setup correctly (I simply have power going into the chip at VDD and being ground at VSS and a resistor from Pin B2 going to a grounded LED). The tutorial specifies that "Only 6 pins of the PIC are connected. 2 for +5V and ground, 2 for the crystal, 1 for the LED and 1 for /MCLR." So I'm guessing I need to hookup the crystal, etc. but don't have the details for doing that.
Are there any good books or (preferably) online tutorials that covers using PICs from the very basics? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jan 09, 2007 5:08 pm |
|
|
As additional information on the CCS naming of the fuses I always find the file fuses.txt in the PICC directory very helpfull.
In your example program you have Code: | #if defined(__PCM__)
| but without the #endif. Is some code missing here? Remember to select the 'Disable HTML' button when posting code (set this as prefered setting in your profile).
As the code is now this line is not required.
What kind of oscillator are you using? 10MHz can only be achieved with an external crystal and requires the HS fuse setting (see page 93 of the PIC12C67X datasheet for maximum clock frequencies for each option).
The main problem why your tiny program doesn't work can be found on page 25 of the datasheet Quote: | On a Power-on Reset, GP0, GP1, GP2
and GP4 are configured as analog inputs
and read as '0'. |
Please try the following program Code: | #include <12C672.h>
#fuses HS // High Speed Osc (> 4MHz), external crystal
#fuses NOWDT // No Watchdog Timer
#fuses NOPROTECT // Code not protected from reading
#fuses PUT // Power Up Timer enabled
#fuses NOMCLR // Reset (Master Clear) pin used for I/O
#use delay(clock=10 mhz)
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
while (TRUE) {
output_high(PIN_A0);
delay_ms(1500);
output_low(PIN_A0);
delay_ms(1500);
}
} |
|
|
|
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
|
Posted: Tue Jan 09, 2007 6:30 pm |
|
|
I tried the code, but no luck... Given that more experienced people have eye-balled the code, I'm wondering if I'm setting the hardware up wrong.
As mentioned above, all I have is current going to the chip at vdd and being grounded at vss as well as a resistor leading from PIN_A0 to a ground LED. Nothing else is needed for this program? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 09, 2007 6:44 pm |
|
|
If you don't have a crystal, then delete this part of the program:
Quote: |
#include <12C672.h>
#fuses HS // High Speed Osc (> 4MHz), external crystal
#fuses NOWDT // No Watchdog Timer
#fuses NOPROTECT // Code not protected from reading
#fuses PUT // Power Up Timer enabled
#fuses NOMCLR // Reset (Master Clear) pin used for I/O
#use delay(clock=10 mhz)
|
Use this code instead of the above:
Code: |
#include <12C672.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, NOMCLR
#use delay(clock=4000000)
|
Keep the lines in the exact order shown above.
After doing that, if it still doesn't work then post your compiler version.
The version will be a number like 3.191, 3.249, or 4.020, etc.
You can find it at the top of the .LST file, which is in your project directory.
You don't need to post any of the numbers that come after the version
number. |
|
|
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
|
Posted: Tue Jan 09, 2007 7:07 pm |
|
|
That still didn't work... I'm wondering now if the problem might be the quality of the voltage I'm giving the chip. It's coming right off an adapter. I used a multimeter to verify the voltage was within the range that the chip uses, but maybe it needs to be cleaned up with a voltage regulator?
I'm using compiler version 4.020 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 09, 2007 7:15 pm |
|
|
Read the label on the adapter. What does it say the output voltage is ? |
|
|
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
|
Posted: Tue Jan 09, 2007 7:50 pm |
|
|
Well, it says 3V DC at 100mA... but I've burnt out BASIC stamps by trusting an adapter's label (in fact, the first adapter I was going to use this morning was labeled 5v, but was actually putting out 8 volts). My multimeter indicates it is putting out 4 volts. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 09, 2007 9:43 pm |
|
|
What programmer are you using ? If your programmer erased the
program memory at address 0x7FF, then your PIC won't work with
the internal oscillator. Can you use your programmer to read the
program memory at that address ? What does it show is stored at
address 0x7FF ?
This location contains the OSCCAL value. The compiler inserts code
to fetch the calibration value when the program first starts running.
If the calibration value isn't there anymore, the program will crash.
This can be easily fixed, but we need to know if the value has been
erased.
Some programmers preserve the word at the end of memory, but others
don't. That's why important to know what value is currently at address 0x7FF. |
|
|
Simenzo
Joined: 06 Jan 2007 Posts: 9
|
|
Posted: Wed Jan 10, 2007 8:59 am |
|
|
This seems a promising line if inquiry! I'm using a PICSTART PLUS (version R21). The program memory at that address seems to be blank:
2048 7FF 3FFF ADDLW 0xff
What would be the solution to this? I currently have the memory ranges automatically set... do I need to manually set the end address?
Many thanks! |
|
|
|