Files
51-microcontroller-homework/homework5/src/test1.c
T
2025-04-24 18:44:28 +08:00

47 lines
1.2 KiB
C

// test1.c
// 数码管动态显示自己学号后6位
// display the last 6 digits of your student ID on the Seg.
#include "homework5.h"
unsigned char LedBuff[6] = {
0xFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF};
unsigned char i = 0;
unsigned char display_id[6] = {1, 3, 0, 0, 7, 1};
void test1()
{
// display the number on the Seg.
// 5 is high digit.
// 0 is low digit.
LedBuff[5] = LedChar[display_id[0]];
LedBuff[4] = LedChar[display_id[1]];
LedBuff[3] = LedChar[display_id[2]];
LedBuff[2] = LedChar[display_id[3]];
LedBuff[1] = LedChar[display_id[4]];
LedBuff[0] = LedChar[display_id[5]];
while (1) {
/*
* seg id on 38 transistors:
* Y0: LEDS0 the latest digit.
* Y1: LEDS1 the second digit.
* Y2: LEDS2 the third digit.
* Y3: LEDS3 the forth digit.
* Y4: LEDS4 the fifth digit.
* Y5: LEDS5 the highest digit.
* Y6: 2LED to the LED lights.
*/
set38Transistors(i);
P2 = LedBuff[i];
i++;
timer(1);
// reset the i to 0 when it reaches 6.
if (i >= 6) {
i = 0;
}
}
}
void main()
{
test1();
}