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

NEED HELP, PLEASE!! - FUNCTION NOT BEEN CALLED

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



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

NEED HELP, PLEASE!! - FUNCTION NOT BEEN CALLED
PostPosted: Sun May 23, 2004 9:36 am     Reply with quote

MPLAB 6.5
PCM V 3.186
MPLAB ICD2

Dear All,

I am in a rut can someone help me please!!!

I HAVE CODED A SIMPLE CLOCK PROGRAM, ThE ACTUAL INCREMENTATION of mins/hours/milli WORKS PERFECT

BUT WHEN I TRY TO CALL THE DISPLAY FUNCTION WITHIN THE ISR() it simply ignores the call

NO COMPILER ERRORS!!!!!!!!

code =
------------------------------------------------------------------------------
#if defined(__PCM__)
#include <16F874.h>
#device ICD=TRUE
#fuses XT,NOWDT,NOPROTECT,NOLVP,PUT,NOBROWNOUT
#use delay(clock=4000000)
#endif

#include <lcd.c>

void display(void);

#bit t0if = 0xb.2


int sec=0; //second
int min=0;//minute
int hrs=0; //hour
int milli=0;
int increment = 0;

char data[16];

#int_rtcc
void clock()
{
increment++;
if (increment==2)
{ milli++;
increment=0;
}
if (milli==10) // 10*100ms = 1second passed
{
sec++;
milli=0;
}
if (sec==60) // 60*1sec = minute
{
sec=0;
min++;
display();
}
if (min==60)
{
min=0;
hrs++;
display(); THIS FUNCTION WILL NOT CALL
}

if ((hrs==24) || (hrs && min==0))
{
sec=0;
hrs=0;
display(); //THIS FUNCTION WILL NOT CALL
}
if (milli < 10) //milli lower than 10 exit after incrementing milli
set_RTCC(60); //setup TMR0 to count upto 100ms

}
void display(void)
{
lcd_init();
if (t0if==TRUE)
{
lcd_gotoxy(0,1);
printf(lcd_putc,"%02U:%02U",hrs,min);
}
else
{
lcd_gotoxy(1,1);
printf(lcd_putc,"%S",data);
}
}






void main()
{

enable_interrupts(int_RTCC);
enable_interrupts(GLOBAL);

setup_counters(RTCC_INTERNAL,RTCC_DIV_256);

set_RTCC(60);





}
_________________
Best Regards
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun May 23, 2004 11:02 am     Reply with quote

Try to set a flag in ISR and in main loop call this LCD function.
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

Clarifying the question question
PostPosted: Sun May 23, 2004 11:03 am     Reply with quote

The function of the code is a "real time clock"

Within the ISR I call a function called "display()", this function updates the time on the LCD using the standard CCS drivers.

When I step throught the code the system seems to ignore the call to the display function all together.

The ISR is working as I can see the variables min, hour, milli being incremented as a real time clock.

NO COMPILER ERRORS

I thankyou in advance for advising me!
_________________
Best Regards
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

function will not be called even from the
PostPosted: Sun May 23, 2004 11:11 am     Reply with quote

If I try to call the fucntion from function main, it will still not branch

Is the compiler version bug free?
_________________
Best Regards
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Sun May 23, 2004 11:14 am     Reply with quote

You should not call code like "printf" from inside ISRs. Two reasons, one is it takes too long to execute and second is that printf is not re-entrant.

Set a flag inside your ISR indicating there is new data to print or keep a phantom copy outside the ISR and test for new data in your main.

Code:

int1 newdata;

void main(void)
{
   newdata=0; // initialize boolean flag
   // your initialization routines here to set up timer, etc

   while(1)
   {
      if (newdata)
      {
         display();
         newdata=0; // clear new data flag
      }
      // do other things in you main or just let it run a
      // tight loop looking for new data to display...
   }
}

#int_rtcc
void clock()
{
   if (!newdata) // use this to block changes to data structure during
   {                 // display().  otherwise just run your code
      // your code goes here
   }
   newdata=1; // signal new data ready
}

_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








Re: Clarifying the question question
PostPosted: Sun May 23, 2004 11:14 am     Reply with quote

asjad wrote:
The function of the code is a "real time clock"

Within the ISR I call a function called "display()", this function updates the time on the LCD using the standard CCS drivers.

When I step throught the code the system seems to ignore the call to the display function all together.

The ISR is working as I can see the variables min, hour, milli being incremented as a real time clock.

NO COMPILER ERRORS

I thankyou in advance for advising me!


As the previous reply:

DO NOT call your LCD function from inside of the ISR.
Make a global flag

int flag=0;

the in the ISR set it to 1

and somwwhere in your main loop test the flag and then call the LCD function

somewhere in main loop

if ( flag == 1 )
{
LCD();
flag=0; // allow it to be called again
}
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