7段数码管静态显示程序
扫描二维码
随时随地手机看文章
/***************************************************
7段数码管静态显示程序
***************************************************/
#include
/*4个7段数码管锁存器地址*/
#defineLED1ADDR0x80
#defineLED2ADDR0x81
#defineLED3ADDR0x82
#defineLED4ADDR0x83
//0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
/*0-9a-f的7段数码管显示编码*/
unsignedcharledcode[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x00};
/*存放要显示的数字值*/
unsignedcharval[4];//
/*延时的子程序*/
voiddelay(unsignedintt)
{
unsignedinti;
for(i=0;i
;
}
/*写锁存器的子程序*/
voidwraddr(unsignedintaddr1,unsignedchard)
{
P2=addr1;
P0=d;
}
/*显示子程序*/
voiddisplay(void)
{unsignedintaddr[4]={LED1ADDR,LED2ADDR,LED3ADDR,LED4ADDR};
inti;
for(i=0;i<4;i++)
{delay(50);
if((val[i]>=0)&&(val[i]<=15))
{wraddr(addr[i],ledcode[val[i]]);
}
else
{wraddr(addr[i],0xff);
}
}
}
/*初始化子程序*/
voidinit(void)
{wraddr(LED1ADDR,0XFF);
wraddr(LED2ADDR,0XFF);
wraddr(LED3ADDR,0XFF);
wraddr(LED4ADDR,0XFF);
//输入要显示的数值
val[0]=0;
val[1]=0;
val[2]=0;
val[3]=0;
}
/*主程序入口*/
intmain(void)
{
unsignedintii,jj=0,kk=0;
init();
while(1)
{
for(ii=0;ii<0xff;ii++)
display();
jj++;
if(jj==10)
jj=0;
val[0]=jj;
val[1]=jj;
val[2]=jj;
val[3]=jj;
}
}