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

Using the delay_ms function / oscillator configuration

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



Joined: 06 May 2010
Posts: 22

View user's profile Send private message

Using the delay_ms function / oscillator configuration
PostPosted: Thu May 06, 2010 9:55 am     Reply with quote

Hi,

I'm using a PIC18F4580 and using its internal 8Mhz oscillator.

As far as I know the delay_ms function will create a delay in milliseconds of the parameter you give to it. But it seems that this is not working in my code or at least working at a much greater rate than it should - when I use the function it seems as if there is no delay at all!

I have the following code in my main.c file:
Code:
#include "main.h"

void main()
{
   output_high(PIN_B2);
   output_low(PIN_B3);
 
   while(TRUE)
   {
         delay_ms(1000);
         output_toggle(PIN_B3);
         delay_ms(1000);
         output_toggle(PIN_B2);
   }

In my main.h file I have:
Code:
#include <18F4580.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES BBSIZ2K                  //2K words Boot Block size
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES XINST                    //Extended set extension and Indexed Addressing mode enabled

#use delay(clock=8000000)

I have LED outputs connected to B2 and B3. When I run this code they should blink alternately but so far one just stays lit all the time and the other does not light.

Have I got my program configured correctly to use the internal oscillator for this chip?
And if so, why is the delay_ms function not working as it should?

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Thu May 06, 2010 10:03 am     Reply with quote

Change XINST, to NOXINST. CCS does not support XINST.
Have you got a pull up on MCLR.
Have you got a pull down on the PGM pin. You have LVP selected, if this is wanted (it rarely is....), you _must_ ensure the PGM pin is pulled down, when you want to run the chip.

Best Wishes
adamp524



Joined: 06 May 2010
Posts: 22

View user's profile Send private message

PostPosted: Fri May 07, 2010 1:46 am     Reply with quote

Thanks,

Changing to NOXINST and removing LVP fixed it!
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