移位寄存器74595如何驱动数码管
发布网友
发布时间:2022-04-26 07:22
我来回答
共2个回答
热心网友
时间:2022-06-25 05:35
595是个芯片,不是寄存器。寄存器怎么可以说来驱动数码管呢?是用芯片驱动数码管,你就是把这个芯片的abcdefgh端和数码管的ABCDEFGDp段连接起来,然后用SPI通信方式给芯片的寄存器送数据就OK了。
但是这个通讯方式你得清楚哦!要是你知道怎么用单片机的IO口驱动数码管的话,你就应该知道这个原理的,因为这个芯片可以说就好比是单片机的输出口的扩充。
希望这个回答你能看得懂。
void SPI_Send_Byte(uchar b_yte)
{
uchar k;
for(k=0;k<8;k++)
{
DS_OUT = (b_yte>>(7-k))&0x01;
S_CLK;
S_CLK;S_CLK;
R_CLK;
}
}
这个函数就是给595芯片传一个字节的数据的例子
下面这个程序是用595驱动点阵的一个程序实例,你看看595是怎么写程序的就好了。
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define S_CLK CLK = 1
#define R_CLK CLK = 0
sbit DS_OUT = P3^0;
sbit CLK = P3^1;
sbit SP_CP = P2^0;
sbit OE = P2^1;
uchar idata dispram[8]={0}; //用于显示的中间数组
uchar code digit_tab[]={
0xFF,0xC1,0xBE,0xBE,0xC1,0xFF,0xFF,0xFF,/*"0",0*/
0xFF,0xBD,0x80,0xBF,0xFF,0xFF,0xFF,0xFF,/*"1",1*/
0xFF,0x9D,0xAE,0xB6,0xB9,0xFF,0xFF,0xFF,/*"2",2*/
0xFF,0xDD,0xB6,0xB6,0xC9,0xFF,0xFF,0xFF,/*"3",3*/
0xFF,0xC7,0xD9,0x80,0xDF,0xFF,0xFF,0xFF,/*"4",4*/
0xFF,0xB0,0xB6,0xB6,0xCE,0xFF,0xFF,0xFF,/*"5",5*/
0xFF,0xC1,0xB6,0xB6,0xCD,0xFF,0xFF,0xFF,/*"6",6*/
0xFF,0xFC,0x8E,0xF6,0xF8,0xFF,0xFF,0xFF,/*"7",7*/
0xFF,0xC9,0xB6,0xB6,0xC9,0xFF,0xFF,0xFF,/*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0,0xBF,0xBF,0xC0,0xFF,0xFF,0xFF,/*"U",30*/
0xFF,0xF0,0x8F,0x8F,0xF0,0xFF,0xFF,0xFF,/*"V",31*/
0xFF,0x80,0xCF,0xCF,0x80,0xFF,0xFF,0xFF,/*"W",32*/
0xFF,0x9C,0xE3,0xE3,0x9C,0xFF,0xFF,0xFF,/*"X",33*/
0xFC,0xFB,0x87,0xFB,0xFC,0xFF,0xFF,0xFF,/*"Y",34*/
0xFF,0x9E,0xA6,0xB2,0xBC,0xFF,0xFF,0xFF/*"Z",35*/
};
void Time0(void)
{
TMOD = 0x01;
TH0 = 0xfd;
TL0 = 0x18;
TCON = 0x10; //运行定时器
IE |= 0x02; //允许定时器0中断
}
void delay(uint i) //延时
{
register uchar j;
for(;i;i--)
{for(j=0;j<255;j++);}
}
void SPI_Send_Byte(uchar b_yte)
{
uchar k;
for(k=0;k<8;k++)
{
DS_OUT = (b_yte>>(7-k))&0x01;
S_CLK;
S_CLK;S_CLK;
R_CLK;
}
}
/**********从LRp的第LRheard个字左移出显示number个字************/
void L_Removeout_Word(uchar LRp[],uchar LRheard,uchar number,uchar s,uchar state)
{
uchar i,k,l;
for(i=0;i<number;i++)
{
for(k=0;k<8;k++)
{
for(l=0;l<8;l++)
{
dispram[l]=dispram[l]<<1|LRp[(i+LRheard)*8+l]>>(7-k);
}
delay(20*s);
}
delay(20*state);
}
}
void M_Words(uchar wordsp[],uchar MWheard,uchar number,uchar s,uchar state)
{register uchar i,w;
for(w=0;w<number;w++)
{
for(i=0;i<8;i++)
{
dispram[i]=wordsp[(MWheard+w)*8+i];
delay(s*20);
}
delay(state*20);
}
}
void SPI_Send_Byte(uchar b_yte);
void main(void)
{
Time0();
EA = 1;
OE = 0; //允许595输出
while(1)
{
L_Removeout_Word(digit_tab,0,36,2,20);
M_Words(digit_tab,0,36,2,20);
}
}
void timer0(void) interrupt 1 //定时器0的中断服务程序
{
register uchar m;
TH0 = 0xfd;
TL0 = 0x18;
m = P1; //获取当前的扫描列
m =(++m)&0x07;
SPI_Send_Byte(~dispram[m]);
P1 &= 0xf8; //扫描完后将当前列加一
P1 |= m;
SP_CP = 1;
SP_CP = 0;
}
热心网友
时间:2022-06-25 05:36
74HC595和74LS164一样,是串入并出的移位寄存器。
学过数字电路的,都知道寄存器是可以驱动数码管的。
一般的单片机教材上,都给出了164的使用方法,而595是后起之秀,介绍甚少。
由于595比164性能更好一些,在LED点阵显示屏上,普遍都用595了。
用74HC595点阵显示屏可见:
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/e4d7db39c77e9f35b9998f26.html
用74HC595驱动数码管的电路和程序如下。注意:电路中省略了限流电阻(1K左右)。
;用595并行输出带动4个数码显示器.
ORG 0000H
SJMP START
START:
MOV SCON, #0
M_LOOP:
MOV 30H, #1
MOV 31H, #3
MOV 32H, #0
MOV 33H, #8
CALL TXD_595
LJMP M_LOOP
;**************************************************
;595发送程序.
;**************************************************
TXD_595:
MOV R0, #30H
TXD_B:
MOV A, @R0
ADD A, #(TAB - $ - 3)
MOVC A, @A+PC
CPL A
MOV SBUF, A
JNB TI, $
CLR TI
INC R0
CJNE R0, #34H, TXD_B
CLR P3.2
SETB P3.2
RET
TAB:
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H
DB 7FH, 6FH, 77H, 7CH, 39H, 5EH, 79H, 71H
;这些段码是共阴极的,若为共阳极 取反即可.
;-------------------------------------------------