用c语言使keil实现数码管从0依次到99的显示
以下为使用Keil实现数码管从0依次到99的显示的代码:
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit D1 = P2^0;
sbit D2 = P2^1;
sbit D3 = P2^2;
sbit D4 = P2^3;
uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
void delay(uint i) //延时函数
{
while(i--);
}
void display(uchar num) //数码管显示函数
{
uchar a, b;
a = num / 10;
b = num % 10;
D1 = 0;
P0 = table[a];
delay(100);
D1 = 1;
D2 = 0;
P0 = table[b];
delay(100);
D2 = 1;
}
void main()
{
uint i;
for(i = 0; i < 100; i++)
{
display(i);
}
while(1);
}
注:该代码使用的是共阴数码管,如果使用共阳数码管,需要在数码管显示函数中将table数组中的数码值取反
原文地址: https://www.cveoy.top/t/topic/fjwK 著作权归作者所有。请勿转载和采集!