|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 14, 2006 5:00 pm |
|
|
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
|
|
Posted: Mon Jan 08, 2007 5:21 am |
|
|
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
|
|
|
|
|
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
|