2012年9月19日 星期三

Arduino::Boolean AND Gate



//boolean_and.pde
#define A 2
#define B 3
#define Y0 4

void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/20>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Boolean algebra AND Gate example");
Serial.println("Y0=B*A");
Serial.println("B,A=>Y0");
Serial.println("------------");
Serial.println("0,0  =>0");
Serial.println("0,1  =>0");
Serial.println("1,0  =>0");
Serial.println("1,1  =>1");

pinMode(A,INPUT);
pinMode(B,INPUT);
pinMode(Y0,OUTPUT);
}
void loop() {
boolean OutY0;
OutY0=digitalRead(B) && digitalRead(A) ;
digitalWrite(Y0,OutY0);
}

2012年9月18日 星期二

Boolean Algebra



#define A 2
#define B 3
#define C 4
#define Y0 5
#define Y1 6
#define Y2 7
#define Y3 8
void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/18>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Boolean algebra example");
Serial.println("Y0=/C*/B*/A+C*B*A");
Serial.println("Y1=/C*/B*A+C*B*/A");
Serial.println("Y2=/C*B*/A+C*/B*A");
Serial.println("Y3=/C*B*A+C*/B*/A");
Serial.println("C,B,A=>Y3,Y2,Y1,Y0");
Serial.println("--------------------");
Serial.println("0,0,0  =>0,0,0,1");
Serial.println("0,0,1  =>0,0,1,0");
Serial.println("0,1,0  =>0,1,0,0");
Serial.println("0,1,1  =>1,0,0,0");
Serial.println("1,0,0  =>1,0,0,0");
Serial.println("1,0,1  =>0,1,0,0");
Serial.println("1,1,0  =>0,0,1,0");
Serial.println("1,1,1  =>0,0,0,1");

pinMode(A,INPUT);
pinMode(B,INPUT);
pinMode(C,INPUT);
pinMode(Y0,OUTPUT);
pinMode(Y1,OUTPUT);
pinMode(Y2,OUTPUT);
pinMode(Y3,OUTPUT);
}
void loop() {
  boolean OutY3,OutY2,OutY1,OutY0;
//Serial.println("Y0=/C*/B*/A+C*B*A");
OutY0=!digitalRead(C) && !digitalRead(B) && !digitalRead(A) ||digitalRead(C) && digitalRead(B) && digitalRead(A) ;
//Serial.println("Y1=/C*/B*A+C*B*/A");
OutY1=!digitalRead(C) && !digitalRead(B) && digitalRead(A) ||digitalRead(C) && digitalRead(B) && !digitalRead(A) ;
//Serial.println("Y2=/C*B*/A+C*/B*A");
OutY2=!digitalRead(C) && digitalRead(B) && !digitalRead(A) ||digitalRead(C) && !digitalRead(B) && digitalRead(A) ;
//Serial.println("Y3=/C*B*A+C*/B*/A");
OutY3=!digitalRead(C) && digitalRead(B) && digitalRead(A) ||digitalRead(C) && !digitalRead(B) && !digitalRead(A) ;
digitalWrite(Y0,OutY0);
digitalWrite(Y1,OutY1);
digitalWrite(Y2,OutY2);
digitalWrite(Y3,OutY3);
}

Arduino::Simulate IC 7483



