I'm using PIC18F258 and I would like to refer inputs with #bit pre-processor.
Is this would work?
Code:
// setting the pin direction to input
set_tris_a(0xFF);
//
#byte PORTA = getenv("SFR:PORTA")
//
#bit A0 = PORTA.0
//
if (A0 == 1)
{
// do something...
}
When the Input pin is changing, the PORTA register is also changing ? Or I have to use input() statement...
Thanks in advance!
Valentinus
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Jan 20, 2014 3:05 pm
You can test this. Make a small test program that uses both methods.
Compile it and look at the code in the .LST file. See if there are any
important differences. If not, then you have proved it will work.
Code:
#include <18F258.h>
#fuses XT, NOWDT, BROWNOUT, PUT
#use delay(clock=4M)
#byte PORTA = getenv("SFR:PORTA")
#bit A0 = PORTA.0
//========================
void main()
{
int8 i;
set_tris_a(0xFF);
if(A0 == 1)
i = 0x55;
if(input(PIN_A0) == 1)
i = 0x55;
while(1);
}
Valentinus
Joined: 21 Nov 2011 Posts: 6
Posted: Mon Jan 20, 2014 3:48 pm
Thank you very much for this practical idea. That was very helpfull.
And the answer for my question is: Yes, it will work!!! :D
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