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

convert input_b result to pin_bx handle

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



Joined: 19 Jun 2017
Posts: 27

View user's profile Send private message

convert input_b result to pin_bx handle
PostPosted: Sat Jul 01, 2017 11:40 am     Reply with quote

Is there mathematical way to convert the result of the result of input_b (int8) to the value of the pin numerical handle?

I know it be done with a conditional statement but that would take lot more instructions to process than a simple mathematical operation if there is any.


Thx in advance!
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sat Jul 01, 2017 11:45 am     Reply with quote

The numerical handle is simply the memory address of the port, *8, plus the actual pin number.
So yes, this can be coded, but since there would be 256 possible values, you'd need 256 pins for every possible value.....
Alphada



Joined: 19 Jun 2017
Posts: 27

View user's profile Send private message

PostPosted: Sat Jul 01, 2017 12:25 pm     Reply with quote

Ttelmah wrote:
The numerical handle is simply the memory address of the port, *8, plus the actual pin number.
So yes, this can be coded, but since there would be 256 possible values, you'd need 256 pins for every possible value.....


thx thats what i wanted to know:
Quote:
The numerical handle is simply the memory address of the port, *8, plus the actual pin number.


Btw what i want is to loop the whole port with "input_b" for changes from high to low and then send that pin handle to a function to process debounce.

Now i understand your answer, took me some time, but is right. How would that variable know exactly what port to process ? I need to think of something else, maybe using an array and processing the first to arrive, since is a theoretical keyboard and no more than one key should be pressed at once.
That clarified my doubt, thx.
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sat Jul 01, 2017 1:42 pm     Reply with quote

Beware though that using variables is much bulkier/slower than using direct names.

So (for instance):

input(PIN_xx);

If using fast I/O codes as a single instruction. If using standard I/O 3 instructions normally.

However if you have a variable 'n' with a pin address:

input(n);

Will code as perhaps 20 instructions.....

Remember you can always talk directly to a port by just coding it's register address as a pointer. If you are scanning for a particular bit, then better to use a mask, and rotate this yourself. If you have such a mask already used to access a particular bit, make this global, or pass this to your function, and the function can use this to access the bit far faster.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 02, 2017 9:27 pm     Reply with quote

I ran the program below in MPLAB vs. 8.92 simulator. I put breakpoints
on the input() and while() statements. Then I ran the MPLAB Stopwatch
utility. It showed the following number of instruction cycles to execute
the input() function:

PIN_B0: 79 instruction cycles
PIN_B1: 87 instruction cycles
PIN_B2: 95 instruction cycles
.
.
.
PIN_B7: 135 instruction cycles

The duration depends upon the bit position in PortB. It goes up by 8
cycles for each further bit position. That's because the CCS writebit
and readbit routines each have a DECFSZ loop that takes 4 cycles each.
This was tested with vs. 5.071.

Test program:
Code:

#include <16F887.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)

//==========================
void main()     
{
int8 pin;
int8 result;

pin = PIN_B0;

result = input(pin);

while(TRUE);   
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Jul 03, 2017 2:11 am     Reply with quote

I meant to say about 20*, not 20 instructions.
Does make the point of just how much this does cost!...
Worse than I thought. :(
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