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 support@ccsinfo.com

12f629 adding a long variable causes program to hang

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



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

12f629 adding a long variable causes program to hang
PostPosted: Tue Sep 01, 2015 9:25 am     Reply with quote

This code runs correctly. If a long variable is introduced, it hangs. Compiler is pcm 4.121
Code:

#include <12f629.h>
#fuses MCLR, PROTECT, NOWDT,INTRC_IO,PUT ,NOBROWNOUT
#use delay(clock=4000000)

#define SENSOR    Pin_A5   
#define LED       Pin_A4
#define BEACON    Pin_A2
#define LEAKMODEENABLE  Pin_A0
#define LED_ON    output_low(LED)
#define LED_OFF   output_high(LED)
#define BEACON_ON  output_high(BEACON)
#define BEACON_OFF output_low(BEACON)

#define THRESHOLD  240

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}


#byte PORTA = 5
#byte WPU = 0x95
/////////////////////////////////////////////
long junk;   //Comment this out and the last line  and all works fine;
             //      otherwise the program hangs.
////////////////////////////////////////////
unsigned char Hit;
unsigned char j;
unsigned char i;
unsigned char Mode = 1;   //1 = normal operation, 0 = light leak detect mode.

void Flash_Beacon(void)
  { BEACON_ON;
    if (Mode)
        delay_ms(20);    // longer flash when not in light leak mode
   else
        delay_us(500);    // shorter flash when in light leak mode


    BEACON_OFF;
  }
void Leak_detect()
   {
    Hit=0;
    for (i=0;i<255;i++)
     {
      LED_ON;     
     delay_cycles(5);

     LED_OFF;
     if (   !input(PIN_A5)  )  { Hit++;}  //               
     
     delay_cycles (2);
     }

   }


void Send_and_receive()
 {
 Hit=0;
 for (i=0;i<255;i++)
     {
      LED_ON;     
     delay_cycles(5);
   

     LED_OFF;
     if (   !input(PIN_A5)  )  { Hit++;}  //               
     else Hit=0;
     delay_cycles(2);
     
    }

   }

void main(void)
  {
  WPU = 1;   //A0 weak pullup on
  set_tris_a(0b00100001);   //A0 input to detect Mode choice
  LED_OFF;  BEACON_OFF;// everything off
  set_options(0x80);
  setup_comparator(NC_NC_NC_NC);
  Mode = input(PIN_A0) ;    // 1 = normal, 0 = leak detect mode
  set_tris_a(0b00100000); //turn off input on A0

 for (j=0; j<(2+Mode); j++)  // 3 flashes for normal mode , 2 for light leak mode
  {BEACON_ON; delay_ms(2);BEACON_OFF; delay_ms(400); 
      }
 delay_ms(3000);
 while(1){
  BEACON_OFF;
  if (Mode)
     Send_and_receive();
  else
   Leak_detect();

  delay_ms(300);
  if (Hit>THRESHOLD*Mode)     
   
         Flash_Beacon();
             
 
 delay_ms(300);

 junk = junk^1;
}
}

johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Tue Sep 01, 2015 9:29 am     Reply with quote

Just figured it out. Need to use "int16" instead of "long"

Spoke too soon. I changed the variable "i" to int16 and the program hung.

Update: I had the programming range set to a fixed number in MPLAB. Changing to "Auto" fixed the issue.

Why does MPLAB report Programming/Verify complete when it is not true?
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Tue Sep 01, 2015 11:06 am     Reply with quote

Because it has successfully programmed the range you have told it to program.....
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Sep 01, 2015 11:44 am     Reply with quote

one other observation:

you use set_tris to declare the I/O pin state for port A
S O . . . .
it is a REALLY good practice to have executed
a
#USE FAST_IO()
declaration for porta before doing the first SET_TRIS operation
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