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
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);}
}
//--------Instruction ------------#define Serial.beginSerial,printSerial.printlnpinModedigitalReaddigitalWriteif ....else....Set Var Bit=0,1 or notCheck Var Bit=0 or 1.
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--------------
#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 -------------------
//--------Instruction ------------#define Serial.beginSerial,printSerial.printlnpinModedigitalReaddigitalWriteif ....else....Set Var Bit=0,1 or notCheck Var Bit=0 or 1.
訂閱:
文章 (Atom)