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

Newbie Question

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



Joined: 13 Apr 2004
Posts: 8

View user's profile Send private message

Newbie Question
PostPosted: Tue Apr 13, 2004 4:50 pm     Reply with quote

I'm using a PIC16F627A, and I can't get a signal from any pin. Any help would be greatly appreciated. Here's my code. I don't have any I/O pins grounded: only A7 hooked to an LED/RESISTOR.

I have Vss and Vdd at 5.0V regulated. /MCLR = Vdd (*edit).

Here's My code:
Code:

//--HEADER FILE
#include <16F627.h>
#use delay(clock=20000000)
#fuses INTRC_IO,NOWDT

//--END HEADER FILE

void main() {

   setup_counters(RTCC_INTERNAL,RTCC_DIV_256);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   loop:
      output_high(PIN_A7);
      delay_ms(1000);
      output_low(PIN_A7);
      delay_ms(1000);
   goto loop;

(*edit)
}

TIA!!
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Tue Apr 13, 2004 6:45 pm     Reply with quote

I do not really see much wrong with it.

Only things I would point out is that you should have this,

Code:
#use delay(clock=4000000)

since the INTRC is either 4MHz or 37kHz.

Also, although I do not think it is necessary, you could specify the TRIS registers for the Ports.

e.g.

Code:
...
void main() {
   set_tris_a(0b01111111);  // RA7 output, all others input
   set_tris_b(0b11111111);  // portB all inputs
...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 13, 2004 7:04 pm     Reply with quote

Quote:
I have Vss and Vdd at 5.0V regulated. /MCLR = Vdd (*edit).

Hopefully you really have Vss connected to Ground (and not 5.0v as
stated above).

Quote:
I'm using a PIC16F627A.
#include <16F627.h>

Your include file is set for the "non-A" chip. The "A" and the
"non-A" chip have different programming algorithms. If you
try to program an "A" when MPLAB is set for a "non-A" chip,
I don't know what would happen.
Guest








PostPosted: Wed Apr 14, 2004 1:13 am     Reply with quote

Additionally use NOLVP option in #fuses statement because as you wrote your port pins are floating.
Whizzard9992



Joined: 13 Apr 2004
Posts: 8

View user's profile Send private message

Awesome
PostPosted: Wed Apr 14, 2004 8:45 am     Reply with quote

Thank you all for your input!!!!

I'm a veteran programmer but new to MCUs. I have a book and am drudging my way through it, so please bear with me if my knowledge is like swiss cheese.

I did get it to work, but one comment did spark my curiosity. What is NOLVP? By floating, do you mean thier direction is not specified? I can't find any documentation on it...

Vss = Ground, Vdd = +5.0v, /MCLR = Vdd

My problem was a combination of a number of different things. Firstly, I'm not using a PIC programmer. Instead, I got a Xeltek 3000U. I figured if I was going to drop a gino on a programmer, I would like it to program more than just PICs. I was trying to burn the chip using BINARY instead of INTEL format. Also, I had /MCLR high through a 10K resistor (as it has in my book). Tapping Vdd directly seemed to do the trick. Is the the correct way?

Also, I got it to work without specifying TRISB. I read that this is a depreciated command, so I'm going to avoid it. That's not to say I didn't try it Wink

Thanks again!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Apr 14, 2004 9:42 am     Reply with quote

As far as TRIS, the default is to use standard I/O which should take care of the TRIS registers for you. With Fast I/O or Fixed I/O you have to set data directions yourself.

NOLVP means No Low Voltage Programming. Low voltage programming lets the chip be programmed by voltages in the 0 to 5V range, which is handy if you want to update your code while the chip is in the product. But it also means the program could changed accidentally if pins are left floating. NOLVP means the program can't be changed unless 12V is applied to the programming pin, which makes accidental program corruption much less likely. In a product you should allways tie I/O pins to something. But when experimenting that is not allways convienient.
_________________
The search for better is endless. Instead simply find very good and get the job done.
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

floating
PostPosted: Wed Apr 14, 2004 10:48 am     Reply with quote

Floating is a term that is used when a pin is left unconnected to any other component. Usually, you only have to worry about this when the pin is left as an input. Inputs should never be left floating even if unused. Either you pull them up or pull them down, preferrably to a state that draws the least current or does not alter the way the rest of your circuit must opperate.

Port B on PIC's can usually be configured with weak (draws little current from VCC) pullups for this reason and just in case the input is being driven by an open collector(drain) output of another device.

You could also just set unused pins to outputs.
Whizzard9992



Joined: 13 Apr 2004
Posts: 8

View user's profile Send private message

PostPosted: Wed Apr 14, 2004 11:28 am     Reply with quote

Excellent information. This helped a TON.

Thanks!
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