51单片机控制3位共阴数码管
扫描二维码
随时随地手机看文章
51单片机控制3位7段共阴数码管,P0口控制 abcdefg dp,P2.0-P2.3控制123位。
要使其间隔1s分别显示123,231, 321, 213...........无限循环
给我一个程序
最佳答案:
//下列程序,经过仿真,符合要求。
#include
#include
#define uchar unsigned char
sbit bit1 = P2^0;
sbit bit2 = P2^1;
sbit bit3 = P2^2;
uchar code dulatab[] = { //数字编码0-9
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
//----------------------------------------------------------------
void delay(uchar time)
{
uchar i, j;
for(i = 0; i < time; i++) for(j = 0; j < 110; j++);
}
//----------------------------------------------------------------
void disp_num(uchar a, b, c)
{
uchar i;
for(i = 1; i < 250; i++) {
P2 = 255; //关显示.
P0 = dulatab[a]; bit1 = 0; delay(4);
P2 = 255; //关显示.
P0 = dulatab[b]; bit2 = 0; delay(4);
P2 = 255; //关显示.
P0 = dulatab[c]; bit3 = 0; delay(4);
}
}
//----------------------------------------------------------------
void main()
{
while(1) {
//要使其间隔1s分别显示123,231, 321, 213...........无限循环.
disp_num(1, 2, 3);
disp_num(2, 3, 1);
disp_num(3, 2, 1);
disp_num(2, 1, 3);
// disp_num(?, ?, ?); 还想显示?内容,楼主可自行编写.
// disp_num(?, ?, ?);
}
}