Knight rider LED effect
Demonstration of connecting the 74HC595 8-bit shift register to the MSP430 Launchpad.
Simple Knight rider back and forth flashing LED's.
// MSP430G2231
// shift reg. 74hc595 test ... Knight Rider back/forth flashing
#include <msp430x20x2.h>
#include <io.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
static void __inline__delay(register unsigned int n);
void main( void )
{
int i, k = 0x01, j, ud = 1;
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x3f;
P1SEL = 0x00;
while( 1 )
{
if (ud)
{
k = k<<1;
if (k == 0x80 ) ud = 0;
}else
{
k = k>>1;
if( k == 0x01) ud = 1;
}
__inline__delay(0x8ff0);
j = k;
P1OUT &= ~BIT2;
for(i=0; i < 8; i++)
{
P1OUT &= ~BIT1;
if (j & 0x01)
{
P1OUT |= BIT0;
}else{
P1OUT &= ~BIT0;
}
P1OUT |= BIT1;
j = j>>1;
}
P1OUT |= BIT2;
}
}
// 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));
}