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

truth table

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

truth table
PostPosted: Tue Jul 21, 2009 6:57 pm     Reply with quote

Hi

What is better way to make a truth table?

I have one PIC for make this decoder, X0 to X4 is inputs and output is other pins...



I make some like that:
Code:

#include <16F876A.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#define X0 PIN_C6
#define X1 PIN_C7
#define X2 PIN_B0
#define X3 PIN_B1
#define X4 PIN_B2


void main()
{
while (TRUE)
{
//###################### relay OFF #######################
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_B6); //R1
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_low(PIN_B5); //R2
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==1)) output_low(PIN_B4); //R3
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==0)) output_low(PIN_B3); //R4
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_C5); //R5
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==0)) output_low(PIN_C4); //R6
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==1)) output_low(PIN_C3); //R7
if ((input(X4)==0) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==0)) output_low(PIN_C2); //R8
if ((input(X4)==0) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_C1); //R9
if ((input(X4)==0) && (input(X3)==1) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_low(PIN_C0); //R10

//###################### relay ON #######################
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_high(PIN_B6); //R1
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_high(PIN_B5); //R2
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==1)) output_high(PIN_B4); //R3
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==0)) output_high(PIN_B3); //R4
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==1)) output_high(PIN_C5); //R5
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==0)) output_high(PIN_C4); //R6
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==1)) output_high(PIN_C3); //R7
if ((input(X4)==1) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==0)) output_high(PIN_C2); //R8
if ((input(X4)==1) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_high(PIN_C1); //R9
if ((input(X4)==1) && (input(X3)==1) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_high(PIN_C0); //R10


//###################### relay ALL OFF #######################
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==0)) //ALL OFF
   {
      output_low(PIN_B6); //R1
      output_low(PIN_B5); //R2
      output_low(PIN_B4); //R3
      output_low(PIN_B3); //R4
      output_low(PIN_C5); //R5
      output_low(PIN_C4); //R6
      output_low(PIN_C3); //R7
      output_low(PIN_C2); //R8
      output_low(PIN_C1); //R9
      output_low(PIN_C0); //R10
   }
}
}



what you think?

kind regards
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Tue Jul 21, 2009 9:02 pm     Reply with quote

One way of doing this, instead of writing tons of code (which could be host to several errors) is to use an 'overlay' approach.

You can create a 'structure' of sorts, in which different pins are mapped to bits in a byte, and input/output to pins in that structure by modifying that byte.

With this method, instead of
Code:
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_B6); //R1
you'd be able to do something like this
Code:
if (my_byte==0x03)
{some_other_byte=0x08;}
where the bits in *my_byte* are mapped to pins.

Read this http://ccsinfo.com/forum/viewtopic.php?t=35816 and http://www.ccsinfo.com/forum/viewtopic.php?t=18949&start=6

Rohit
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 8:06 pm     Reply with quote

Hi

I try make with 16F876 an decoder and put combination with 18F452.

on 18F452 I have:
Code:

void RELAY1ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_low (PIN_C2);
output_low (PIN_C3);
output_high (PIN_C4);
}
void RELAY2ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_low (PIN_C2);
output_high(PIN_C3);
output_low (PIN_C4);
}
void RELAY3ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_low (PIN_C2);
output_high (PIN_C3);
output_high (PIN_C4);
}
void RELAY4ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_low (PIN_C3);
output_low (PIN_C4);
}
void RELAY5ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_low (PIN_C3);
output_high (PIN_C4);
}
void RELAY6ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_high (PIN_C3);
output_low (PIN_C4);
}
void RELAY7ON ()
{
output_high(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_high (PIN_C3);
output_high (PIN_C4);
}
void RELAY8ON ()
{
output_high(PIN_C0);
output_high (PIN_C1);
output_low (PIN_C2);
output_low (PIN_C3);
output_low (PIN_C4);
}
void RELAY9ON ()
{
output_high(PIN_C0);
output_high (PIN_C1);
output_low (PIN_C2);
output_low (PIN_C3);
output_high (PIN_C4);
}
void RELAY10ON ()
{
output_high(PIN_C0);
output_high (PIN_C1);
output_low (PIN_C2);
output_high (PIN_C3);
output_low (PIN_C4);
}
//##################### RELAY OFF #####################
void RELAY1OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_low (PIN_C2);
output_low (PIN_C3);
output_high (PIN_C4);
}
void RELAY2OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_low (PIN_C2);
output_high(PIN_C3);
output_low (PIN_C4);
}
void RELAY3OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_low (PIN_C2);
output_high (PIN_C3);
output_high (PIN_C4);
}
void RELAY4OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_low (PIN_C3);
output_low (PIN_C4);
}
void RELAY5OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_low (PIN_C3);
output_high (PIN_C4);
}
void RELAY6OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_high (PIN_C3);
output_low (PIN_C4);
}
void RELAY7OFF ()
{
output_low(PIN_C0);
output_low (PIN_C1);
output_high (PIN_C2);
output_high (PIN_C3);
output_high (PIN_C4);
}
void RELAY8OFF ()
{
output_low(PIN_C0);
output_high (PIN_C1);
output_low (PIN_C2);
output_low (PIN_C3);
output_low (PIN_C4);
}
void RELAY9OFF ()
{
output_low(PIN_C0);
output_high (PIN_C1);
output_low (PIN_C2);
output_low (PIN_C3);
output_high (PIN_C4);
}
void RELAY10OFF ()
{
output_high(PIN_C0);
output_high (PIN_C1);
output_low (PIN_C2);
output_high (PIN_C3);
output_low (PIN_C4);
}

