74HC595的程序样例

如题所述

第1个回答  2016-05-10

DS接MOSI,OE/GND接GND,SH_CP接SCLK,ST_CP接使能信号BIT0@P1,MR/VCC接POWER,如果不需要16位,改US16B,不使用H寄存器即可,还有SPI工作期间可以进入低功耗,也可以执行指令. #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模块驱动程序 //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(unsignedinti);void HC595SendData(unsignedcharSendVal);main(){unsignedcharLed=0xfe;HC595SendData(0xff);while(1){ HC595SendData(Led);Led<<=1;Led =Led|0x01;if(Led==0xff)Led=0xfe;delay(200);}}voiddelay(unsignedinti){unsignedintj;for(i;i>0;i--)for(j=300;j>0;j--);}voidHC595SendData(unsignedcharSendVal){unsignedchari;for(i=0;i<8;i++){if((SendVal<<i)&0x80)MOSIO=1;elseMOSIO=0;S_CLK=0;NOP();NOP();S_CLK=1;}R_CLK=0;NOP();NOP();R_CLK=1;}74HC595驱动静态数码管程序 #include<reg51.h>#include<intrins.h>#defineNOP()_nop_()sbitMOSIO=P3^4;sbitR_CLK=P3^5;sbitS_CLK=P3^6;voiddelay(unsignedinti);voidHC595SendData(unsignedcharSendVal);unsignedcharcodeLED7Code[]={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71};main(){unsignedcharHC595SendVal;unsignedintLedNumVal;while(1){ LedNumVal++;HC595SendVal=LED7Code[LedNumVal%16]; HC595SendData(HC595SendVal);delay(200);}}voiddelay(unsignedinti){unsignedintj;for(i;i>0;i--)for(j=300;j>0;j--);}voidHC595SendData(unsignedcharSendVal){unsignedchari;for(i=0;i<8;i++){if((SendVal<<i)&0x80)MOSIO=1;elseMOSIO=0;S_CLK=0;NOP();NOP();S_CLK=1;}R_CLK=0;NOP();NOP();R_CLK=1;}双595驱动点阵程序 #include<reg51.h>#include<intrins.h>#defineNOP()_nop_()sbitMOSIO=P3^7;sbitR_CLK=P3^5;sbitS_CLK=P3^6;sbiten573=P1^3;sbitends=P1^2;voidHC595SendData(unsignedintSendVal);unsignedintVal;unsignedcharcodetab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsignedcharcodedigittab[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}};unsignedinttimecount;unsignedcharcnta;unsignedcharcntb;voidmain(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){ }}voidt0(void)interrupt1using0{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;}}voidHC595SendData(unsignedintSendVal){unsignedchari;for(i=0;i<16;i++){ if((SendVal<<i)&0x8000)MOSIO=1;//setdatalinehigh0X8000elseMOSIO=0; //MOSIO=1S_CLK=0;NOP();NOP();S_CLK=1;}R_CLK=0;//setdatalinelowNOP();NOP();R_CLK=1;}

第2个回答  2021-03-21

74HC595:一个8位串行输入、并行输出的位移缓存器

74HC595的程序样例
= 0x01){ \/\/此处可以干别的\/\/这里写入与SPI无关的代码,共8*16=128条单周期指令.}USICTL1 &= ~USIIFG;P1OUT &= ~BIT0;}}单片机74HC595模块驱动程序 \/\/74HC595 LED控制#include <reg51.h>#include <intrins.h>#define NOP() _nop_()sbit MOSIO=P3^4;sbit R_CLK=P3^5;sbit S_CLK...

74HC595芯片功能和引脚图功能详细介绍
74HC595是硅结构的CMOS器件, 兼容低电压TTL电路,遵守JEDEC标准。 74HC595是具有8位移位寄存器和一个存储器,三态输出功能。 移位寄存器和存储器是分别的时钟。 数据在SHcp的上升沿输入,在STcp的上升沿进入到存储寄存器中去。如果两个时钟连在一起,则移位寄存器总是比存储寄存器早一个脉冲。 移位寄存器...

74HC595芯片功能和引脚图功能详细介绍分别是什么?
74HC595是硅结构的CMOS器件, 兼容低电压TTL电路,遵守JEDEC标准。 74HC595是具有8位移位寄存器和一个存储器,三态输出功能。 移位寄存器和存储器是分别的时钟。 数据在SHcp的上升沿输入,在STcp的上升沿进入到存储寄存器中去。如果两个时钟连在一起,则移位寄存器总是比存储寄存器早一个脉冲。 移位寄存器...

74HC595芯片功能和引脚图功能详细介绍分别是什么?
74HC59574HC595是硅结构的CMOS器件,兼容低电压TTL电路,遵守JEDEC标准。74HC595是具有8位移位寄存器和一个存储器,三态输出功能。移位寄存器和存储器是分别的时钟。数据在SHcp的上升沿输入,在STcp的上升沿进入到存储寄存器中去。如果两个时钟连在一起,则移位寄存器总是比存储寄存器早一个脉冲。移位寄存器有...

相似回答