新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 试验数码管上显示数字( 单片机直接实现位选 共阴极)

试验数码管上显示数字( 单片机直接实现位选 共阴极)

作者: 时间:2016-12-01 来源:网络 收藏

位定义

本文引用地址:https://www.eepw.com.cn/article/201612/324172.htm

#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uchar code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
while(1)
{
LSA=0;
LSB=0;
LSC=0;
P0=num[6];
delay(2);
LSA=1;
LSB=0;
LSC=0;
P0=num[6];
delay(2);
}
}


//让八个数码管全部亮并且从0~9循环

#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//段选,选择要显示的数字
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//八位数码管
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}


上一页 1 2 下一页

评论


技术专区

关闭