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

void function pointer

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



Joined: 05 Jul 2010
Posts: 4

View user's profile Send private message

void function pointer
PostPosted: Mon Jul 05, 2010 12:47 am     Reply with quote

Hi everybody,
I am using the folowing code to pass the address of the next function to be executed.
Code:

typedef void (*fn)();
void green()
{
output_bit(pin_green, 0);
delay_ms(500);
output_bit(pin_green, 1);
}
void yellow()
{
output_bit(pin_yellow, 0);
delay_ms(500);
output_bit(pin_yellow, 1);
}
int main(void)
{
fn ptr;
init_hardware();
while (TRUE)
  {
   ptr = green; 
   (*ptr)();
   ptr = yellow;
   (*ptr)();
  }
return 0;
}

My issue is that when I use the CCS debugger I found that the void pointer "ptr" has a one byte value and not 2 bytes as expected.
When executing this code (*ptr)(); using the single step option in the debugger, the debugger becomes irresponsive and I have to click on HALT PROGRAM to stop it. though the code works.
My aim is to be able to use the debugger single step mode and the void pointer to a function at the same time because my code has about 400 lines and without the single step option in the debugger I won't be able to get it to work.

Thanks a lot
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 05, 2010 2:00 am     Reply with quote

Post your PIC and compiler version.
bennisx



Joined: 05 Jul 2010
Posts: 4

View user's profile Send private message

PostPosted: Mon Jul 05, 2010 2:07 am     Reply with quote

PCM programmer wrote:
Post your PIC and compiler version.


My PIC is the 18F4580 and my compiler ver is 4.104

Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 05, 2010 11:47 am     Reply with quote

I installed vs. 4.104, and modified your program so I could test it in
MPLAB simulator. I changed it to do putc() statements so I can see
the results in the Output Window of MPLAB. It works. It displays this output:
Quote:

GyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGy
GyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGy
GyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGyGy

It's possible that you have a CCS debugger/IDE issue. But the compiler
itself produces code that does work, at least in this simple test program.
I don't have the CCS IDE (I use MPLAB) so I can't really help any more
on that.
Code:

#include <18F4580.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)


typedef void (*fn)(void);

void green()
{
putc('G');
}

void yellow()
{
putc('y');
}

void main(void)
{
fn ptr;
//init_hardware();

while (TRUE)
  {
   ptr = green; 
   (*ptr)();

   ptr = yellow;
   (*ptr)();
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 2:05 am     Reply with quote

Agree.
Tried PCM programmers test code, in a hardware ICE, and it reports the pointer as a two byte value, and it works.
Are you sure that it is not just a case of needing to explicitly tell the debugger you are using, that the value is an 'int16', with it possibly assuming the value to be an int8, by 'default?.

Best Wishes
bennisx



Joined: 05 Jul 2010
Posts: 4

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 12:14 pm     Reply with quote

Ttelmah wrote:
Agree.
Tried PCM programmers test code, in a hardware ICE, and it reports the pointer as a two byte value, and it works.
Are you sure that it is not just a case of needing to explicitly tell the debugger you are using, that the value is an 'int16', with it possibly assuming the value to be an int8, by 'default?.

Best Wishes


I found out that the code works fine. It's just when I try to debug it using the single step option. when I reach " ptr = yellow; " or "ptr = green; " I have to click on halt program in order to debug the code further because it becomes irresponsive.
Thank you
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