|
|
View previous topic :: View next topic |
Author |
Message |
Requan
Joined: 11 May 2008 Posts: 74
|
Function with IO ports as arguments |
Posted: Thu Jul 12, 2012 3:13 am |
|
|
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
|
|
Posted: Thu Jul 12, 2012 8:27 am |
|
|
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
|
|
Posted: Fri Jul 13, 2012 7:22 am |
|
|
Thanks Ttelmah for help.
Quote: |
Also, I doubt if you will see this. The led will only be on for 1mSec.....
|
Yes You right
I made mistake instead ms I write us.
Best Regards, |
|
|
|
|
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
|