int seg7[]={2,3,4,5,6,7,8,9};
int dip_sw[]={13,12,11,10};
int weight[]={8,4,2,1};
int num;
int value;
char table_7seg[]=
{
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0Xc6,0xa1,0x86,0x8E
};
//--------------------------------------------------
void setup()
{
// put your setup code here, to run once:
for(int i=0;i<8;i++)
{
pinMode(seg7[i],OUTPUT);
}
for(int i=0;i<4;i++)
{
pinMode(dip_sw[i],INPUT);
digitalWrite(dip_sw[i],HIGH);
}
}
//---------------------------------------------------------
void tx(byte data)
{
for(int j=0;j<8;j++)
{
if(data%2==1)
digitalWrite(seg7[j],LOW);
else
digitalWrite(seg7[j],HIGH);
data=data/2;
}
}
//--------------------------------------------------------
void loop()
{
// put your main code here, to run repeatedly:
num=0;
for(int k=0;k<4;k++)
{
value=digitalRead(dip_sw[k]);
if(value==HIGH)
num=num+ weight[k];
}
tx(table_7seg[num]);
}
沒有留言:
張貼留言