View previous topic :: View next topic |
Author |
Message |
tomasch
Joined: 14 May 2004 Posts: 3
|
help! Keep the state of a port pin constant when I/O ing |
Posted: Fri May 14, 2004 6:52 am |
|
|
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
|
|
Posted: Fri May 14, 2004 9:55 am |
|
|
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
|
|
Posted: Fri May 14, 2004 1:36 pm |
|
|
Like I said - I don't want to use any RAM (variable) Thanks anyway |
|
|
prwatCCS
Joined: 10 Dec 2003 Posts: 70 Location: West Sussex, UK
|
|
Posted: Fri May 14, 2004 2:38 pm |
|
|
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
|
|
Posted: Fri May 14, 2004 2:44 pm |
|
|
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
|
|
Posted: Fri May 14, 2004 4:54 pm |
|
|
So then what good is read-modify-write. Surly the port latch is a "register"
It's mostly an elegance thing based on how tight the code is - just my comulsive side coming out.
Thanks tou all thus far |
|
|
|