CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PICKIT 1 & 12F675 programing

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PICKIT 1 & 12F675 programing
PostPosted: Fri May 21, 2004 9:13 pm     Reply with quote

Hello,

Im new to PICs and have been trying to program a 12F675 using a PICKit 1 flash programer from microchip.

This is an example of the code I am using to attempt to make pin 2 on the chip go high:

#include <12f675.h>
#use delay (clock=400000)


void main()
{

output_high (PIN_A0);
}

It compiles ok, and creates a HEX file. I then use the PICKit tool to write the HEX file to the PIC.

I then moved the PIC to my breadboard connected +5v to pin 1 and pin 8 to GND, but PIN 2 never goes high.

Am I doing something wrong?

Thanks
Eric.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri May 21, 2004 9:58 pm     Reply with quote

Just a quick note: never let your code flow past the end of main(). Add this line under the output_high():

while (1);
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Sat May 22, 2004 12:04 am     Reply with quote

Eric,

You have to enable the pins for digital IO operation, example follows.

Code:
/////////////////////////////////////////////////////////////////////////
///   Example program to blink an LED connected to GP0
///
///   Fuses: LP,XT,INTRC,HS,NOWDT,WDT,CPD,NOCPD,PROTECT,NOPROTECT,NOMCLR
///   Fuses: MCLR,PUT,NOPUT,RC,EC,RC_IO,INTRC_IO,BROWNOUT,NOBROWNOUT
///   Fuses: BANDGAPLOW,BANDGAPHIGH
/////////////////////////////////////////////////////////////////////////

//   Preprocessor
#include <12F675.h>
#device ADC=10
#fuses INTRC,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5

void init()
{
   set_tris_a( 0b11111110 );         // set GP0 output, all other inputs   
   setup_comparator( NC_NC_NC_NC );   // disable comparators
   setup_adc_ports( NO_ANALOGS );      // disable analog inputs
   setup_adc( ADC_OFF );            // disable A2D
}

//   Main Program
main()
{
   init();
   while ( TRUE )                  // blink LED
   {
      output_high( GP0 );            // turn LED on
      delay_ms( 250 );            // wait 250ms
      output_low( GP0 );            // turn LED off
      delay_ms( 250 );            // wait 250ms
   }
}
brokebit



Joined: 21 May 2004
Posts: 3

View user's profile Send private message

Still nothing
PostPosted: Sat May 22, 2004 1:32 pm     Reply with quote

Languer,

I cut and pasted your code example, it compiled fine, and I was able to sucesfully write it to the pic using the PICKit programer; however, It still will not flash any LED.

Very strange. Is there somewhere I can look for documentation on some of the Pre-Processor commands such as FUSE and DEVICE ADC? I have the CCS Refrence manual, but it does not go into to much detail.

Also, when wiring this up on a breadboard, I did not include any external components. Only a +5V source on pin 1, and GND on pin 8.

THoughts, comments, suggestions welcome.

Eric.
Stuck in Fujisawa
Guest







Clock?
PostPosted: Sat May 22, 2004 11:27 pm     Reply with quote

What is your clock? 400 kHZ, or should it really be 4 MHz? Just a thought...
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

Corrections to original code
PostPosted: Sun May 23, 2004 12:48 am     Reply with quote

The following corrections were made to original code to blink GP1 on the PICKit (not GP0, as GP0 is used in for the A2D section).
Code:
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR

note that I missed the _IO originally.
Code:
set_tris_a( 0b11100001 ); // set GP1-GP4 to outputs, all other inputs

GP2-GP3 had to be set to low (not left floating as originally) to let the current flow to the LED.
Code:
main()
{
   init();
   output_low( GP2 );   // set low
   output_low( GP3 );   // set low
   output_low( GP4 );   // set low
   while ( TRUE )   // blink LED
   {
      output_high( GP1 );   // turn LED on
      delay_ms( 250 );   // wait 250ms
      output_low( GP1 );   // turn LED off
      delay_ms( 250 );   // wait 250ms
   }
}

Note that this will blink D7 on the PICKit board. Are you using the PICKit board to test your code or just program, and then run the chip on its own board?

As I think you're doing the later, I would test it first on the PICKit. Now given the fact that you can't blink a non-existent LED on GP0 in the PICKit, you will need to modify this in your board. In theory you would just need the +5V and GND as you pointed (a bypass capacitor is recommended on +5V). You also want a current-limiting resistor (such as R8 on PICKit) between GP0 (or GP1 if you change it) and LED. Make sure LED is installed correctly with anode to GP0 and cathode to GND (hey, it happens sometimes).

As for the Pre-Processor stuff, the help file has a dedicated section for this. The device-file has the possible FUSES.

Hope it helps.
brokebit



Joined: 21 May 2004
Posts: 3

View user's profile Send private message

PostPosted: Tue May 25, 2004 8:46 pm     Reply with quote

Languer,

I made the changes but Im still a little confused by the #Fuses pre-processor stuff. I found the following in the help file, however I have not found definitions of the various options, i.e. INTRC_IO, NOCPD, etc:

Code:
Syntax:
 #fuse options

 
 
Elements:
 options vary depending on the device.  A list of all valid options has been put at the top of each devices .h file in a comment for reference.  The PCW device edit utility can modify a particular devices fuses.  The PCW pull down menu VIEW | Valid fuses will show all fuses with their descriptions.

 

Some common options are:

·   LP, XT, HS, RC

·   WDT, NOWDT

·   PROTECT, NOPROTECT

·   PUT, NOPUT   (Power Up Timer)

·   BROWNOUT, NOBROWNOUT

 
 
Purpose:
 This directive defines what fuses should be set in the part when it is programmed.   This directive does not affect the compilation; however, the information is put in the output files.   If the fuses need to be in Parallax format, add a PAR option.   SWAP has the special function of swapping  (from the Microchip standard) the high and low BYTES of non-program data in the Hex file.  This is required for some device programmers. 

 
 
Examples:
 #fuses  HS,NOWDT

 
 
Example Files:
 ex_sqw.c

 
 
Also See:
 None
 


Thanks
Eric.
brokebit



Joined: 21 May 2004
Posts: 3

View user's profile Send private message

Re: Clock?
PostPosted: Tue May 25, 2004 8:46 pm     Reply with quote

Stuck in Fujisawa wrote:
What is your clock? 400 kHZ, or should it really be 4 MHz? Just a thought...


Why is your subject Stuck in Fujisawa?
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Wed May 26, 2004 1:29 pm     Reply with quote

Eric,

The following #FUSES are found in the device file 12F675.h under the DEVICES subdirectory.
Code:
// Program memory: 1024x14  Data RAM: 64  Stack: 8
// I/O: 6   Analog Pins: 4
// Data EEPROM: 128
// C Scratch area: 20   ID Location: 2000
// Oscilator Calibration Address: 90
// Fuses: LP,XT,INTRC,HS,NOWDT,WDT,CPD,NOCPD,PROTECT,NOPROTECT,NOMCLR
// Fuses: MCLR,PUT,NOPUT,RC,EC,RC_IO,INTRC_IO,BROWNOUT,NOBROWNOUT

Each device has their own set of associated FUSES. The FUSES are not defined, but they should have a one-one relationship with the datasheet (section 9.1 for the PIC12F629/675).

One more thing, I just realized that on the new device files the BANDGAP configuration was removed.
Code:
///   Fuses: BANDGAPLOW,BANDGAPHIGH

For good reason probably as these are factory set.

Hope this helps,

languer.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group