11.7

今天学习了七段数码管的显示,下午编写了一个表的程序

void display(uint8_t val, uint8_t bit);

const uint8_t code_pins[] = {1,2,3,4,5,6,7,8}; //a~h段输出引脚

const uint8_t bit_pins[]  = {9,10,11,12}; //位

const uint8_t decode[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; //共阴极译码值

uint8_t  fen1=0;

uint8_t fen2=8;

uint8_t miao1=0;

uint8_t miao2=0;

void setup() {

for (int i = 0; i<8; i++) {

pinMode(code_pins[i], OUTPUT); // 送段值引脚初始化

}

for (int i = 0; i < 4; i++) {

pinMode(bit_pins[i], OUTPUT); // 送位值引脚初始化

}

}

void loop() {

for(int j=0;j<9;j++)

{display(fen1,0);

delay(24);

display(fen2,1);

delay(24);

display(miao1,2);

delay(24);

display(miao2,3);

delay(24);}

if(miao2<9)

miao2++;

else if(miao1<5)

{miao1++;miao2=0;}

else if(fen2<9)

{fen2++;miao1=0;miao2=0;}

else if(fen1<5)

{fen1++;fen2=0;miao1=0;miao2=0;}

else

{  fen1=0;

fen2=0;

miao1=0;

miao2=0;}

}

void display(uint8_t val, uint8_t bit) {

uint8_t code = decode[val];

for (int i = 0; i < 8; i++ ) {

digitalWrite(code_pins[i],code & ((uint8_t)1<

for (int i = 0; i < 4; i++) {

if (i == bit) {

digitalWrite(bit_pins[i], LOW); // 选择位有效

}

else {

digitalWrite(bit_pins[i], HIGH);

}

}

}

你可能感兴趣的:(11.7)