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

SORTED: Please Help a Programming Newbie - 16F873A

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



Joined: 02 Jan 2009
Posts: 6

View user's profile Send private message

SORTED: Please Help a Programming Newbie - 16F873A
PostPosted: Fri Jan 02, 2009 8:31 pm     Reply with quote

Right. I'm new to the micro controller game.
I've been playing with making simple programs with 12F683's which have an internal oscillator and they have been going fine Smile
But i need more I/O pins so I got me a few 16F873A's as they seem to be easy to get hold of, have the I/O pins I need and have plenty of stuff about them out there on the net.
The problem is I can't get any code to run on them :( as 16F873A's don't have an internal oscillator I also got me some 20Mhz Ceramic Resonator's (ZTT design - as I read these work) to run them. But I can't seem to get the things to work :(

For example I have the following code
Code:
#include <16F873A.H>
#use delay(oscillator=20M)
#fuses  NOLVP

void main() {
while(1)
   {
      output_bit(PIN_A0,0);
      delay_ms(100);
      output_bit(PIN_A0,1);
      delay_ms(100);
     
   }
}

I've used multiple variations of the same code but still can't seem to get the thing to work.
I have the chip wired like this:
Pin 19 - VSS - to ground
Pin 20 - VDD - to +V5 (provided by a voltage regualator)
Pin 9 - OSC1 - To the left pin of the Ceramic Resonator
Pin 10 - OSC2 - To the right pin of the Ceramic Resonator
(middle pin of the Ceramic Resonator to ground)
Pin 2 - A0 - to the Anode of a LED
(cathode of the LED to ground thou a resistor)

once i power the chip nothing happens, I don't have access to any special tools to see whats happening inside the chip - but if i use the same code on a 12F683 it works fine
Code:
#include <12F683.H>
#use delay(clock = 20000000)

void main()
{
While(1)
   {
      output_high(PIN_A0);
      delay_ms(100);
      output_low(PIN_A0);
      delay_ms(100);
   }
}


I'm guessing I'm doing something wrong with the oscillator and I'm hoping one of you can point me in the right direction... if you need anymore info or anything just post back

Thanks Smile

OH BTW: I'm using the latest version of the compiler Smile

EDIT: Found the info i needed (I swear i searched and found nothing)
http://www.ccsinfo.com/forum/viewtopic.php?t=37157
i was using the wrong #fuses :S
changed the top to
Code:
#fuses HS,NOWDT,NOLVP
#use delay(clock=20M)
All was well Smile and added a voltage to the reset pin as the code was only running for a short time before stopping (I had tried running the reset pin high but wasn't getting anywhere)
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Fri Jan 02, 2009 10:50 pm     Reply with quote

What are you doing with the MCLR pin? You should have it pulled up to Vcc via a resistor, say 4.7K.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
Razo



Joined: 02 Jan 2009
Posts: 6

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 10:13 am     Reply with quote

Thats exactly how i'm pulling it up Smile
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