|
|
View previous topic :: View next topic |
Author |
Message |
dsaari
Joined: 05 May 2006 Posts: 25
|
16F1824 clock setup |
Posted: Wed Jul 17, 2013 7:26 pm |
|
|
Hello all,
I'm trying to simply understand what I might be doing wrong. I've recently started programming a new PIC that I'm not too familiar with. It's the 16F1824 MCU. I wrote a "hello world" program with hopes that I could toggle an LED and printf something to the debug terminal. Super simple program.
Anyway, when I compile it for the ICD-U64 debugger and attach/load my program; at the bottom it says "READY; MCU running at 0.5MHz". When I press the little play button to start my code it acts as though I stepping through the program as opposed to running continuous like I am used to, but, more importantly, nothing happens like my LED coming on or anything in the monitor window. I am familiar using the debugger and the monitor window, so some of the simpler things like "enable monitor = true" can be ruled out.
I am concerned that I have not set up the clock properly. Additionally, this PIC has no place to connect PIN6 of the ICD unless I misunderstood the connection diagram. I have programmed the PIC for use without the debugger (normal uart pin settings) and the LED does blink at an apparent 1 sec interval. I didn't check the serial output though. Can anyone point me to what I am doing wrong?
Any help is much appreciated.
Compiler version 5.009
Code: | #include <16F1824.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES DEBUG //Debug mode for ICD
#FUSES NOWRT //Program Memory Write Protected
#FUSES PLL_SW // PLL under software control, disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOCLKOUT //Output clock on OSC2
#use delay(clock=32000000)
#use rs232(debugger)
#define LED PIN_C3
void main()
{
setup_oscillator(OSC_8MHZ | OSC_NORMAL | OSC_PLL_ON);
while(true)
{
output_toggle(LED);
printf ("Hello World n\r");
delay_ms(1000);
}
} |
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jul 18, 2013 4:28 pm |
|
|
align your use delay with your int clock
on one line is 32 mhz then you call for a setup 8 mhz
make up your mind
SIMPLIFY !!
use just the internal 8 mhz speed
then
try a normal #use rs232 and read the port with a Term prog
or just select 32mhz straight up
lose the debugger declaration and see what you get
and perhaps try a 1 sec LED flasher to see if your clock is OK |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Jul 19, 2013 4:19 am |
|
|
The 32/8MHz part is OK.
He is selecting the 8MHz clock, with the *4PLL turned on, which gives 32MHz.
The clock settings are perfectly legitimate.
The Pin6, is 'optional'. It can be connected to any pin on the PIC (supporting output), or should be driven high (this was required on older debuggers, but is now 'optional', but 'better practice'. B3, was the 'standard' on PIC's having this pin.
Look at:
<http://www.ccsinfo.com/forum/viewtopic.php?t=44287>
Where this is covered.
It is used as a serial output from the PIC, to the ICD.
I would get rid of the extra spaces between the '#use', and 'delay'. CCS has a habit of being finicky about such things, but not always complaining. It actually sounds as if the ICD, is not detecting what the clock speed set in the code is.
I'd try the alternative way of setting the clock speed:
Code: |
#include <16F1824.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES NOWRT //Program Memory Write Protected
#FUSES PLL_SW // PLL under software control, disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOCLKOUT //Output clock on OSC2
#device ICD=TRUE
#OCS 20 MHz
|
I don't see how you can specify '#use rs232(debugger)', without the debugger RS232 connection. This may well be causing the problem.
Best Wishes |
|
|
|
|
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
|