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

Function with IO ports as arguments

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



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

Function with IO ports as arguments
PostPosted: Thu Jul 12, 2012 3:13 am     Reply with quote

Hi,
I would like to built two function with port as argument for write and read data in port, so e.g:
Code:

#include <18F46k20.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20M)

#define LedOK Pin_B1
#define LedNG Pin_B0

Led(int8 *Port)
{
   output_low(Port);
   delay_us(1000);
   output_high(Port);
   delay_us(1000);
   output_low(Port);
}
main()
{
   int8*pointLedOK = LedOK;
   Led(*pointLedOK);
   while(1)
}

I used pointer but i didn't work.
Where i made mistake?
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Jul 12, 2012 8:27 am     Reply with quote

A port pin number, is just a number, not a pointer. It is also an int16, not an int8.
So:
Code:

#include <18F46k20.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20M)

#define LedOK Pin_B1
#define LedNG Pin_B0

void Led(int16 pin_number) {
   output_low(pin_number);
   delay_us(1000);
   output_high(pin_number);
   delay_us(1000);
   output_low(pin_number);
}

void main(void) {
   int16 pointLedOK = LedOK;
   Led(pointLedOK);
   while(1) ;
}

Also, I doubt if you will see this. The led will only be on for 1mSec.....

Best Wishes
Requan



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 7:22 am     Reply with quote

Thanks Ttelmah for help.
Quote:

Also, I doubt if you will see this. The led will only be on for 1mSec.....

Yes You right Embarassed
I made mistake instead ms I write us.
Best Regards,
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