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

problem by Spontaneous pic

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



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

problem by Spontaneous pic
PostPosted: Wed Feb 27, 2013 9:09 pm     Reply with quote

hello
I am working by pic16f72.
The program consists of a several functions.
My problem is with the micro After several days of working on their own.
Why are function calls Spontaneous?
The program uses the timer1 & interrupt timer1.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 28, 2013 12:26 am     Reply with quote

Read these threads and the possible solutions given in them:

Simple source code = Erratic behaviour -
http://www.ccsinfo.com/forum/viewtopic.php?t=41964

large code. Strange behavior -
http://www.ccsinfo.com/forum/viewtopic.php?t=39439
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Wed Mar 06, 2013 5:53 am     Reply with quote

Is not resolved problem.
I am work by interrupt timer1.
When a program is in the main function, sometimes order if{} will be ignored and inside order if{} runs. The problem is interrupt timer1.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Mar 06, 2013 6:35 am     Reply with quote

Can you post a SHORT complete compilable code which shows the problem?

Mike

EDIT Yes I know it's a lot to ask, but you don't give us much to work on.
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Thu Mar 07, 2013 8:12 am     Reply with quote

code is :
Code:

#define led pin_c5
#define pushb pin_b2
int16 sh;int8 ll=0,zr=0;

 #int_timer1
   void Timer1_isr()
   {zr+=1; ll+=1;
    if(ll>=255){
sh+=1;}
     tmr1on=1; set_timer1(65216);
 }
 
 //---------------------------------------------------------
 void main(){int8 i; output_b(0b0);
  setup_timer_1 ( T1_internal | T1_DIV_BY_1 );
  enable_interrupts(INT_TIMER1);
  enable_interrupts(GLOBAL);
  set_tris_b(0b00000101);set_tris_a(0b0000011);
     
  while(true){
 
 //*******************push button*****************************************
  if(input(pushb)){
sh=0;
output_low(led);
  while(input(pushb)){
if (sh>300){
erase();
}
  }
    }
  and Continuation program............
 
  }
  //----------------------------------------------------------------------
  void erase(){ int16 i=0;
  i=0;
  while(i<1024){
  output_high(led);
write_ext_eeprom(i,255);
  delay_ms(2);i++; };
  }
 



when the main loop program is running , this goes on:

Code:
if(input(pushb)){sh=0; output_low(led);
  while(input(pushb)){if (sh>300){erase();}}}


and then erase() function runs


but it must not happen.and it is because of timer1 interrupt.
what should i do to stop it?


Last edited by mahdifahime on Thu Mar 07, 2013 12:05 pm; edited 2 times in total
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Mar 07, 2013 8:45 am     Reply with quote

Shocked

This is really confusing code. The formatting is so very poor that it makes it difficult to understand what any of it does. If I reformat that little piece of code I get this:

Code:

if(input(pushb))
{
   sh = 0;
   output_low(led);
   while(input(pushb))
   {
      if (sh > 300)
      {
         erase();
      }
   }
}


I think this is meant to detect if the button has been pressed, and then if its held for a time, depending on how often the timer1 ISR runs, then erase() is called. One obvious problem is that if the button is kept down erase() will be called over and over again as sh is never reset.

Also I notice that main starts like this:

Code:

while(true){m:


that 'm:' is a label, so you must have a goto somewhere. Do you?

There's so much wrong with this code: short, meaningless variable names, very poor formatting, gotos to name only three, that I haven't seen anything like it since the early days of BASIC.

Good luck getting any of it to work!

RF Developer
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Mar 07, 2013 11:01 am     Reply with quote

I asked for SHORT COMPLETE COMPILABLE code.

I want something I can cut and paste without too much effort on my part.
After all, you're the one asking for help.

Also:-

You have not used the code button.
It preserves formatting which helps make code easier to read.

Mike

+++++++++++++++++++
He edited to use Code button after Mod's suggestion.

- Forum Moderator
+++++++++++++++++++
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Thu Mar 07, 2013 1:24 pm     Reply with quote

please post your master clock /delay statement

also
as coded the timer int is going to be called VERY frequently -

AND

when you call ERASE() - it's execution is bound to be much longer than any one timer #int period
unless the master clock is 5khz or so Very Happy Very Happy Very Happy
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Thu Mar 07, 2013 11:48 pm     Reply with quote

asmboy wrote:
please post your master clock /delay statement

also
as coded the timer int is going to be called VERY frequently -

AND

when you call ERASE() - it's execution is bound to be much longer than any one timer #int period
unless the master clock is 5khz or so Very Happy Very Happy Very Happy


please give me an example that in loop interrupt timer1 write in external eeprom.
thanks Wink
ckielstra



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

View user's profile Send private message

PostPosted: Fri Mar 08, 2013 6:11 am     Reply with quote

We always ask for a complete, compilable, program. That is because it makes it easier to us to just copy/paste your program, but also because then we have your fuses and delay statements.
So, as someone else already asked, please post your #fuses and #delay lines.

Code:
 //*******************push button*****************************************
  if(input(pushb)){
sh=0;
output_low(led);
  while(input(pushb)){
if (sh>300){
erase();
}
  }
Assuming your clock is running at a slow 2MHz, you will have to hold the push button for 4.9 seconds to activate erase, but at 20MHz it activates in just 0.49 seconds.
Do you see why we want to know your clock frequency?

Quote:

please give me an example that in loop interrupt timer1 write in external eeprom.
Sorry, but I don't understand the question. Can you give a longer explanation of what you want to do?
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