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 use PINs in loops?

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



Joined: 16 Oct 2010
Posts: 20

View user's profile Send private message

how to use PINs in loops?
PostPosted: Sat Oct 16, 2010 6:00 pm     Reply with quote

Hello
I am a beginner and I want to use variable pins in FOR loop
I mean something like that:

Code:
int i;

for(i=0;i<8,i++)
 {
  if(input(pin_b[i]))
    {
     output_high(pin_c[i])
    }
 }
 

I am using picf877.
How I can make pin_b[i] varies from pin_b0 to pin_b7?

I want to make 8 switches on PORTB to control 8 LEDs on PORTC
Is there easier way to make this instead of loops?

Last question
Is there a function to test if any pin in portB got 1 signal from out?
I mean:

check(PORTB)

If 1 comes to pin_b3 for example, check(portb) should return pin_b3.

Thanks and sorry for my bad english.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 16, 2010 9:18 pm     Reply with quote

You could create an array of 8 bytes, and initialize it to the list of pin
names that you want. The pin names (constants) are given in the
16F877.h file. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=29344
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

PostPosted: Sun Oct 17, 2010 2:11 am     Reply with quote

There are a number of ways to do what you want. You could capture
port b, and test it to display the contents on port c. You would want to
pull up each pin to VCC using a 47k resistor.

I believe this might do the trick for you.
Code:

void main(void)
{
byte switches;                  //variable to hold switch data
switches = input_b();           //switches connected to port b
output_c (switches);            // Port C display's contents of port B

while (true);                   // loop forever
}

Regards Scott
doryme



Joined: 16 Oct 2010
Posts: 20

View user's profile Send private message

PostPosted: Mon Oct 18, 2010 4:09 pm     Reply with quote

Thanks a lot for your help! Smile
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