#define A_0 2
#define A_1 3
#define A_2 4
#define A_3 5
#define B_0 6
#define B_1 7
#define B_2 8
#define B_3 9
#define S0 10
#define S1 11
#define S2 12
#define S3 13
#define S4 14
void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/18>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Simulate IC7483");
Serial.println("S[4..0]=A[3..0]+B[3..0]");
pinMode(A_0,INPUT);
pinMode(A_1,INPUT);
pinMode(A_2,INPUT);
pinMode(A_3,INPUT);
pinMode(B_0,INPUT);
pinMode(B_1,INPUT);
pinMode(B_2,INPUT);
pinMode(B_3,INPUT);
pinMode(S0,OUTPUT);
pinMode(S1,OUTPUT);
pinMode(S2,OUTPUT);
pinMode(S3,OUTPUT);
pinMode(S4,OUTPUT);
}
void loop() {
int Ain,Bin,Sum;
int InA,InB,InC,InD;

//Input Pin Map InData
InA=digitalRead(A_0);
InB=digitalRead(A_1);
InC=digitalRead(A_2);
InD=digitalRead(A_3);
//Input Pin Map Ain
Ain=(InA) | (InB<<1) | (InC<<2) | (InD<<3);
//Input Pin Map Bin
InA=digitalRead(B_0);
InB=digitalRead(B_1);
InC=digitalRead(B_2);
InD=digitalRead(B_3);
Bin=(InA) | (InB<<1) | (InC<<2) | (InD<<3);
Sum=Ain+Bin;
//Serial.print("Ain=0x");Serial.println(Ain,HEX);
//Serial.print("Bin=0x");Serial.println(Bin,HEX);
//Serial.print("Sum=0x");Serial.println(Sum,HEX);
//Serial.println("===========================");
//Sum Map Output Pin
if ((Sum & 1)!=0) //-------------check bit 0
    {digitalWrite(S0,HIGH);}
else
    {digitalWrite(S0,LOW);}
if ((Sum & 2)!=0) //-------------check bit 1
    {digitalWrite(S1,HIGH);}
else
    {digitalWrite(S1,LOW);}
if ((Sum & 4)!=0) //-------------check bit 2
    {digitalWrite(S2,HIGH);}
else
    {digitalWrite(S2,LOW);}
if ((Sum & 8)!=0) //-------------check bit 3
    {digitalWrite(S3,HIGH);}
else
    {digitalWrite(S3,LOW);}
if ((Sum & 16)!=0) //-------------check bit 4
    {digitalWrite(S4,HIGH);}
else
    {digitalWrite(S4,LOW);}      
}

Arduino::Simulate IC7447

 //==========SimIC7447.pde#define A 2#define B 3#define C 4#define D 5#define sa 6#define sb 7#define sc 8#define sd 9#define se 10#define sf 11#define sg 12void setup() {Serial.begin(9600);Serial.println("Chang Yung Fu <<<2012/9/18>>>");Serial.println("Combining Logic using  Arduino");Serial.println("Simulate IC 7447");Serial.println("D,C,B,A=>sa,sb,sc,sd,se,sf,sg");Serial.println("--------------------------");Serial.println("0x0 => b1111110");Serial.println("0x1 => b0110000");Serial.println("0x2 => b1101101");Serial.println("0x3 => b1111001");Serial.println("0x4 => b0110011");Serial.println("0x5 => b1011011");Serial.println("0x6 => b1011111");Serial.println("0x7 => b1110000");Serial.println("0x8 => b1111111");Serial.println("0x9 => b1111011");Serial.println("0xA => b1110111");Serial.println("0xb => b0011111");Serial.println("0xC => b1001110");Serial.println("0xD => b0111101");Serial.println("0xE => b1001111");Serial.println("0xF => b1000111");pinMode(A,INPUT);pinMode(B,INPUT);pinMode(C,INPUT);pinMode(D,INPUT);pinMode(sa,OUTPUT);pinMode(sb,OUTPUT);pinMode(sc,OUTPUT);pinMode(sd,OUTPUT);pinMode(se,OUTPUT);pinMode(sf,OUTPUT);pinMode(sg,OUTPUT);}void loop() {int InData,OutData;int Table[]={0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,0x47};  //Input Pin Map InDataInData=0;if (digitalRead(A)==HIGH)     {InData=InData |0x1;}else    {InData=InData & (~0x1);}if (digitalRead(B)==HIGH)     {InData=InData |0x2;}else    {InData=InData & (~0x2);}if (digitalRead(C)==HIGH)     {InData=InData |0x4;}else    {InData=InData & (~0x4);}if (digitalRead(D)==HIGH)     {InData=InData |0x8;}else    {InData=InData & (~0x8);} //Serial.print("InData(Bin)=");Serial.println(InData,BIN);    //Serial.println("------------------------------------");  //Table Map OutDataOutData=Table[InData];//Serial.print("OutData(Bin)=");Serial.println(OutData,BIN);    //Serial.println("------------------------------------");  //OutData Map Output Pinif ((OutData & 1)==0) //-------------check bit 0     {digitalWrite(sg,HIGH);}else    {digitalWrite(sg,LOW);}if ((OutData & 2)==0) //-------------check bit 1     {digitalWrite(sf,HIGH);}else    {digitalWrite(sf,LOW);}if ((OutData & 4)==0) //-------------check bit 2     {digitalWrite(se,HIGH);}else    {digitalWrite(se,LOW);}if ((OutData & 8)==0) //-------------check bit 3     {digitalWrite(sd,HIGH);}else    {digitalWrite(sd,LOW);}  if ((OutData & 16)==0) //-------------check bit 4     {digitalWrite(sc,HIGH);}else    {digitalWrite(sc,LOW);}    if ((OutData & 32)==0) //-------------check bit 5     {digitalWrite(sb,HIGH);}else    {digitalWrite(sb,LOW);}    if ((OutData & 64)==0) //-------------check bit 6     {digitalWrite(sa,HIGH);}else    {digitalWrite(sa,LOW);}        //----------Simulate--------------------------------
}


