1 Y6C控制锁存器,进一步控制段选(低电平有效)
2 Y7C控制锁存器,进一步控制位选(高电平有效)
3 数码管为共阳极数码管
实现功能:
8段数码管分别依次显示0—F的内容,以及从0到F分别由8个数码管依次显示。
#include "reg52.h"
unsigned char code display_duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(unsigned int t)
{
while(t--);
}
void InitHC138(unsigned char n)
{
switch(n)
{
case 4:
P2=(P2&0x1f)|0x80;
break;
case 5:
P2=(P2&0x1f)|0xa0;
break;
case 6:
P2=(P2&0x1f)|0xc0;
break;
case 7:
P2=(P2&0x1f)|0xe0;
break;
}
}
void display(unsigned int pos,unsigned int num)
{
InitHC138(6);
P0=0x01<<pos;
InitHC138(7);
P0=display_duan[num];
}
void main()
{
while(1)
{
int i,j=0;
for(i=0;i<=15;i++)
{
for(j=0;j<=7;j++)
{
display(j,i);
delay(60000);
}
}
for(j=0;j<=7;j++)
{
for(i=0;i<=15;i++)
{
display(j,i);
delay(60000);
}
}
delay(60000);
delay(60000);
}
}