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

output_high(PIN1, PIN2);

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



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

output_high(PIN1, PIN2);
PostPosted: Sun Jun 02, 2013 3:28 am     Reply with quote

Hello everyone,
How can i output high 2 pins at the same time without using the weight method, this method should call its name not its weight for example (PIN_C0 - PIN_C1), etc

the function should be like this
Code:
output_high(int16 PIN1, int16 PIN2)
{
      //need help
}


Thanks in advance,
z3ngew
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 4:23 am     Reply with quote

Please explain EXACTLY what you mean.

1) Do you want to create a function which does the work for you?
2) Will both pins be on the same port?
3) Can the pins go high one after the other?
4) Do you want the actual action to be both pins go high in one machine cycle?
5) ............Anything else

Mike
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 4:28 am     Reply with quote

1-both pins will be in the same port
2- i want the actual action to be both go high in one machine cycle
3- the parameter of the function should be(int16 PIN1, int16 PIN2)

Thanks,
z3ngew
temtronic



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

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 5:24 am     Reply with quote

quick reply not tested...

One method is to create your own function and use the

CCS function ...output_x( )

inside it.

You'll have to read the port first,then mask that data with your 'pins to set high',then write to the port the new data.
//pseudo code..NOT tested...
my_new_function(int8 pin1,int8 pin2)

old_data=input_b();
my_pin_data= ??code to parse pin1,pin2 into correct format
new_data=old_data | my_pin_data;
output_b(new_data);
//

You'll have to fill in 'my_pin_data' as required.

Depending on the devices attached to the pins, even a simple bit_set() function may work for you, but will take a couple more machine cycles to turn on the pins BUT overall would be much faster.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19365

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 7:38 am     Reply with quote

Unfortunately, to do this using pin names, is going to take longer than using the two separate outputs.

Key is first that the pin number, is the memory address of the physical port, *8, plus the bit number for the pin.
So:
Code:

output_high_two(int16 PIN1, int16 PIN2)
{
      int8 * port_address;
      int8 mask=0;
      port_address=PIN1/8;
      bit_set(mask,(PIN1 & 7));
      bit_set(mask,(PIN2 & 7));
      *port_address=*port_address | mask;
}   


However this is terribly inefficient. Multiple problems/reasons. If you use the 'output_high' function, with a single fixed pin number, the compiler does the solution to what port it is, and the bit number involved _at compile time_. The chip has a 'bit_set' function that can set a single bit in one instruction. This is then used by the compiler, allowing two successive output_high instructions, to take just two machine cycles.
Using the two pin numbers involves first having to work out the address (three 16bit rotations to give /8). Then set the two bits required (build a mask, rotate it - another dozen instructions typically). Do this twice, then read the port, apply the mask, and write the result back. So though the final output is done in just one instruction, it takes an age....

Alternative (much better), is to just #define masks for the bits.
So:
Code:

#define BIT0 1
#define BIT1 2
#define BIT2 4
#define BIT3 8
#define BIT4 16
#define BIT5 32
#define BIT6 64
#define BIT7 128

//demo on port B
#define set_bitsonportB_high(x) output_b(input_b() | x)
#define set_bitsonportB_low(x) output_b(input_b() & (~(x)))

//Then to use:

set_bitsonportB_high(BIT2 | BIT5);


This will set bit 2 and bit 5 on port B high at the same time.
Obviously change the port involved to suit.

Now key here is that again 90% is done 'in advance'. The symbolic bit 'names' already represent the masks needed. You can use as few or as many bits as you want (you could set four bits at once, just as easily as one). The compiler just has to read the port, do the masking operation and write the result back.

I've also included the complementary function, to turn multiple bits low.

Best Wishes
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Tue Jun 04, 2013 10:36 am     Reply with quote

I have developed this method, it is now available in the code library,
follow this link: http://www.ccsinfo.com/forum/viewtopic.php?p=176690#176690

Good Luck,
z3ngew
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