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

Reading Port A

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



Joined: 16 Feb 2004
Posts: 26

View user's profile Send private message

Reading Port A
PostPosted: Mon Mar 21, 2005 6:01 am     Reply with quote

Hi, This could be a pic problem or a code problem.
I am trying to write a value to port A then read it back and display the value on screen. code below.

void TestFunc()
{
#byte PORTA = 5
#define ALL_OUT 0
#define ALL_IN 0xff

int i;

set_tris_a(ALL_OUT);
porta=0x0a;
set_tris_a(ALL_IN);
i=porta;
printf("%x \n\r",i);
return;
}

I have tried other ways but get the same problem.
Setting the port up is no problem, the correct byte is placed on the pins. The problem is when I try to read, all the pins go high!
Any help appreciated.
Thanks
Steve
Mark



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

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

PostPosted: Mon Mar 21, 2005 6:34 am     Reply with quote

What do you have connected to the pins?????

You do realize that
Code:
set_tris_a(ALL_IN);

will make them inputs. You are not necessarily going to read what you wrote to the port. Also be aware of the Read Modify Write problem.


Last edited by Mark on Mon Mar 21, 2005 8:07 am; edited 1 time in total
stma



Joined: 16 Feb 2004
Posts: 26

View user's profile Send private message

PostPosted: Mon Mar 21, 2005 7:53 am     Reply with quote

Thanks for that. Good point about reading not neccesarily what i wrote. It is really a test routine. I am writing a byte to a cpld to set a multiplexer address. Then I read data in from another pin (well thats the plan)
Im off to do a bit more thinking!!
Thanks again
Steve
Ttelmah
Guest







PostPosted: Mon Mar 21, 2005 8:07 am     Reply with quote

Add, that unless you specify #use fast_io(A), the compiler will already be adding the equivalent to the two set TRIS functions for you. This will be adding to the duration from the moment the output is written to the pins, and the attempt is made to read them.
If you want to read what is currently being output on the pins, use #use fast_io, set the pins as outputs, and write the data pattern, then leave the pins as outputs, and read the input. The input function will work, whether the pins are operating as outputs, or as inputs, but in the latter case, the signals are not driven by the chip when the reading is made.

Best Wishes
Mark



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

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

PostPosted: Mon Mar 21, 2005 8:12 am     Reply with quote

Ttelmah wrote:
Add, that unless you specify #use fast_io(A), the compiler will already be adding the equivalent to the two set TRIS functions for you. This will be adding to the duration from the moment the output is written to the pins, and the attempt is made to read them.
If you want to read what is currently being output on the pins, use #use fast_io, set the pins as outputs, and write the data pattern, then leave the pins as outputs, and read the input. The input function will work, whether the pins are operating as outputs, or as inputs, but in the latter case, the signals are not driven by the chip when the reading is made.

Best Wishes


This does not always work. It depends on what is connected to the pins. Most of the time it will work correctly though. I use this as sort of a self test mode. By pulling things high and checking, pulling things low and checking I can determine whether pullups were installed correctly, shorts, etc...
Ttelmah
Guest







PostPosted: Mon Mar 21, 2005 8:18 am     Reply with quote

I think I'd say, that technically, it does 'always work', but it reflects the real status of the pins, rather than what you are trying to drive them to. Assuming the original poster is trying to actually test whether the pins are going to the pattern required, then this would be what was wanted.
It is an important 'caveat' though, especially if the instructions are done quickly one after the other, where the capacitance of the pins can prevent them from havin yet reached the required target voltage...

Best Wishes
Mark



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

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

PostPosted: Mon Mar 21, 2005 8:24 am     Reply with quote

Ttelmah wrote:
I think I'd say, that technically, it does 'always work', but it reflects the real status of the pins, rather than what you are trying to drive them to. Assuming the original poster is trying to actually test whether the pins are going to the pattern required, then this would be what was wanted.
It is an important 'caveat' though, especially if the instructions are done quickly one after the other, where the capacitance of the pins can prevent them from havin yet reached the required target voltage...

Best Wishes


Yeah, that is what I was saying by
Quote:
It depends on what is connected to the pins.
The operating frequency also plays a role. Not enough capacitance and too slow a frequency you won't be able to read the data back in time. On the other hand, too much capacitance and too fast a read, the inputs won't have time to rise.

Also note that an interrupt can occur just before the read so you might want to disable them.
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