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

Program hang--CCS compiler problem?

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



Joined: 21 Oct 2004
Posts: 9

View user's profile Send private message

Program hang--CCS compiler problem?
PostPosted: Tue Apr 12, 2005 8:01 pm     Reply with quote

Hi,
Is it possible for the program run to an non-implemented memory area?
In debug mode, I have encounted this problem.

My device with progammed PIC16F684 run very well. But it hangs somewhere in one test and i can not repeat this problem again.

I am using

CCS PCM C Compiler, Version 3.217, 27214

Appreciate any advise

Confused
_________________
CC
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Apr 12, 2005 8:21 pm     Reply with quote

You will need to post code to get help
Guest








PostPosted: Tue Apr 12, 2005 8:48 pm     Reply with quote

Here is the main program
Code:


   
#include "D684BB.h"
#DEVICE adc=8   

#fuses INTRC_IO,NOPROTECT,WDT //NOWDT
#use delay (clock=4000000)  //4M hz internal osc

#include "DinitialBB.c"
#include "DcommonBB.c"


/************************************************************
          Main program
*************************************************************/
void main()
   { int t1=0;
     int t2=0;
     int t3=0;
     delay_ms(200);  // add on 13/4 until stable  ??
//----------------ini-----------------
//----WDT initialization---
        SETUP_WDT(WDT_DIV_65536);

     //----ADC initialization---
      SETUP_ADC_PORTS(sAN4|sAN5|sAN6|sAN7|VSS_VDD);       setup_adc( ADC_CLOCK_INTERNAL );   //internal 2-6us
    
      SETUP_COMPARATOR(NC_NC_NC_NC);   
//----Timer1 initialization---
        SETUP_TIMER_1(T1_INTERNAL|T1_DISABLED|T1_DIV_BY_8);    //prescale=1:8, internal clock
        #asm
        bcf 0x03,0x5  //bank0
        bcf 0x10,0x0 //tmr1on=0, stops timer1
        #endasm
//----Timer0 initialization---
        
        #asm
        clrwdt   // clr WDT and postscaler
        bsf 0x03,0x5  //bank1
        movlw 0x06  //'00000110'    //prescale=128, internal cloc
        movwf 0x81   //save in option_reg
        bcf 0x0B,0x5  //disable TIM0 intp
        bcf 0x03,0x5  //bank0
        #endasm
                    
 //----I/O initialization---
 // change to asm code due to register not set correctly
      #asm
     bcf  0x03,0x5      //bank 0
     clrf    0x05       //
                  clrf    0x07       //;Init PORTC

     bsf  0x03,0x5       //bank 1

    
     movlw 0x08
     movwf 0x85       //set TRISA RA0-2,RA4,5  as output
     movlw 0x0f
     movwf 0x87       //set TRISC Rc4,5 as output,other as input
    
     #endasm
   
    //init();  // init for ADC, I/O, Timer

//--------------------------------
     LED_Blink(3,1,30); // indication of MCU working
    
//--------check Beam connection-------------------------
       
          set_adc_channel(FBACK);
          delay_us(20);          
chk:      t1=read_adc();            
         t2=read_receiving(3,10,1);
         delay_us(50);         
         t3=read_receiving(3,20,1);
         delay_ms(10);
                                         
//based on above reading, find out which beam is connected                  
         
           if((t1-t2)<(t1-t3))//(abs(t1-t3)-abs(t1-t2))>5)
             Beam=2;   
                                 
          else if((t1-t3)<(t1-t2))
               Beam=4;
          if(t1<10)                              Beam=0;                 
          if(t1>51&&(abs(t2-t3))<5) //2.5V
          Beam=6;                
//-----------indication-----------------
          if(Beam==0)
          {LED_Blink2(2,200);
           goto chK;
          }                       
          Beam=2;    -- for sample only
            
          switch(Beam){
                           case 2: output_high(LED1);break;
                           case 4: output_high(LED2);break;
                           case 6: output_high(LED2);output_high(LED1); break;
                             };
                delay_ms(250);
                 #asm
                   bcf 0x03,0x5  //bank0
                   clrwdt
                   #endasm                 delay_ms(250);
                 #asm
                   bcf 0x03,0x5  //bank0
                   clrwdt
                   #endasm //; clear watch dog
                delay_ms(250);
                 #asm
                   bcf 0x03,0x5  //bank0
                   clrwdt
                   #endasm //; clear watch dog
                 switch(Beam){
                           case 2: output_low(LED1);break;
                           case 4: output_low(LED2);break;
                           case 6: output_low(LED2);output_low(LED1); break;
                             };       //to indicate which beam connected
 
//-------------checking receiving-----------------------
           
      if (bit_test(Beam,1))
      ION1=AlignmentCheck(1) ;   
     
      if (bit_test(Beam,2))
      ION2=AlignmentCheck(2) ;   
             
     

      
          if(Beam==2)
         NoTarget2=60;           if(Beam==4)
         NoTarget1=60; 
/*-----------------------------------------
         main detection start
-------------------------------------------   */
         
//----------enable TIM1 & TIM0 intp---------------             
          #asm   
          bsf 0x3,0x5  //bank1
          bsf 0x8c,0x0// PIE1.0=1 ,enable timer1 intp
          bcf 0x3,0x5  //bank0
          bcf 0x0c,0x0   // clr overflow flag PIR1.0
          bsf 0x10,0x0 //tmr1on=1, starts timer1
         // clrf 0x0e   //clear TRM1L
          //clrf 0x0f   //clear TRM1H
          bsf 0x0B,0x6//   PEIE of INTCON=1, enable peripheral intp
          bcf 0x0B,0x2//   T0IF of INTCON=1 , clear timer0 overflow flag
          clrf 0x01   // clr TMR0
          bsf 0x0B,0x5//   T0IE of INTCON=1 , enable timer0 intp
          bsf 0x0B,0x7//   GIE of INTCON=1 , enable global intp
          #endasm              
       //SETUP_WDT(WDT_ON);   // Start WDT
//-------------------------------------------   
Chk1:    if (bit_test(Beam,1)==1) 
           { CH=10;
                
             goto process;
           }
Chk2:    if (bit_test(Beam,2)==1)
            CH=20;
process: 
           if (done==0)     //done=1 means (TIM1 intp finish)
           goto process;
                 
          done=0;

           if(NoTarget1>=Counter_Notarget && NoTarget2>=Counter_Notarget&&TCont>13&&rlyOn==1)
              {

                   #asm
                   bcf 0x3,0x5  //bank 0
                   bcf 0x5,0x0                     #endasm
                   TCont=0;
                   rlyOn=0; 
               }
           
         
           if(RCont>100)
             {
             SET_TIMER1(0); 
             #asm   
             bcf 0x3,0x5  //bank0
             bcf 0x10,0x0 //T1CON-tmr1on=0, stops timer1
             #endasm
            
             delay_ms(10);
             Read_TRIM();
             RCont=0;
            
             #asm   //
             bcf 0x3,0x5  //bank0
             bsf 0x10,0x0 //T1CON-tmr1on=1, starts timer1
             #endasm
          
             }     
             if(CH==10)
              goto Chk2;
              else
              goto Chk1; 
         
}



Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 13, 2005 6:30 am     Reply with quote

