LaunchPad + 74595 io extender 實作
[复制链接]
74595 很常用在輸出擴充上,當mcu腳位不足時,尤其對430G2231這種LOW PIN COUNT的MCU,很方便因為他是串列介面,MCU和74595之間只用了3支腳位連接,價位上也很便宜"國產的更便宜",再這實例裡74595輸出是接LED,也可接七節管等其他元件 呵呵 總算在時間內發三帖了 期待下次的團購 程序如下 (此程序是從51移植來的) //2012-5-4 74595 串聯擴充3個,程序由keil_c 51移植成的 #include <msp430g2231.h> #define uchar unsigned char #define uint unsigned int #define set_SDATA_595 P1OUT |= 0x08 #define set_SCLK_595 P1OUT |= 0x10 #define set_RCK_595 P1OUT |= 0x20 #define clr_SDATA_595 P1OUT &= 0xf7 #define clr_SCLK_595 P1OUT &= 0xef #define clr_RCK_595 P1OUT &= 0xdf void WR_DATA_595(unsigned char dat1,unsigned char dat2,unsigned char dat3); void delay(int ms) { int k; while(ms--) { for(k=0; k<250; k++) { } } } void WR_595(unsigned char datx) { uchar j; for (j=0;j<8;j++) { // datx=datx<<1 ; // SDATA_595=CY; if ( (datx&0x80) == 0x80 ) set_SDATA_595 ; else clr_SDATA_595 ; datx=datx<<1 ; // SCLK_595=1; //write data to 595 set_SCLK_595; // SCLK_595=0; clr_SCLK_595; } } void OUT_595(void) { // RCK_595=0; clr_RCK_595; // RCK_595=1; //data out to buffer set_RCK_595; // RCK_595=0; clr_RCK_595; } void WR_DATA_595(unsigned char dat1,unsigned char dat2,unsigned char dat3) { WR_595 (dat1) ; WR_595 (dat2) ; WR_595 (dat3) ; OUT_595(); } step_step(void) { WR_DATA_595(0xff,0xff,0x7f); delay(20); WR_DATA_595(0xff,0xff,0xbf); delay(20); WR_DATA_595(0xff,0xff,0xdf); delay(20); WR_DATA_595(0xff,0xff,0xef); delay(20); WR_DATA_595(0xff,0xff,0xf7); delay(20); WR_DATA_595(0xff,0xff,0xfb); delay(20); WR_DATA_595(0xff,0xff,0xfd); delay(20); WR_DATA_595(0xff,0xff,0xfe); delay(20); ///// WR_DATA_595(0xff,0x7f,0xff); delay(20); WR_DATA_595(0xff,0xbf,0xff); delay(20); WR_DATA_595(0xff,0xdf,0xff); delay(20); WR_DATA_595(0xff,0xef,0xff); delay(20); WR_DATA_595(0xff,0xf7,0xff); delay(20); WR_DATA_595(0xff,0xfb,0xff); delay(20); WR_DATA_595(0xff,0xfd,0xff); delay(20); WR_DATA_595(0xff,0xfe,0xff); delay(20); // WR_DATA_595(0x7f,0xff,0xff); delay(20); WR_DATA_595(0xbf,0xff,0xff); delay(20); WR_DATA_595(0xdf,0xff,0xff); delay(20); WR_DATA_595(0xef,0xff,0xff); delay(20); WR_DATA_595(0xf7,0xff,0xff); delay(20); WR_DATA_595(0xfb,0xff,0xff); delay(20); WR_DATA_595(0xfd,0xff,0xff); delay(20); WR_DATA_595(0xfe,0xff,0xff); delay(20); //--------------------------------------- WR_DATA_595(0xfe,0xff,0xff); delay(20); WR_DATA_595(0xfd,0xff,0xff); delay(20); WR_DATA_595(0xfb,0xff,0xff); delay(20); WR_DATA_595(0xf7,0xff,0xff); delay(20); WR_DATA_595(0xef,0xff,0xff); delay(20); WR_DATA_595(0xdf,0xff,0xff); delay(20); WR_DATA_595(0xbf,0xff,0xff); delay(20); WR_DATA_595(0x7f,0xff,0xff); delay(20); WR_DATA_595(0xff,0xfe,0xff); delay(20); WR_DATA_595(0xff,0xfd,0xff); delay(20); WR_DATA_595(0xff,0xfb,0xff); delay(20); WR_DATA_595(0xff,0xf7,0xff); delay(20); WR_DATA_595(0xff,0xef,0xff); delay(20); WR_DATA_595(0xff,0xdf,0xff); delay(20); WR_DATA_595(0xff,0xbf,0xff); delay(20); WR_DATA_595(0xff,0x7f,0xff); delay(20); WR_DATA_595(0xff,0xff,0xfe); delay(20); WR_DATA_595(0xff,0xff,0xfd); delay(20); WR_DATA_595(0xff,0xff,0xfb); delay(20); WR_DATA_595(0xff,0xff,0xf7); delay(20); WR_DATA_595(0xff,0xff,0xef); delay(20); WR_DATA_595(0xff,0xff,0xdf); delay(20); WR_DATA_595(0xff,0xff,0xbf); delay(20); WR_DATA_595(0xff,0xff,0x7f); delay(20); } flash(void) { WR_DATA_595(0x55,0x55,0x55); delay(100); WR_DATA_595(0xaa,0xaa,0xaa); delay(100); WR_DATA_595(0x55,0x55,0x55); delay(100); WR_DATA_595(0xaa,0xaa,0xaa); delay(100); WR_DATA_595(0x55,0x55,0x55); delay(100); WR_DATA_595(0xaa,0xaa,0xaa); delay(100); WR_DATA_595(0x55,0x55,0x55); delay(100); WR_DATA_595(0xaa,0xaa,0xaa); delay(100); WR_DATA_595(0xff,0xff,0xff); delay(100); } main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= 0x38; //P1.3 P1.4 P1.5 all are set output mode // SCLK_595 =0; clr_SCLK_595; //RCK_595 =1; set_RCK_595; WR_DATA_595(0xff,0xff,0xff); //off all led while(1) { flash(); step_step(); step_step(); step_step(); } }