74HC595是一個8位串列輸入、並行輸出的位移快取器:並行輸出為三態輸出。在SCK 的上升沿,串列數據由SDL輸入到內部的8位位移快取器,並由Q7'輸出,而並行輸出則是在LCK的上升沿將在8位位移快取器的數據存入到8位並行輸出快取器。當串列數據輸入端OE的控制信號為低使能時,並行輸出端的輸出值等於並行輸出快取器所存儲的值。
基本介紹
- 中文名:74HC595
- 類別:存儲器
- 功能:數據存儲
- 結構:矽結構的CMOS器件
特點
輸出能力
引腳說明
符號 | 引腳 | 描述 |
Q0--Q7 | 第15腳,第1-7腳 | 8位並行數據輸出, |
GND | 第8腳 | 地 |
Q7’ | 第9腳 | 串列數據輸出 |
/MR | 第10腳 | 主復位(低電平有效) |
SH_CP | 第11腳 | 數據輸入時鐘線 |
ST_CP | 第12腳 | 輸出存儲器鎖存時鐘線 |
/OE | 第13腳 | 輸出有效(低電平有效) |
DS | 第14腳 | 串列數據輸入 |
VCC | 第16腳 | 電源 |
使用方法
真值表
輸入 | 輸出 | 功能 | |||||
SHCP | STCP | OE | MR | DS | Q7’ | Qn | |
× | × | L | L | × | L | NC | MR為低電平時僅僅影響移位暫存器 |
× | ↑ | L | L | × | L | L | 清空移位暫存器到輸出暫存器 |
× | × | H | L | × | L | Z | 清空移位暫存器,並行輸出為高阻狀態 |
↑ | × | L | H | H | Q6’ | NC | 邏輯高電平移入移位暫存器狀態0,包含所有的移位暫存器狀態 移入 |
× | ↑ | L | H | × | NC | Qn’ | 移位暫存器的內容到達保持暫存器並從並口輸出 |
↑ | ↑ | L | H | × | Q6’ | Qn’ | 移位暫存器內容移入,先前的移位暫存器的內容到達保持暫存器並出 |
相關注釋
程式樣例
#include <msp430.h>void main(void){ WDTCTL = WDTPW + WDTHOLD; P1DIR |= BIT0 + BIT1; P1OUT &= ~BIT0; USICTL0 |= USIPE6 + USIPE5 + USIMST + USIOE; USICTL1 |= USIIE; USICKCTL = USIDIV_7 + USISSEL_2; USICTL0 &= ~USISWRST; while(1) { P1OUT |= BIT0; USISRH = 0xAA; USISRL = 0xAA; USICNT = 0x10 + USI16B; // 16位數,級聯可用. while((USICTL1 & USIIFG) != 0x01){ //此處可以乾別的 //這裡寫入與SPI無關的代碼,共8*16=128條單周期指令. } USICTL1 &= ~USIIFG; P1OUT &= ~BIT0; }}
//74HC595 LED控制#include <reg51.h>#include <intrins.h>#define NOP() _nop_()sbit MOSIO=P3^4;sbit R_CLK=P3^5;sbit S_CLK=P3^6;void delay(unsigned int i);void HC595SendData(unsigned char SendVal);main( ){ unsigned char Led=0xfe; HC595SendData(0xff); while(1) { HC595SendData(Led); Led<<=1; Led =Led|0x01; if(Led==0xff)Led=0xfe; delay(200); }}void delay(unsigned int i){ unsigned int j; for(i;i>0;i--) for(j=300;j>0;j--);}void HC595SendData(unsigned char SendVal){ unsigned char i; for(i=0;i<8;i++) { if((SendVal<<i)&0x80)MOSIO=1; else MOSIO=0; S_CLK=0; NOP(); NOP(); S_CLK=1; } R_CLK=0; NOP(); NOP(); R_CLK=1;}
#include<reg51.h>#include<intrins.h>#define NOP()_nop_()sbit MOSIO=P3^4;sbit R_CLK=P3^5;sbit S_CLK=P3^6;void delay(unsigned int i);void HC595SendData(unsigned char SendVal);unsigned char code LED7Code[]={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71};main(){ unsigned char HC595SendVal; static unsigned char LedNumVal=0; while(1) { LedNumVal++; HC595SendVal=LED7Code[LedNumVal%16]; HC595SendData(HC595SendVal); delay(200); }}void delay(unsigned int i){ unsigned int j; for(i;i>0;i--) for(j=300;j>0;j--);}void HC595SendData(unsigned char SendVal){ unsigned char i; for(i=0;i<8;i++) { if((SendVal<<i)&0x80)MOSIO=1; else MOSIO=0; S_CLK=0; NOP(); NOP(); S_CLK=1; } R_CLK=0; NOP(); NOP(); R_CLK=1;}
#include<reg51.h>#include<intrins.h>#define NOP() _nop_()sbit MOSIO=P3^7;sbit R_CLK=P3^5;sbit S_CLK=P3^6;sbit en573=P1^3;sbit ends=P1^2;void HC595SendData(unsigned int SendVal);unsigned int Val;unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char code digittab[18][8]={{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00},//0{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00},//1{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00},//2{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00},//3{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00},//4{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00},//5{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00},//6{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00},//7{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00},//8{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00},//9{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00},//P{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00},//R{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00},//E{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00},//C{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00},//H{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00},//I{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00},//N{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00}};unsigned int timecount;unsigned char cnta;unsigned char cntb;void main(void){ TMOD=0x01; TH0=(65536-3000)/256; TL0=(65536-3000)%256; TR0=1; ET0=1; EA=1; cntb=0; ends=0; en573=0; while(1) { }}void t0(void)interrupt 1 using 0{ TH0=(65536-3000)/256; TL0=(65536-3000)%256; if(cntb<18) { //P1=0xFF; //P2=tab[cnta]; P0=~digittab[cntb][cnta]; Val=tab[cnta]&0x00ff; Val<<=8; Val=Val+0x00ff; HC595SendData(Val); } else { //P2=0xFF; //P1=tab[cnta]; P0=~digittab[cntb-18][cnta]; Val=tab[cnta]; Val=Val+0xFF00; HC595SendData(Val); } if(++cnta>=8)cnta=0; if(++timecount>=333) { timecount=0; if(++cntb>=36)cntb=0; }}void HC595SendData(unsigned int SendVal){ unsigned char i; for(i=0;i<16;i++) { if((SendVal<<i)&0x8000)MOSIO=1;//setdatalinehigh0X8000 else MOSIO=0; //MOSIO=1 S_CLK=0; NOP(); NOP(); S_CLK=1; } R_CLK=0;//setdatalinelow NOP(); NOP(); R_CLK=1;}