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 CCS Technical Support

16F1824 clock setup

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



Joined: 05 May 2006
Posts: 25

View user's profile Send private message AIM Address

16F1824 clock setup
PostPosted: Wed Jul 17, 2013 7:26 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Jul 18, 2013 4:28 pm     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Fri Jul 19, 2013 4:19 am     Reply with quote

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