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

I/O pin management

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 14, 2006 5:00 pm     Reply with quote

Quote:
what if I need input and output ?

The demo program below shows how to read eight spare bits and pack
them into a byte variable.
You don't need to set the TRIS if you're running the compiler in Standard
i/o mode. The compiler will handle it, since I'm using CCS i/o functions
in the macro. ("Standard i/o" mode is the default mode of the compiler).
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)

// This macro reads the value of the following
// pins and packs the result into a single byte.
// RA0,RA1,RA4,RB2,RB5,RB7,RC0,RC5

#define read_spare_bits(x) \
x = 0; \                 
if(input(PIN_A0)) bit_set(x, 0); \
if(input(PIN_A1)) bit_set(x, 1); \
if(input(PIN_A4)) bit_set(x, 2); \
if(input(PIN_B2)) bit_set(x, 3); \
if(input(PIN_B5)) bit_set(x, 4); \
if(input(PIN_B7)) bit_set(x, 5); \
if(input(PIN_C0)) bit_set(x, 6); \
if(input(PIN_C5)) bit_set(x, 7);


//==================================
void main()
{
int8 result;

while(1)
  {
   // Read the value of the spare bits and put
   // it into the 'result' variable.
   read_spare_bits(result);

   printf("Result = %X \n\r", result);

   delay_ms(500);
  }

}
Guest








PostPosted: Mon Jan 08, 2007 5:21 am     Reply with quote

I've just tried implementing the above macro set_spare_bits() and instead of turning on a static image on the 7-seg it cycles through the segments, one at a time, starting with one segment and then two, three, four, etc.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 11:17 am     Reply with quote

Read this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=18183&highlight=leds+read+modify+write

Questions:
1. What PIC are you using ?

2. Can you post a list of the Port pins that you're using ?
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