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

pic 18f6722

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



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

pic 18f6722
PostPosted: Sun Mar 09, 2014 7:45 am     Reply with quote

i am using the pic18f6722 for the first time. I tried a simple LED toggle program using CCS, but it wont work.

i tried putting some value on one of its port, which works fine.

so i concluded that the delay_ms() function is not working in it. i tried internal oscillator, external oscillator of 4MHZ, but nothing seems to make the delay function work.

if someone would have simple code blinking a led with delay_ms(), working on internal oscillator or external oscillator 4MHz, it would be very helpful.

thankyou in advance.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 09, 2014 7:48 am     Reply with quote

Please show us your program so we can debug it.Select the 'code' button in the line that says 'message body', before and after you 'cut and paste' your program. Also tell us which version of the compiler you have.

Also, please delete the 2nd thread that you have. I suspect you might have pressed the 'submit' button twice(easy to do !).


hth
jay
amit



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

PostPosted: Sun Mar 09, 2014 8:00 am     Reply with quote

this is the file i used for testing
Code:


#include "main.h"

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_low_volt_detect(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);

   // TODO: USER CODE!!
   while(1)
   {
      output_bit( PIN_D0, 0);
      delay_ms(1000);
      output_bit( PIN_D0, 1);
      delay_ms(1000);   
   
   }

}


this is main.h file which i have included
Code:

#include <18F6722.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV25                   //Brownout reset at 2.5V
#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 NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES XINST                    //Extended set extension and Indexed Addressing mode enabled
#FUSES BBSIZ1K                  //1K words Boot Block size

#use delay(clock=8000000)

amit



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

PostPosted: Sun Mar 09, 2014 8:08 am     Reply with quote

i have version 4.038.

the LED does not glows at all with code that i have posted above.

If i swap position of output bit as shown below, the LED glows and does not gets OFF.

Code:

   while(1)
   {
      output_bit( PIN_D0, 1);
      delay_ms(1000);
      output_bit( PIN_D0, 0);
      delay_ms(1000);   
   
   }
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 09, 2014 8:33 am     Reply with quote

possible problem ....

#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)

99.9999% of PIC programmers do NOT use LVP, so change to NOLVP.

also
#FUSES NOPUT //No Power Up Timer

I always set to PUT, as it allows the PIC a little bit of time to get organized internally.


I didn't see anything else that's 'obvious' wrong...though I don't know why the 'code' button didn't work either!

hth
jay


++++++++++++++++++++++
Reason: User amit disabled BBcode in his profile.

Fixed.

- Forum Moderator
++++++++++++++++++++++
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sun Mar 09, 2014 2:58 pm     Reply with quote

Code:

   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);


These are both wrong.
Need to be 'setup_spi(FALSE);' etc..

These will prevent the pins for both SPI1, and SPI2 from being used for normal I/O. Haven't checked what pins they are on this chip, but won't help...

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 09, 2014 3:34 pm     Reply with quote

Quote:
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled

And this is wrong. It will enable the extended instruction set which is
not supported. Your program will do crazy things. Change it to NOXINST.
amit



Joined: 08 Mar 2014
Posts: 7
Location: India

View user's profile Send private message

PostPosted: Tue Mar 11, 2014 7:07 am     Reply with quote

PCM Programmer,

Your suggestion worked i used NOXINST and it worked instantly, thankyou.
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