void RELAYALLOFF ()
{
output_high (PIN_C0);
output_high (PIN_C1);
output_high (PIN_C2);
output_high (PIN_C3);
output_high (PIN_C4);
}


and on 16F876 I have
Code:

void main()
{
while (TRUE)
{
//###################### relay OFF #######################
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_B6); //R1
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_low(PIN_B5); //R2
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==1)) output_low(PIN_B4); //R3
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==0)) output_low(PIN_B3); //R4
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_C5); //R5
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==0)) output_low(PIN_C4); //R6
if ((input(X4)==0) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==1)) output_low(PIN_C3); //R7
if ((input(X4)==0) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==0)) output_low(PIN_C2); //R8
if ((input(X4)==0) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_low(PIN_C1); //R9
if ((input(X4)==0) && (input(X3)==1) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_low(PIN_C0); //R10

//###################### relay ON #######################
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_high(PIN_B6); //R1
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_high(PIN_B5); //R2
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==1) && (input(X0)==1)) output_high(PIN_B4); //R3
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==0)) output_high(PIN_B3); //R4
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==0) && (input(X0)==1)) output_high(PIN_C5); //R5
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==0)) output_high(PIN_C4); //R6
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==1) && (input(X1)==1) && (input(X0)==1)) output_high(PIN_C3); //R7
if ((input(X4)==1) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==0)) output_high(PIN_C2); //R8
if ((input(X4)==1) && (input(X3)==1) && (input(X2)==0) && (input(X1)==0) && (input(X0)==1)) output_high(PIN_C1); //R9
if ((input(X4)==1) && (input(X3)==1) && (input(X2)==0) && (input(X1)==1) && (input(X0)==0)) output_high(PIN_C0); //R10


//###################### relay ALL OFF #######################
if ((input(X4)==1) && (input(X3)==0) && (input(X2)==0) && (input(X1)==0) && (input(X0)==0)) //ALL OFF
   {
      output_low(PIN_B6); //R1
      output_low(PIN_B5); //R2
      output_low(PIN_B4); //R3
      output_low(PIN_B3); //R4
      output_low(PIN_C5); //R5
      output_low(PIN_C4); //R6
      output_low(PIN_C3); //R7
      output_low(PIN_C2); //R8
      output_low(PIN_C1); //R9
      output_low(PIN_C0); //R10
   }
}
}



but it don't work Crying or Very sad

if for example I call RELAY1ON(); on 18F542
it turn on and turn off all relays very quickly Confused

some one can help me for make this decoder?

kind regards
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 22, 2009 9:46 pm     Reply with quote

It is possible that the relays are causing glitches in the supply.

-How are you powering/activating the relays? Separate supply with a driver? Or is the supply shared between the relays and microcontroller?

-Are you using a snubber diode across your relays?

-Instead of relays use LEDs, and see if you face the same problem.

-Have you got a pull up on the MCLR pins of the microcontrollers?

Rohit
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 10:08 pm     Reply with quote

Hi

Thanks for opinions...

Problem stay on hardware...

Now all stay fine. Thanks Laughing
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