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

about 74ls138 and pic16f877a

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



Joined: 18 Aug 2016
Posts: 1

View user's profile Send private message

about 74ls138 and pic16f877a
PostPosted: Fri Aug 19, 2016 1:52 am     Reply with quote

hi every pro!
can you help me, i dont understand this code when use 74ls138:
Code:
void LS138_Out(uint8_t Point)
{
   LS138_A=((Point&0x01)==0x01);
   LS138_B=((Point&0x02)==0x02);
   LS138_C=((Point&0x04)==0x04);   
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Fri Aug 19, 2016 2:29 am     Reply with quote

Problem is that you can't fully tell what this is doing without knowing how LS138_A, B & C are defined....

However parts are 'simple':

Point&0x01 Takes the value in 'Point', and bitwise and's it with 0x1.

==0x01 Then tests if this is '1'.

So this can be coded alternatively as:

bit_test(Point,1)

So the result of this test is loaded into LS138_A (whatever this is....).

Now 'guessing', since I know the LS138, that LS138_A, is actually a bit definition of the output latch for the PIC pin connected to the LS138 'A' pin, this then puts the three bottom bits in 'Point', out on the three pins that select which output to turn 'on' (low).

So LS138_Out(0) will pull Y0 low. LS138_Out(1) will pull Y1 low etc..

So in fact the test could be done as:

output_bit(PIN_LSA, bit_test(Point,1));

Where 'PIN_LSA' is a pin define for the pin for the LS138 A connection.

Like most things in C, there are actually dozens of ways of coding the same result...
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