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

Function Pointer PIC18 CCS bug?

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







Function Pointer PIC18 CCS bug?
PostPosted: Thu Jun 01, 2006 2:15 am     Reply with quote

Hallo All
I have sample code which is not working is I'm using function pointer to turn-on red led (LED is turned-on when pin_A0=0)
PS.
I did the same way as shows CCS example "ex_qsort.c" in /examples directory!

#include <18F2550.h>
#byte LATA = 0xF89
#byte TRISA = 0xF92
//#device *=16 // 16 bit pointers

// *** ROM program locations *** //
#build( reset=0x0A00, interrupt=0x0A00+8)
#org 0x0000, 0x0A00-1 { } // bootloader

// CPU clock (config determined in bootloader)
#define FREQ_CPU 48000000 // 48Mhz
#use delay ( CLOCK = FREQ_CPU, RESTART_WDT )

#define LED_RED PIN_A0
#define RED_ON output_low( LED_RED )
#define RED_OFF output_high( LED_RED )

typedef void (*HandlerFun) ();
void hRedOn() {RED_ON;}
void hRedOff() {RED_OFF;}

//----------------------------------------------------------
void main (void)
{
HandlerFun hFun;

delay_ms( 10 ); // need to wait for PLL?
LATA = 0xff; // all leds off!
TRISA = 0x0; // all outputs
delay_ms( 100 );


hRedOn(); // force CCS to this link function
hRedOff();

hFun = hRedOn;
while(1)
{
(*hFun)(); // like in example "ex_sort.c" but here not
working!!!
//goto_address(hFun);// not working also!
//hRedOn(); // WORKING!!!
restart_wdt();
}

return;
}

Ktos zna ten bug?
Ttelmah
Guest







PostPosted: Thu Jun 01, 2006 4:45 am     Reply with quote

This is _C_, not C++. There is a very fundamental difference in the way that 'void' is understood.
Seperately though, there is a probable problem with trying to generate addresses for the internal 'functions' output_high, and output_low. These are almost certainly macro definitions, _not_ actual functions.
If you want to use these through pointer accesses, then put each into a wrapper function, and generate the addresses of these. If you look at the 'call tree' for a program, you will see that there is no call ever occuring to these names, making it certain that they are macros, not actual funstions.

Best Wishes
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