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

help! Keep the state of a port pin constant when I/O ing

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



Joined: 14 May 2004
Posts: 3

View user's profile Send private message

help! Keep the state of a port pin constant when I/O ing
PostPosted: Fri May 14, 2004 6:52 am     Reply with quote

Embarassed
Excuse my silly question but - no sleep - and I can't figure it out.

I am trying to use Port A for input AND output. I'd like to set a pin (let's say pin_a7) to a value of my choosing - i.e. on or off - for an LED, let's say.

I want to futz with the port, but when I write back to the port I do not want to change the state of Pin_a7.

I know it's a combination of fast_io or standard_io and set_tris_a because of read-modify-write, but head hurts from goofing with it too long.

oh yeah... I do not want to take up an extra spot of RAM for keeping a lookup for the state of pin_a7

16F628 and CCS v 3.112 (I think!)

Your expert help is much needed and much appreciated

Here's the idea in pseudo code

#use fast_io(a)
set_tris_a(0b01110000);

output_high(pin_a7); // I'd like pin_a7 to stay at whatever I set it at - could be hi - LED OFF
//
// or it could be low!!!

output_low(pin_a7); // I'd like pin_a7 to stay at whatever I set it at - could be low - LED ON

// do some stuff

val=(input_a() & 0b01110000); // REading the input pins

// do some stuff with val which may change bits 0 to 4
// here comes tricky part
val=val & 0b01111111; // strip the high bit of val to not influence pin_a7 when writing
output_a((input_a() & 0b10000000) | val); // re-read Port A keep pin_a7 only and output new value but keep pin_a7 in original state (H or L)

// now what sherlock?
Steve H
Guest







PostPosted: Fri May 14, 2004 9:55 am     Reply with quote

Keep the LED pin state in a variable, then when writing port wise to the port - AND the led bit wioth a zero to clear it, then OR in the variable value.

Steve H.
tomasch



Joined: 14 May 2004
Posts: 3

View user's profile Send private message

PostPosted: Fri May 14, 2004 1:36 pm     Reply with quote

Like I said - I don't want to use any RAM (variable) Thanks anyway
prwatCCS



Joined: 10 Dec 2003
Posts: 67
Location: West Sussex, UK

View user's profile Send private message

PostPosted: Fri May 14, 2004 2:38 pm     Reply with quote

Why the concern over a RAM variable. Surely is not that tight?
_________________
Peter Willis
Development Director
Howard Eaton Lighting Ltd UK
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri May 14, 2004 2:44 pm     Reply with quote

I don't think you can avoid having the compiler use strach variable. You can see what gets used in the list file.

Code:

if(input(pin_a7))
{ output_a(val || 0x80);
}
else
{ output_a(val && 0xEF);
}
Guest








PostPosted: Fri May 14, 2004 4:54 pm     Reply with quote

So then what good is read-modify-write. Surly the port latch is a "register"

It's mostly an elegance thing Rolling Eyes based on how tight the code is - just my comulsive side coming out.

Thanks tou all thus far
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