用51单片机程序显示3位7段数码管,求具体程序

如题所述

假设为共阴极数码管,驱动输入端接单片机P1口,共阴极接P2口的0.1.2.脚。我的程序如下,当前显示数字123
#include <reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef long int uint32;
code uint8 number[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay_ms(uint16 x)//1ms延时
{
uint8 i = 121;
while(x > 0)
{
i = 121;
while(i > 0)
i --;
x --;
}
}
void xianshi(uint16 x)
{
uint8 i=0;
for(i=0;i<=2;i++)
{
P2=~(1<<i);
switch(i)
{
case 0:P1=number[(x/1)%10];break;
case 1:P1=number[(x/10)%10];break;
case 2:P1=number[(x/100)%10];break;
default:break;
}
delay_ms(10);
}
}
main()
{
while(1)
{
xianshi(123);
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-02
动态扫描么,要显示??
相似回答