2012年9月18日 星期二

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--------------------------------
}


沒有留言:

張貼留言