Jump to content
43oh

LaunchPad LED Display Booster


Recommended Posts

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Here is a little LED Display Booster pack (a.k.a. Shield) I have created for LaunchPad. It has 2 595's, uses 3 wires to communicate with LP, and supports both, common cathode and common anode display

It's finally here!   See my original post for more pictures and the movie.  

For those who got my boards, here's one example which uses USI in SPI mode to communicate with the board (bit banging can also be used, can post an example if needed.) P1.0, P1.5, and P1.6 have shor

Posted Images

For those who got my boards, here's one example which uses USI in SPI mode to communicate with the board (bit banging can also be used, can post an example if needed.)

P1.0, P1.5, and P1.6 have shorting blocks.

 

#include 

unsigned int counter = 0;                   // Counter variable
unsigned int digitCounter = 0;				// Digit counter
unsigned char digit = 0;					// Single digit to be displayed
unsigned char bcd7digit[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // BCD to 7 digit map
unsigned char digitSelector[4] = {0x08, 0x04, 0x02, 0x01}; // Digit selector map

void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

 P1OUT |= 0x01; 							// Port P1.0 will be used to latch
 P1DIR |= 0x01;

 USICTL0 |= USIPE6 + USIPE5 + USIMST + USIOE; // Out & clk enable, SPI Master
 USICTL1 |= USICKPH + USIIE;               // Counter interrupt, flag remains set
 USICKCTL = USIDIV_7 + USISSEL_2;          // /128 SMCLK
 USICTL0 &= ~USISWRST;                     // USI released for operation
 USICNT = USI16B;                     		// Enable 16 bit

 CCTL0 = CCIE;                             // CCR0 interrupt enabled
 CCR0 = 500;								// 
 TACTL = TASSEL_2 + MC_1 + ID_3;           // SMCLK, upmode

 _bis_SR_register(LPM0_bits + GIE);        // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{	
 digitCounter++;        					// Increase digit counter
 digitCounter &= 0x03; 					// Mask, counter range is 0-3
 digit = counter>>(4 * digitCounter); 		// Shift digits right
 digit &= 0x0F; 							// Mask, we need first digit only
 USISRL = bcd7digit[digit]; 				// Get segments from the map
 USISRH = digitSelector[digitCounter]; 	// 
 if(digitCounter == 0) {
 	counter = _bcd_add_short(counter, 0x01);// Decimally increase counter's when on first digit
 }
 USICNT |= 16;                           	// Start USI
}

// USI interrupt service routine
#pragma vector = USI_VECTOR
__interrupt void USI_TXRX (void)
{
 USICTL1 &= ~USIIFG;               		// Clear pending flag
 P1OUT &= ~0x01;							// Latch data
 P1OUT |= 0x01;
}

Link to post
Share on other sites

Here's an example that works on 2553 and 2231, it displays raw ADC.

 

#include 

#define DATAPIN BIT6
#define CLOCKPIN BIT5
#define LATCHPIN BIT0

unsigned int txCounter = 0;                   // Counter variable
unsigned char txData = 0;
unsigned int digitCounter = 0;				// Digit counter
unsigned int adcCounter = 0;
unsigned const char bcd7digit[10] = {
                                       0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F
                                   }
                                   ; // BCD to 7 digit map
unsigned const char digitSelector[4] = {
                                          0x01, 0x02, 0x04, 0x08
                                      }
                                      ; // Digit selector map
unsigned char data[4] = {0,0,0,0};

void binaryToUnpackedBCD(unsigned int n, unsigned char * digits);

void main(void) {

   WDTCTL = WDTPW + WDTHOLD;			// disable WDT
   BCSCTL1 = CALBC1_1MHZ;				// 1MHz clock
   DCOCTL = CALDCO_1MHZ;

   P1OUT |= LATCHPIN;
   P1DIR |= LATCHPIN + CLOCKPIN + DATAPIN;

   CCR0 = 2000;
   TACTL = TASSEL_2 + MC_1;			// SMCLK, upmode
   CCTL0 = CCIE;

   ADC10CTL1 = INCH_4;
   ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE;

   __bis_SR_register(GIE);				// enable global

   while(1) {							// main loop

       txData = digitSelector[digitCounter];
       txCounter = 0;

       while(txCounter < 8) {
           (txData & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN);
           txData <<= 1;
           P1OUT |= CLOCKPIN;
           P1OUT &= ~CLOCKPIN;
           txCounter++;
       }

       txData = bcd7digit[data[digitCounter]];
       txCounter = 0;

       while(txCounter < 8) {
           (txData & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN);
           txData <<= 1;
           P1OUT |= CLOCKPIN;
           P1OUT &= ~CLOCKPIN;
           txCounter++;
       }

       P1OUT &= ~LATCHPIN;                     // Latch data
       P1OUT |= LATCHPIN;

       __bis_SR_register(LPM0_bits);	// go to sleep and wait for the timer
   }
}

// Timer A0 interrupt service routine
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void) {
   digitCounter++;        					// Increase digit counter
   digitCounter &= 0x03; 
   adcCounter++;				// Mask, counter range is 0-3
   if(adcCounter == 100) {
       ADC10CTL0 |= ENC + ADC10SC;
       adcCounter = 0;
   }
   __bic_SR_register_on_exit(LPM0_bits);
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {

   binaryToUnpackedBCD(ADC10MEM, data);
}

void binaryToUnpackedBCD(unsigned int n, unsigned char * digits) {
   __asm(" clr      R14");
   __asm(" rla      R12");
   __asm(" rla      R12");
   __asm(" rla      R12");
   __asm(" rla      R12");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" rla      R12");
   __asm(" dadd   R14, R14");
   __asm(" mov.b   R14, 3(R13)");
   __asm(" swpb   R14");
   __asm(" mov.b   R14, 1(R13)");
   __asm(" rra      R14");
   __asm(" rra      R14");
   __asm(" rra      R14");
   __asm(" rra      R14");
   __asm(" mov.b   R14, 0(R13)");
   __asm(" swpb   R14");
   __asm(" mov.b   R14, 2(R13)");
   __asm(" and      #0x0F0F, 0(R13)");
   __asm(" and      #0x0F0F, 2(R13)");
   return;
}

Link to post
Share on other sites
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...