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 CCS Technical Support

How to read output.

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



Joined: 22 Jan 2005
Posts: 12
Location: Rio de Janeiro, Brazil

View user's profile Send private message MSN Messenger

How to read output.
PostPosted: Sat Jan 22, 2005 1:58 pm     Reply with quote

Hi,
I'am new in using the C & CCS compiler.
I have made a program the sets or clears outputs on the pic.
how can i read the actual state on a pin.
i tried:
if (pin_b4) do_what_ever; else do_somthing_else;
But it doesent work.
It's easy in assembler, so it should be possible here too?

Please help..

John
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Sat Jan 22, 2005 2:23 pm     Reply with quote

Code:

if (input(PIN_B4))
{
   // do something impressive
}

is one way to do things. Another is to create a #byte and #bit pragma and access the pin that way. Need to #use fast_io() or #use fixed_io() if you #byte/#bit access the ports. input() will work with #use standard_io(), #use fast_io() and #use fixed_io()
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
John_Rio



Joined: 22 Jan 2005
Posts: 12
Location: Rio de Janeiro, Brazil

View user's profile Send private message MSN Messenger

PostPosted: Sat Jan 22, 2005 2:30 pm     Reply with quote

I already tried the one you mentione here if (input(pin_b4) ....

The problem is that this sets the pin as an input.
I am looking for a way to read the actual output.

John
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Sat Jan 22, 2005 2:54 pm     Reply with quote

So what you are trying to do is readback the port register some time after altering the state of the output pin.

Have you tried (assuming PORTA on PIC16F877A, adjust to taste)

Code:

#byte PORTA = 0x05
#bit PINA0 = PORTA.0

#use fast_io(A)

... more code
set_tris_A(0x00); // all outputs
PINA0 = 1; // set pin high

// do many things here and loose track of how pin was set

if (PINA0)
{
   // do something wonderful
}


I haven't tested this code myself.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
John_Rio



Joined: 22 Jan 2005
Posts: 12
Location: Rio de Janeiro, Brazil

View user's profile Send private message MSN Messenger

PostPosted: Sat Jan 22, 2005 3:22 pm     Reply with quote

Thanks a lot.
That did it.

#bit powerbit=0xF81.4
if (powerbit) Outbuffer[5]='0'; else Outbuffer[5]='1';

I'am using 18F452 so i had to change the register address.

Thanks a lot.[/list]
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