Page 1 of 1
Implicit Definition Of A Pin
Posted: Sun Jan 13, 2008 3:52 pm
by Widgetman
Hi All,
I know it is probably a silly question, but I need to know how to Implicitally define a I/O pin as a Input on a PIC part to make sure it comes up correctly. I could not find any example. Any help would be greatly appreciated.
Thanks
Posted: Sun Jan 13, 2008 4:25 pm
by TimB
Its a pic related question You need to set the tris register
trisx.x = 1
Posted: Sun Jan 13, 2008 4:32 pm
by octal
Hi,
as Tim stated you can use
Code: Select all
//Pins numbering is zero based
TrisA.3 = 1 '<<< makes Pin3 on PortA as Input
TrisB.5 = 0 '<<< makes Pin5 on PortB as Output
' For all Port you may set all TRISx in one shot "1" or Input "0" for Output
TrisB = %01001110
or you can simply use the
Input()/Output() predefined subs
From Swordfish Help in Topic
Language Reference>>Predefined Subroutines and Functions
Input
sub input(byref portpin as bit)
The input subroutine makes the specified port pin an input. For example,
input(PORTD.7)
Output
sub output(byref portpin as bit)
The output subroutine makes the specified port pin an output. For example,
output(PORTD.7)
Regards
octal
Implicit Definition
Posted: Sun Jan 13, 2008 9:09 pm
by Widgetman
Thanks a bunch guys !!!!!
Posted: Sun Jan 13, 2008 9:33 pm
by Widgetman
Hi,
I tried what you suggested and got a compile error. I was wondering if there is a #option command to set say PORTA.3 as Input
I tried dim PORTA.3 as Input and got a compile error on the next line complaining about no end statement
Any ideas ?
I would like to define certain pins in my code to be specific
Thanks
Posted: Sun Jan 13, 2008 10:07 pm
by TimB
Dim is an alias to one or more registers it does nothing to the pic
Trisx.x = 1 or input(portx.x) is a implicit command and will make the pic pin an input
If you want to use dim then use
dim xxx as portx.x then issue
input(xxx)
Or
Dim xxx as trisx.x and issue
xxx = 1
Posted: Sun Jan 13, 2008 10:58 pm
by Widgetman
Hi,
Thanks again for the help
I got it to work by using Input(PORTX.X)
I did notice however I had to place the Input command after my sub routines or it would not compile. I am not sure why
Posted: Sun Jan 13, 2008 11:26 pm
by TimB
I did notice however I had to place the Input command after my sub routines or it would not compile. I am not sure why
That's the way the compiler works All subs etc before main commands.