nexusone1984 32 Posted July 8, 2011 Share Posted July 8, 2011 Been busy with a lot of other stuff... but after a little time here and there put together a 4x4x4 LED Cube. Soldering the LED's took me forever.... I used Common Cathode configuration for the LED's, this way logic 1 turns on the LED. and Logic 1 also turns on a Row transistor. Simple little demo. Parts: Launchpad board, 3 x 74HC595 8-bit shift registers, 4 x 2N3904 NPN transistors, 64 Yellow LED's. nuetron, xpg, EngIP and 3 others 6 Quote Link to post Share on other sites
bluehash 1,581 Posted July 9, 2011 Share Posted July 9, 2011 Nice! Was wondering where you went. Good video. Now make it better with an RGB Quote Link to post Share on other sites
nexusone1984 32 Posted July 9, 2011 Author Share Posted July 9, 2011 Thanks I am still here, Summer Vacation, etc.. works been crazy.... I get times where I have more free time then others. Still have a list of stuff on the MSP430 to make. Nice! Was wondering where you went. Good video. Now make it better with an RGB Quote Link to post Share on other sites
nuetron 64 Posted July 9, 2011 Share Posted July 9, 2011 Now make it better with an RGB I second the motion! Quote Link to post Share on other sites
Theshadowwalker91 0 Posted August 25, 2011 Share Posted August 25, 2011 hello. good job on the cube. i was wondering when/if you are going to put the code up for this project. i have built a 4x4x4 cube with an arduino but it cost to much to make it worth keeping. i have been wanting to make one with the msp430 because they only cost 5 bucks so i dont mind putting one together for good. Quote Link to post Share on other sites
Theshadowwalker91 0 Posted November 18, 2011 Share Posted November 18, 2011 hello again. i notice that the code was posted on a link. but it is for linux based software. is there anyone that can make this code work with CCS. // MSP430G2231 4X4X4 Matrix Cube code // uses three 74hc595 shift registers #include #include #include #include #include void Initializeports(void); static void __inline__delay(register unsigned int n); int binary2bcd16( unsigned char *bcd, int t ); // 16bit int display_led(int t, int display); void display_refresh( void ); // Time function varibles volatile unsigned char days = 0, hours = 0, minutes = 0, seconds = 0, e_hours = 0, e_minutes = 0, e_seconds = 0; volatile unsigned int milliseconds = 0, milliseconds_t = 0; // Display buffer/control volatile int display_buffer[8]; volatile int display_ctl[8]; volatile int display_blink = 0; volatile int display_blink_rate; volatile int display_position; // Switch, mode control char d_mode = 0, e_mode = 0, d_mode_digit = 0, switch1, switch2; unsigned int switch1_dt, switch2_dt; char scroll[48] = {"MSP430 Launchpad....--->Hello Yuri...Alex<--...."}; void main(void) { int i, t, l; unsigned char digit[5], alt_digit = 0; WDTCTL = WDTPW + WDTHOLD; // Stop WDT //1Mhz BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */ CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 1000; TACTL = TASSEL_2 + MC_2; // SMCLK, contmode Initializeports(); _EINT(); /* Main Application Loop */ while(1) { display_buffer[0] = 0x0000; display_buffer[1] = 0xffff; display_buffer[2] = 0xffff; display_buffer[3] = 0xffff; for(t=0; t<80; t++) { l = display_buffer[3]; display_buffer[3] = display_buffer[2]; display_buffer[2] = display_buffer[1]; display_buffer[1] = display_buffer[0]; display_buffer[0] = l; for(i=0;i<600;i++) __inline__delay(25); } for(t=0; t<20; t++) { display_buffer[0] = 0x0000; display_buffer[1] = 0x0000; display_buffer[2] = 0x0000; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __inline__delay(100); display_buffer[0] = 0xffff; display_buffer[1] = 0x0000; display_buffer[2] = 0x0000; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __inline__delay(100); display_buffer[0] = 0xffff; display_buffer[1] = 0xffff; display_buffer[2] = 0x0000; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __inline__delay(100); display_buffer[0] = 0xffff; display_buffer[1] = 0xffff; display_buffer[2] = 0xffff; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __inline__delay(100); display_buffer[0] = 0xffff; display_buffer[1] = 0xffff; display_buffer[2] = 0xffff; display_buffer[3] = 0xffff; for(i=0;i<1200;i++) __inline__delay(100); } for(l=0;l<20;l++) { display_buffer[t] = 0x000f; for(i=0;i<4;i++) { display_buffer[0] = (display_buffer[0]<<4) | 0x00f; display_buffer[1] = display_buffer[0]; display_buffer[2] = display_buffer[0]; display_buffer[3] = display_buffer[0]; __inline__delay(20000); } for(t=0;t<4;t++) { for(i=0;i<17;i++) { display_buffer[t] = (display_buffer[t]<<1) & 0xfff7; __inline__delay(5000); } } } } } int binary2bcd16( unsigned char *bcd, int t ) // 16bit to BCD conversion { int i; while( i < 5) { bcd[i] = 0; i++; } if ( t > 9999 ) bcd[4] = t / 10000; if ( t > 999 ) bcd[3] = t / 1000 - bcd[4] * 10; if ( t > 99 ) bcd[2] = t / 100 - (bcd[3] * 10 + bcd[4] * 100); if ( t > 9 ) bcd[1] = t / 10 - (bcd[2] * 10 + bcd[3] * 100 + bcd[4] * 1000); bcd[0] = t - (bcd[1] * 10 + bcd[2] * 100 + bcd[3] * 1000 + bcd[4] * 10000); } // Display void display_refresh( void ) { int d; if ( (display_ctl[display_position] == 0x01) && (display_blink == 0x01)) { d = 16; }else{ d = display_buffer[display_position]; } display_led( d, display_position); display_position++; if (display_position > 3) display_position = 0; } // Serial out of LED data to 74HC595 int display_led(int t, int display) { int j, i, mask; mask = (0x1000< j = t; P1OUT &= ~BIT2; for(i=0; i < 4; i++) { P1OUT &= ~BIT1; if (mask & 0x8000) { P1OUT |= BIT0; }else{ P1OUT &= ~BIT0; } P1OUT |= BIT1; mask = mask<<1; } for(i=0; i < 16; i++) { P1OUT &= ~BIT1; if (j & 0x8000) { P1OUT |= BIT0; }else{ P1OUT &= ~BIT0; } P1OUT |= BIT1; j = j<<1; } P1OUT |= BIT2; } // setup ports void Initializeports(void) { int i = 0; P1DIR |= 0x07; P1SEL = 0x00; P1OUT = 0x18; // P1.4 set, else reset P1REN |= 0x18; while( i < 8 ) { display_buffer[i] = 0; display_ctl[i] = 0; i++; } } // Delay Routine from mspgcc help file static void __inline__delay(register unsigned int n) { __asm__ __volatile__ ( "1: \n" " dec %[n] \n" " jne 1b \n" : [n] "+r"(n)); } // Time keeping routine interrupt(TIMERA0_VECTOR) Timer_A (void) { milliseconds++; milliseconds_t++; if (milliseconds > 999) { seconds++; milliseconds = 0; } if (milliseconds_t > 59999) { milliseconds_t = 0; } if ( 0x10 & ~P1IN) { switch1_dt++; }else{ switch1_dt = 0; } if ( 0x08 & ~P1IN) { switch2_dt++; }else{ switch2_dt = 0; } if (seconds > 59) { minutes++; seconds = 0; } if (minutes > 59 ) { hours++; minutes = 0; } if (hours > 23) { hours = 0; days++; } display_blink_rate++; if (display_blink_rate > 250) // LED Blink rate { display_blink = (~display_blink) & 0x01; display_blink_rate = 0; } display_refresh( ); CCR0 += 999; } Quote Link to post Share on other sites
gwdeveloper 275 Posted November 19, 2011 Share Posted November 19, 2011 Did you attempt to compile it and get the list of errors? There's only a few things that need changing... I hope Nexusone doesn't mind but since I wanted to test this code for myself too, here it is in CCS... // MSP430G2231 4X4X4 Matrix Cube code // uses three 74hc595 shift registers #include #include #include void Initializeports(void); void binary2bcd16( unsigned char *bcd, int t ); // 16bit void display_led(int t, int display); void display_refresh( void ); // Time function varibles volatile unsigned char days = 0, hours = 0, minutes = 0, seconds = 0, e_hours = 0, e_minutes = 0, e_seconds = 0; volatile unsigned int milliseconds = 0, milliseconds_t = 0; // Display buffer/control volatile int display_buffer[8]; volatile int display_ctl[8]; volatile int display_blink = 0; volatile int display_blink_rate; volatile int display_position; // Switch, mode control char d_mode = 0, e_mode = 0, d_mode_digit = 0, switch1, switch2; unsigned int switch1_dt, switch2_dt; char scroll[48] = {"MSP430 Launchpad....--->Hello Yuri...Alex<--...."}; int i, t, l; unsigned char digit[5], alt_digit = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT //1Mhz BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */ CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 1000; TACTL = TASSEL_2 + MC_2; // SMCLK, contmode Initializeports(); _EINT(); /* Main Application Loop */ while(1) { display_buffer[0] = 0x0000; display_buffer[1] = 0xffff; display_buffer[2] = 0xffff; display_buffer[3] = 0xffff; for(t=0; t<80; t++) { l = display_buffer[3]; display_buffer[3] = display_buffer[2]; display_buffer[2] = display_buffer[1]; display_buffer[1] = display_buffer[0]; display_buffer[0] = l; for(i=0;i<600;i++) __delay_cycles(25); } for(t=0; t<20; t++) { display_buffer[0] = 0x0000; display_buffer[1] = 0x0000; display_buffer[2] = 0x0000; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __delay_cycles(100); display_buffer[0] = 0xffff; display_buffer[1] = 0x0000; display_buffer[2] = 0x0000; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __delay_cycles(100); display_buffer[0] = 0xffff; display_buffer[1] = 0xffff; display_buffer[2] = 0x0000; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __delay_cycles(100); display_buffer[0] = 0xffff; display_buffer[1] = 0xffff; display_buffer[2] = 0xffff; display_buffer[3] = 0x0000; for(i=0;i<1200;i++) __delay_cycles(100); display_buffer[0] = 0xffff; display_buffer[1] = 0xffff; display_buffer[2] = 0xffff; display_buffer[3] = 0xffff; for(i=0;i<1200;i++) __delay_cycles(100); } for(l=0;l<20;l++) { display_buffer[t] = 0x000f; for(i=0;i<4;i++) { display_buffer[0] = (display_buffer[0]<<4) | 0x00f; display_buffer[1] = display_buffer[0]; display_buffer[2] = display_buffer[0]; display_buffer[3] = display_buffer[0]; __delay_cycles(20000); } for(t=0;t<4;t++) { for(i=0;i<17;i++) { display_buffer[t] = (display_buffer[t]<<1) & 0xfff7; __delay_cycles(5000); } } } } } void binary2bcd16( unsigned char *bcd, int t ) // 16bit to BCD conversion { int i = 0; while( i < 5) { bcd[i] = 0; i++; } if ( t > 9999 ) bcd[4] = t / 10000; if ( t > 999 ) bcd[3] = t / 1000 - bcd[4] * 10; if ( t > 99 ) bcd[2] = t / 100 - (bcd[3] * 10 + bcd[4] * 100); if ( t > 9 ) bcd[1] = t / 10 - (bcd[2] * 10 + bcd[3] * 100 + bcd[4] * 1000); bcd[0] = t - (bcd[1] * 10 + bcd[2] * 100 + bcd[3] * 1000 + bcd[4] * 10000); } // Display void display_refresh( void ) { int d; if ( (display_ctl[display_position] == 0x01) && (display_blink == 0x01)) { d = 16; }else{ d = display_buffer[display_position]; } display_led( d, display_position); display_position++; if (display_position > 3) display_position = 0; } // Serial out of LED data to 74HC595 void display_led(int t, int display) { int j, i, mask; mask = (0x1000< j = t; P1OUT &= ~BIT2; for(i=0; i < 4; i++) { P1OUT &= ~BIT1; if (mask & 0x8000) { P1OUT |= BIT0; }else{ P1OUT &= ~BIT0; } P1OUT |= BIT1; mask = mask<<1; } for(i=0; i < 16; i++) { P1OUT &= ~BIT1; if (j & 0x8000) { P1OUT |= BIT0; }else{ P1OUT &= ~BIT0; } P1OUT |= BIT1; j = j<<1; } P1OUT |= BIT2; } // setup ports void Initializeports(void) { int i = 0; P1DIR |= 0x07; P1SEL = 0x00; P1OUT = 0x18; // P1.4 set, else reset P1REN |= 0x18; while( i < 8 ) { display_buffer[i] = 0; display_ctl[i] = 0; i++; } } // Time keeping routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { milliseconds++; milliseconds_t++; if (milliseconds > 999) { seconds++; milliseconds = 0; } if (milliseconds_t > 59999) { milliseconds_t = 0; } if ( 0x10 & ~P1IN) { switch1_dt++; }else{ switch1_dt = 0; } if ( 0x08 & ~P1IN) { switch2_dt++; }else{ switch2_dt = 0; } if (seconds > 59) { minutes++; seconds = 0; } if (minutes > 59 ) { hours++; minutes = 0; } if (hours > 23) { hours = 0; days++; } display_blink_rate++; if (display_blink_rate > 250) // LED Blink rate { display_blink = (~display_blink) & 0x01; display_blink_rate = 0; } display_refresh( ); CCR0 += 999; } Quote Link to post Share on other sites
Theshadowwalker91 0 Posted November 20, 2011 Share Posted November 20, 2011 i get an error when i try to compile. "../main.c", line 215: error: identifier "TIMERA0_VECTOR" is undefined 1 error detected in the compilation of "../main.c". Quote Link to post Share on other sites
gwdeveloper 275 Posted November 20, 2011 Share Posted November 20, 2011 Which mcu are you using? TIMERA0_VECTOR would be for the G2231 and most others. A G2553 will need that changed to TIMER0_A0_VECTOR. Quote Link to post Share on other sites
Theshadowwalker91 0 Posted November 20, 2011 Share Posted November 20, 2011 i tried both G2231 and G2252 with the G2231 i get the error "../lnk_msp430g2231.cmd", line 56: error: run placement fails for object ".bss", size 0x81 (page 0). Available ranges: RAM size: 0x80 unused: 0x4e max hole: 0x4c error: errors encountered during linking; "newtest.out" not built with the G2252 i get the error "../main.c", line 216: error: identifier "TIMERA0_VECTOR" is undefined 1 error detected in the compilation of "../main.c". Quote Link to post Share on other sites
bluehash 1,581 Posted November 20, 2011 Share Posted November 20, 2011 In the case of the 2231, you have run out of RAM space, If I'm not mistaken, by one byte. For the second one, rename to TIMER0_A0_VECTOR Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.