Well the first thing I look for is to make sure that NOLVP is specified in the fuses. Not all devices have this but I can't tell since you didn't tell us which PIC you are using.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Apr 13, 2005 7:16 am     Reply with quote

It is a complex, long and incomplete code that we canīt test. Ovbiously
you come from the assembler arena and your code talk by you, but let
the compiler to do his work, unless you are sure enough of a well know
compiler bug.
You donīt get any advantage toggling the SFR bits by yourself.
Try to post a short code that we can duplicate in bench.
Using goto in C is a non recomended practice, there are nothing
than you canīt do using the C statements.

Humberto
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 13, 2005 10:45 am     Reply with quote

Quote:
you didn't tell us which PIC you are using.
Quote:
My device with progammed PIC16F684 run very well.
Quickly browsing through the 14-pin 16F684 manual I couldn't find an LVP pin, so very likely his problem is somewhere else.

What I don't like in his code is the manual setting of the bank-register. One of the strong points in the CCS compiler is that the compiler takes care of selecting the banks, even when writing assembly. You just declare a variable and have the compiler figure out a free memory location and select the correct bank when required. Changing the banks manually should be possible without problems, but this is not as well tested as other parts of the compiler. So why make life hard on yourself by incorporating instructions the compiler can insert and optimise for you?

Quote:
//----I/O initialization---
// change to asm code due to register not set correctly
I'm not sure what kind of error cindyw is talking about. Probably the compiler would react the way he expects by adding #use FAST_IO
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 13, 2005 11:44 am     Reply with quote

Quote:
What I don't like in his code

"He" is a she.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 13, 2005 3:15 pm     Reply with quote

PCM programmer wrote:
Quote:
What I don't like in his code

"He" is a she.
Oops. Thanks for correcting me. Embarassed
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