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

Simple question

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








Simple question
PostPosted: Mon Oct 31, 2005 12:37 pm     Reply with quote

Hi all. I'm sure i'm just missing this in the manuels somewhere. I'm trying to take 2 vars and combine them in order to read a third var. I.e.

Code:


int8 plug,test;

#define pin1 = plug.0
#define pin2 = plug.1
#define pin3 = plug.2



I'd like to be able to take and step thru each of the pin locations something along the lines of

Code:

int x;
x = 0;
while (x < 4)
   {
    test = pin(x);
    ++x;
    }


I know that pin(x) will not give me what I want but i'm hoping this displays what i'm wanting to do and that someone can point out the correct way to do it. Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 31, 2005 12:48 pm     Reply with quote

Log in, and click the button that says "Log me in automatically",
and then just never log out. Then you'll never get stuck with
"guest" posts.
--------------------------

You can read the entire i/o port at once, and then step through the bits.

Code:
include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use RS232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) 

//======================================
main(void)
{
int8 port_b_value;
int8 bit_value;
int8 i;

port_b_value = input_b();  // Read Port B

// Display the value of each bit read from Port B.
for(i = 0; i < 8; i++)
   {
    bit_value = bit_test(port_b_value, i);
    printf("Bit %u = %u \n\r", i, bit_value);
   }

while(1);
}
timtalk



Joined: 14 Oct 2005
Posts: 10

View user's profile Send private message

PostPosted: Mon Oct 31, 2005 1:53 pm     Reply with quote

I have had that box checked since I created my account I think somehow it was disabled in the update.

My intention is NOT to read a port. I want to read each of the bits in a 8 bit integer. The reason for this is that I want to store each var into the eeprom for later use where it will be read out and then port B of the pic will be set to match the value taken from the eeprom. My project involves a alarm clock type design. Where alarm times are kept in the eeprom along with the config of the port at that time. I.e. eeprom location 0 would contain an hour, eeprom location 1 would contain a min, eeprom location 2 would contain the config of port B at that time. Then the program can scan the eeprom and compare current time to eeprom time, if they match it would read the config value out of the eeprom and apply it to the port on the PIC. I'm trying to set this up so that the times and port configs stored in the eeprom can be updated via a 4 button keypad and a lcd. I've already got most of the program worked out but was looking for ways to easily step thru each of the bit locations of a var. I hope this clears up my intentions. Thanks!
timtalk



Joined: 14 Oct 2005
Posts: 10

View user's profile Send private message

PostPosted: Mon Oct 31, 2005 2:07 pm     Reply with quote

After further reading thru your code you posted I think it still provides me with an answer. Instead of testing port_B_results i can test any int8 that i've set. So thanks for the answer to what I was sure was a simple question!! Very Happy
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