用c语言写LED八位显示数字为23132108的代码
时间: 2023-04-05 07:04:49 浏览: 80
以下是用C语言写LED八位显示数字为23132108的代码:
```
#include <stdio.h>
int main() {
int num = 23132108;
int led[8] = {0}; // 存储每个数码管的数字
// 将数字拆分到数组中
for (int i = 0; i < 8; i++) {
led[i] = num % 10;
num /= 10;
}
// 输出每个数码管的数字
for (int i = 7; i >= 0; i--) {
printf("%d ", led[i]);
}
return 0;
}
```
这个程序将数字23132108拆分到一个数组中,然后按照从右到左的顺序输出每个数码管的数字。
相关问题
51单片机c语言写led八位显示数字为23132108的代码
以下是代码示例:
```
#include <reg51.h>
// 定义数码管段码
unsigned char code LED_DuanMa[10] = {
0x3F, 0x06, 0x5B, 0x4F, 0x66,
0x6D, 0x7D, 0x07, 0x7F, 0x6F
};
// 定义数码管位码
unsigned char code LED_WeiMa[8] = {
0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F
};
void main() {
unsigned int num = 23132108; // 要显示的数字
unsigned char i, j, k, m;
while (1) {
// 循环显示每一位数字
for (i = 0; i < 8; i++) {
// 计算当前位的数字
j = num % 10;
num /= 10;
// 显示当前位的数字
P0 = LED_DuanMa[j];
P2 = LED_WeiMa[i];
// 延时一段时间
for (k = 0; k < 100; k++) {
for (m = 0; m < 100; m++);
}
}
}
}
```
51单片机c语言编写led显示数字为23132108的代码
以下是代码示例:
#include <reg51.h>
#define LED P1
void delay(unsigned int time) // 延时函数
{
unsigned int i, j;
for (i = time; i > 0; i--)
for (j = 110; j > 0; j--);
}
void main()
{
unsigned char num[8] = {2, 3, 1, 3, 2, 1, 0, 8}; // 要显示的数字
unsigned char i;
while (1)
{
for (i = 0; i < 8; i++)
{
LED = ~(1 << i); // 选择要显示的数码管
LED = ~(0x7f & (num[i] << 1)); // 显示数字
delay(500); // 延时
}
}
}