View previous topic :: View next topic |
Author |
Message |
Razo
Joined: 02 Jan 2009 Posts: 6
|
SORTED: Please Help a Programming Newbie - 16F873A |
Posted: Fri Jan 02, 2009 8:31 pm |
|
|
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
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
OH BTW: I'm using the latest version of the compiler
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 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) |
|
![](templates/subSilver/images/spacer.gif) |
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Fri Jan 02, 2009 10:50 pm |
|
|
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!!! |
|
![](templates/subSilver/images/spacer.gif) |
Razo
Joined: 02 Jan 2009 Posts: 6
|
|
Posted: Sat Jan 03, 2009 10:13 am |
|
|
Thats exactly how i'm pulling it up ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|