2012年9月17日 星期一

Combining Logic using Arduino

Combining Logic using  Arduino
Truth table
C,B,A=>Y3,Y2,Y1,Y0
--------------------
0,0,0  =>0,0,0,1
0,0,1  =>0,0,1,0
0,1,0  =>0,1,0,0
0,1,1  =>1,0,0,0

1,0,0  =>1,0,0,0
1,0,1  =>0,1,0,0
1,1,0  =>0,0,1,0
1,1,1  =>0,0,0,1
//---------Circuit--------------

//-----truthtable.pde----------------

#define A 2
#define B 3
#define C 4
#define Y0 5
#define Y1 6
#define Y2 7
#define Y3 8
void setup() {
Serial.begin(9600);
Serial.println("Chang Yung Fu <<<2012/9/18>>>");
Serial.println("Combining Logic using  Arduino");
Serial.println("Truth Table example");
Serial.println("C,B,A=>Y3,Y2,Y1,Y0");
Serial.println("--------------------");
Serial.println("0,0,0  =>0,0,0,1");
Serial.println("0,0,1  =>0,0,1,0");
Serial.println("0,1,0  =>0,1,0,0");
Serial.println("0,1,1  =>1,0,0,0");
Serial.println("1,0,0  =>1,0,0,0");
Serial.println("1,0,1  =>0,1,0,0");
Serial.println("1,1,0  =>0,0,1,0");
Serial.println("1,1,1  =>0,0,0,1");
pinMode(A,INPUT);
pinMode(B,INPUT);
pinMode(C,INPUT);
pinMode(Y0,OUTPUT);
pinMode(Y1,OUTPUT);
pinMode(Y2,OUTPUT);
pinMode(Y3,OUTPUT);
}
void loop() {

int InData,InA,InB,InC,InD,OutData;
int Table[]={1,2,4,8,8,4,2,1};
//Input Pin Map InData
InA=digitalRead(A);
InB=digitalRead(B);
InC=digitalRead(C);
InD=digitalRead(D);
InData=(InA) | (InB<<1) | (InC<<2) | (InD<<3);


//Serial.print("InData(Bin)=");Serial.println(InData,BIN);    
//Serial.println("------------------------------------");  
//Table Map OutData
OutData=Table[InData];
//Serial.print("OutData(Bin)=");Serial.println(OutData,BIN);    
//Serial.println("------------------------------------");  
//OutData Map Output Pin
if ((OutData & 1)!=0) //-------------check bit 0 
    {digitalWrite(Y0,HIGH);}
else
    {digitalWrite(Y0,LOW);}
if ((OutData & 2)!=0) //-------------check bit 1 
    {digitalWrite(Y1,HIGH);}
else
    {digitalWrite(Y1,LOW);}
if ((OutData & 4)!=0) //-------------check bit 2 
    {digitalWrite(Y2,HIGH);}
else
    {digitalWrite(Y2,LOW);}
if ((OutData & 8)!=0) //-------------check bit 3 
    {digitalWrite(Y3,HIGH);}
else
    {digitalWrite(Y3,LOW);}    
}
//-----------Simulate -------------------