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

Masked output to port.

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



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

Masked output to port.
PostPosted: Fri Jan 26, 2007 8:42 am     Reply with quote

Hi,

I'm wondering that the best solution is. I need to set half the outputs of a port from a data byte, speed is the most important factor.

The following is my current solution to the problem.

Code:

#use FAST_IO
#INLINE
void set_EXT_Mux( int em )
{
  if(em&0x01)output_high(PIN_C0); else output_low(PIN_C0);
  if(em&0x02)output_high(PIN_C1); else output_low(PIN_C1);
  if(em&0x04)output_high(PIN_C2); else output_low(PIN_C2);
  if(em&0x08)output_high(PIN_C3); else output_low(PIN_C3);
}


Using "output_bit(pin,value)" does not appear to give any advantage as the "value" would still have to be otained from the byte.

But "output_c(value)" does give significant gains in speed. The problem is I only want to use the first 4 (maybe 5) bits of data, PIN_C6 and PIN_C7 are used for the RS232 communications and I can't' have that interfered with. Is output_c intelligent enough to ignore these pins?

Or have I hit the best solution already?

Thanks Scott
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Jan 26, 2007 9:32 am     Reply with quote

I was thinking along these lines
Code:
#include <16F877.h>
#device *=16   //not needed for now.
#use delay(clock=4000000)
#fuses hs,nowdt,nolvp,protect,put,brownout
#use rs232(baud=19200,xmit=PIN_B3,INVERT,stream=DEBUG)
#case
#zero_ram
#use fast_io(C)
struct my_struc_def_portc
{
   int1 my_stuf:3;//lsb
   int1 unused_part_of_port:5;//msb
};
struct my_struc_def_portc my_output;
struct my_struc_def_portc my_tris;
#byte my_output= 0x07   //note: no semicolin    0x07=C0 on a 16F877
#byte my_tris  = 0x87   //note: no semicolin    0x87=C0 on a 16F877

//======================= Main ==============================
void main(void){
  my_tris.my_stuf=0x00;//set to output
  //set all outputs to 1.
  my_output.my_stuf=0x0F&0b00000111;//overlay variable, masking off unused bits
  while(1){
   }
}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 26, 2007 9:55 am     Reply with quote

There is no need to mask off the unused portion. The compiler will handle this. Also, you should use the standard int size when declaring a portion of a variable.
Code:

#include <16F877.h>
#device *=16   //not needed for now.
#use delay(clock=4000000)
#fuses hs,nowdt,nolvp,protect,put,brownout
#use rs232(baud=19200,xmit=PIN_B3,INVERT,stream=DEBUG)
#case
#zero_ram
#use fast_io(C)
struct my_struc_def_portc
{
   int8 my_stuf:4;//lsb
   int8 unused_part_of_port:4;//msb
};

struct my_struc_def_portc my_output;
#locate my_output= 0x07   //note: no semicolin    0x07=C0 on a 16F877

struct my_struc_def_portc my_tris;
#locate my_tris  = 0x87   //note: no semicolin    0x87=C0 on a 16F877

//======================= Main ==============================
void main(void){
  my_tris.my_stuf=0x00;//set to output
  //set all outputs to 1.
  my_output.my_stuf=0x0F;
  while(1){
   }
}
 
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Jan 26, 2007 10:19 am     Reply with quote

Thanks for the fix up. I didn't want to find hardware to test it. But it compiles.

And as my VB programmers always say"It compiled, ship it". Very Happy
ferrumvir



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

PostPosted: Mon Jan 29, 2007 7:43 am     Reply with quote

Hi Thanks for the help,

Sorry it took me so long to dig through and understand what was going on, very interesting looking at the list file.

It took me considerable amount of time to find the location in memory for the register, for my chip!

I'm now down from 60 unstructions to 4! Fantastic. Very Happy Thanks

one last question:

Then using the hardware UART on the PINS C6,C7 does the content of Register PORTC:6 and PORTC:7 have any effect at all? i.e. Does the UART by-pass/ignore this register? or does the harware UART use this register therefore it is vitally important to do the above?

The reason I ask is that for the 4 instruction cycles where we take a copy of this register and modify part of it before putting it back, if the hardware changes it in this time, do we not introduce glitches?

I suspect that this register is bypassed and therefore I could just write to the whole PORTC register, knowing that the hardware will override/ignore any changes I make to the PORTC:6&7 bits?

4 instructions down to 1?... Yes/no?

Thanks for you're help

Cheers Scott
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