int i;
int j;
int number;
int value;
int weight[]={8,4,2,1};
int seg7_pin[]={2,3,4,5,6,7,8};
int dip_sw[]={9,10,11,12};
int seg7_table[]={
~0xc0,~0xf9,~0xa4,~0xb0,
~0x99,~0x92,~0x82,~0xf8,
~0x80,~0x90,~0x88,~0x83,
~0xc6,~0xa1,~0x86,~0x8E
};
//---------------------------------
void setup()
{
int a,b;
for(a=0;a<7;a++)
{
pinMode(seg7_pin[a],OUTPUT);
}
for(b=0;b<4;b++)
{
pinMode(dip_sw[b],INPUT);
}
}
//---------------------------------------
void outport(char data)
{
for(j=0;j<7;j++)
{
if(data %2==1)
digitalWrite(seg7_pin[j],HIGH);
else
digitalWrite(seg7_pin[j],LOW);
data=data/2;
}
}
//---------------------------------------
void loop()
{
number=0;
for(i=0;i<4;i++)
{
value=digitalRead(dip_sw[i]);
if(value==HIGH)
{
number=number+weight[i];
}
}
outport(seg7_table[number]);
}
沒有留言:
張貼留言