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 support@ccsinfo.com

Change PIN at Runtime

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



Joined: 15 Jan 2019
Posts: 22
Location: Sweden

View user's profile Send private message

Change PIN at Runtime
PostPosted: Sat Nov 27, 2021 5:02 am     Reply with quote

In many examples we can use for example a #Define Pin_to_Use PIN_D1.

This is used when compiler generate the code.

However I have seen an example of change the PIN in runtime like this:
Code:

int16 pin_to_use;

pin_to_use=PIN_B0;

output_low(pin_to_use);

pin_to_use=PIN_B1;

output_low(pin_to_use);

But this does not work in my case so I wonder what can go wrong with this type of code in CCS ? It compiles OK but the I/O address is wrong not point to the address defined in header file for the MCU.

Are there other ways to alter the PIN in an output_high(PIN_xx) at runtime maybe ?

I use compiler 5.076 and MCU is a 30F5011.
PeWa



Joined: 15 Jan 2019
Posts: 22
Location: Sweden

View user's profile Send private message

Re: Change PIN at Runtime
PostPosted: Sat Nov 27, 2021 8:43 am     Reply with quote

PeWa wrote:
In many examples we can use for example a #Define Pin_to_Use PIN_D1.

This is used when compiler generate the code.

However I have seen an example of change the PIN in runtime like this:
Code:

int16 pin_to_use;

pin_to_use=PIN_B0;

output_low(pin_to_use);

pin_to_use=PIN_B1;

output_low(pin_to_use);

But this does not work in my case so I wonder what can go wrong with this type of code in CCS ? It compiles OK but the I/O address is wrong not point to the address defined in header file for the MCU.

Are there other ways to alter the PIN in an output_high(PIN_xx) at runtime maybe ?

I use compiler 5.076 and MCU is a 30F5011.


Edited, the variable address is OK. I can change a static LED but it seems that when I change to variable the output / input functions take some more time to compute. Is that the case ??
temtronic



Joined: 01 Jul 2010
Posts: 9098
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 27, 2021 8:55 am     Reply with quote

doing it as shown ,will require time to get the desired pin and insert into the output function

why not just ...

#DEFINE this_pin PIN_B2;
#DEFINE that_pin PIN_B4;
...
...
output_low(this_pin);
output_low(that_pin);
...
...
it 'should be faster'.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Change PIN at Runtime
PostPosted: Sat Nov 27, 2021 9:23 am     Reply with quote

PeWa wrote:

It seems that when I change to variable the output / input functions take some more time to compute. Is that the case ??

See this post. It shows how much ASM code is required if you use
a variable to pass the CCS pin number.
http://www.ccsinfo.com/forum/viewtopic.php?t=36953&start=3
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Dec 03, 2021 2:29 am     Reply with quote

You can also use the get_env for the PORT and LAT register addresses.

Then build a struct as you like with a default set of values.

Then just write those values to PORT/LAT registers on start up.

You end up configuring an entire register with a single write.

I'd have to go look at an old example to see how much ASM results.... but it should be pretty thin.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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