2012年9月18日 星期二
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);}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言