用74HC164实现数码管的静态显示
要实现静态显示所用的IO较多,因此利用移位寄存器74HC164对IO的扩展来驱动数码管,从而实现静态显示。
硬件电路百度上很多,这里就不说了,写个程序吧
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
const uchar table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef};
sbit dat=P2^0;
sbit clk=P2^1;
void disp(long a);
void write_bit(uchar num);
void main(void)
{
disp(45678);
while(1);
}
void disp(long a)
{
uchar ge,shi,bai,qian,wan;
wan=a/10000;
qian=a000/1000;
bai=a00/100;
shi=a0/10;
ge=a;
write_bit(table[wan]);
write_bit(table[qian]);
write_bit(table[bai]);
write_bit(table[shi]);
write_bit(table[ge]);
}
void write_bit(uchar num)
{
uchar i;
for(i=0;i<8;i++)
{
clk=0; //时钟拉低,等待数据
dat=(num&0x80)?1:0; //最高位开始送,表达式为真时,结果为1,否则为0
clk=1; //时钟拉高,上升沿到来,164数据移位
num<<=1;
}
}