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

PIC12F683 won't run stand-alone

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



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PIC12F683 won't run stand-alone
PostPosted: Fri Feb 24, 2012 3:57 pm     Reply with quote

The program below runs fine using the CCS PIC12F683 dev board with the ICD. But when I remove #device ICD=TRUE and program either the 14-pin ICD chip or a standard 8-pin chip it doesn't run past the first 'if" statement. Same if I program a PIC separate from the dev board. I've tried changing the fuses, clock speed, etc., but no joy. Any ideas?

Code:
#include <12f683.h>
//#device ICD=TRUE
#device ADC=10
#fuses INTRC_IO, NOMCLR, NOWDT, NOPROTECT
#use delay(clock=4000000)
#use fixed_io(a_outputs=PIN_A2,PIN_A4,PIN_A5)

/*
   Pin-out
       (+3.3V) 1 - VDD            VSS - 8 (0V)
   (INDEX OUT) 2 - GP5        GP0/AN0 - 7 (INDEX IN)
    (CH A OUT) 3 - GP4/AN3    GP1/AN1 - 6 (CH A IN)
               4 - GP3        GP2/AN2 - 5
*/

#define ADC_FS    1023
#define HYST      100

                           // PIC12F683 dev board
#define LED_GRN   PIN_A2   // pin 5 = Green LED
#define INDX_IP   0        // pin 7 = AN0
#define CH_A_IP   1        // pin 6 = AN1
#define INDX_OP   PIN_A4   // pin 3 = Red LED
#define CH_A_OP   PIN_A5   // pin 2 = Green LED

void main()
{
   int8 n, db;
   int16 adc_result[2];
   
   setup_adc_ports(sAN0|sAN1);
   setup_adc(ADC_CLOCK_INTERNAL);
   
   output_high(INDX_OP);
   output_high(CH_A_OP);
   
   db=read_eeprom(0);
   
   if (db!=170){
      for(n=0;n<3;++n){
         output_high(LED_GRN);
         delay_ms(150);
         output_low(LED_GRN);
         delay_ms(150);
      }
      write_eeprom(0,170);
      output_low(LED_GRN);
      delay_ms(500);     
      output_high(LED_GRN);
      delay_ms(500);
      output_low(LED_GRN);   
   }
   
   for(n=0;n<3;++n){
      output_high(LED_GRN);
      delay_ms(150);
      output_low(LED_GRN);
      delay_ms(150);
   }
   
   while(1){

      set_adc_channel(INDX_IP);
      delay_ms(1);
      adc_result[INDX_IP]=read_adc();
     
      set_adc_channel(CH_A_IP);
      delay_ms(1);
      adc_result[CH_A_IP]=read_adc();
     
      if(adc_result[INDX_IP]>(ADC_FS/3)){
         output_high(INDX_OP);
      }
      else output_low(INDX_OP);
     
      if(adc_result[CH_A_IP]>(ADC_FS/3)){
         output_high(CH_A_OP);
      }
      else output_low(CH_A_OP);

      for(n=0;n<3;++n){
         output_high(LED_GRN);
         delay_ms(150);
         output_low(LED_GRN);
         delay_ms(150);
      }
   }
}
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 24, 2012 5:44 pm     Reply with quote

Don't know if it applies to you but...
..if using MPLAB, is the 'build configuration' set to 'debug' and not 'release'?

IF 'debug', you need to change to 'release', then recompile (F10) , then download the code....
embedder



Joined: 11 Feb 2010
Posts: 19

View user's profile Send private message

PostPosted: Mon Feb 27, 2012 7:36 am     Reply with quote

Thanks temtronic. I don't think it applies, but I will experiment with the fuses a bit more. I feel like I am missing something obvious. Anyone?
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