Electronics Lab Philippines

74HC595 Shift Register by TI Launchpad/MSP430

Offline zrehtiek/keitherz

  • *******
  • 772
  • 45
  • Gender: Male
  • PhilRoboKit Anito
74HC595 Shift Register by TI Launchpad/MSP430
« on: September 09, 2011, 10:34:55 PM »
Demos:
74HC595 Launchpad

Basic 8-bit shift register demos.

Offline Mayor Johnaray

  • **
  • 2274
  • 247
Re: 74HC595 Shift Register by TI Launchpad/MSP430
« Reply #1 on: September 09, 2011, 10:52:47 PM »
Any schematic?
Souce code etc.?

Care to share it with NEWBIES like me? ;D ;D ;D

Offline zrehtiek/keitherz

  • *******
  • 772
  • 45
  • Gender: Male
  • PhilRoboKit Anito
Re: 74HC595 Shift Register by TI Launchpad/MSP430
« Reply #2 on: September 09, 2011, 10:56:24 PM »
Microprocessor used: msp430g2231/msp430g2211

main.c (ONLY ONE define must be used):
Code: [Select]

#include "msp430g2231.h"

//#define DEMO1 1
//#define DEMO1 2
//#define DEMO2 1
//#define DEMO2 2
#define DEMO3
//#define DEMO4

#if DEMO1 == 1
unsigned serData = 0x80;
#elif DEMO1 == 2
unsigned serData = 0x02;
#else
unsigned serData = 0x00;
#endif

#ifdef DEMO4
unsigned char y = 0x00;
unsigned char x[11] = {0xEE,0x82,0xDC,0xD6,0xB2,0x76,0x7E,0xC2,0xFE,0xF6,0x01};
#endif

void shiftData(void);
void shiftOutInit(void);

void main(void) {
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0x07;
P1OUT = 0x00;

shiftOutInit();

while(1) {
shiftData();
__delay_cycles(0xFFFF);
__delay_cycles(0xFFFF);
}
}

void shiftData(void) {
#if DEMO1 == 1
switch(serData) {
default:
serData = serData >> 1;
break;
case 0x20:
serData = serData >> 2;
break;
case 0x02:
serData = 0x80;
break;

}

#elif DEMO1 == 2
switch(serData) {
default:
serData = serData << 1;
break;
case 0x08:
serData = serData << 2;
break;
case 0x80:
serData = 0x02;
break;
}
#elif defined DEMO2
serData = serData << 1;
#if DEMO2 == 1
if(!(0x08 & P1IN)) serData |= 0x01;
#elif DEMO2 == 2
if(!(0x08 & P1IN)) serData |= 0x02;
#endif

#elif defined DEMO3
switch(serData) {
case 0xFF:
serData = 0x00;
break;
default:
serData++;
break;
}

#elif defined DEMO4
switch(y) {
case 0x0A:
y = 0x00;
break;
default:
y++;
break;
}
serData = x[y];
#endif
}

shiftOut.asm
Code: [Select]

.cdecls C, LIST, "msp430g2231.h"

.text
.global shiftOutInit
.global serData

shiftOutInit:
        mov     #0x0FFF, &TACCR0
        mov     #0x0EFF, &TACCR1
        mov     #TASSEL_2+MC_1, &TACTL
        mov     #OUTMOD_3, &TACCTL1
        bis     #CCIE, &TACCTL0
        eint
        ret

shiftOutISR:
push R11
push R12
add #serData, R12
mov @R12, R12
bic #0x02, &P1OUT
mov #0x08, R11

shiftOutLoop:
and R12, &0x01
jnz dataHigh

dataLow:
bic #0x01, &P1OUT
jmp shiftData
dataHigh:
bis #0x01, &P1OUT

shiftData:
rra R12

pulseDataCLK:
bis #0x04, &P1OUT
bic #0x04, &P1OUT

dec R11
jnz shiftOutLoop

bis #0x02, &P1OUT

pop R11
pop R12
reti

        .sect   ".int09"
        .short  shiftOutISR

.end

pinout:
P1.0(launchpad)->pin14(74HC595)
P1.1(launchpad)->pin12(74HC595)
P1.2(launchpad)->pin11(74HC595)

pin15 + pin1-7(74HC595)->LEDs
pin10(74HC595)->VCC
pin13(74HC595)->GND

COMING SOON: CASCADED SHIFT REGISTERS + LED MATRIX ARRAY

Offline zrehtiek/keitherz

  • *******
  • 772
  • 45
  • Gender: Male
  • PhilRoboKit Anito

Offline zrehtiek/keitherz

  • *******
  • 772
  • 45
  • Gender: Male
  • PhilRoboKit Anito
Re: 74HC595 Shift Register by TI Launchpad/MSP430
« Reply #4 on: September 10, 2011, 09:30:07 PM »
Any schematic?
Souce code etc.?

Care to share it with NEWBIES like me? ;D ;D ;D

hindi ka naman NEWBIE e ;D :D

Offline kaizer

  • ****
  • 4885
  • 227
Re: 74HC595 Shift Register by TI Launchpad/MSP430
« Reply #5 on: September 10, 2011, 09:58:25 PM »
takte,, hanap ako ng hanap ng shift routine, andun pala sa shiftout.asm..

akala ko equivalent to assembly yugn nasa baba nyahahah kaya pala parang kulang :D


-- ate zhrek... ginawa mo rin yung sa asm?

Offline zrehtiek/keitherz

  • *******
  • 772
  • 45
  • Gender: Male
  • PhilRoboKit Anito
Re: 74HC595 Shift Register by TI Launchpad/MSP430
« Reply #6 on: September 10, 2011, 10:27:28 PM »
oo sis, para mas efficient. :D
(sorry sa mga tabs/indentations sa mga code. nagbabago pag paste)

Offline zrehtiek/keitherz

  • *******
  • 772
  • 45
  • Gender: Male
  • PhilRoboKit Anito
Re: 74HC595 Shift Register by TI Launchpad/MSP430
« Reply #7 on: September 23, 2011, 08:31:02 PM »
UPDATE:

New code:
Same demos BUT no more BIT BANGING!
Now using the Universal Serial Interface (USI) peripheral!

Code: [Select]
#include <msp430g2231.h>

//#define DEMO1 1
//#define DEMO1 2
//#define DEMO2 1
//#define DEMO2 2
#define DEMO3
//#define DEMO4

#if DEMO1 == 1
unsigned serData = 0x80;
#elif DEMO1 == 2
unsigned serData = 0x02;
#else
unsigned serData = 0x00;
#endif

#ifdef DEMO4
unsigned char y = 0x00;
unsigned char x[11] = {0xEE,0x82,0xDC,0xD6,0xB2,0x76,0x7E,0xC2,0xFE,0xF6,0x01};
#endif

void shiftData(void);

int main(void) {
WDTCTL = WDTPW + WDTHOLD;

P1DIR |= BIT0;
P1OUT |= BIT0;

USICTL0 |= USIPE6 + USIPE5 + USILSB + USIMST + USIOE;
USICTL1 |= USICKPH + USIIE;
USICKCTL = USIDIV_0 + USISSEL_2;
USICTL0 &= ~USISWRST;
USICNT = 8;

TACCR0 = 64;
TACTL = TASSEL_2 + MC_1;
TACCTL0 = CCIE;

_bis_SR_register(GIE);
while(1) {
shiftData();
__delay_cycles(0x7FFF);
}
}

void shiftData(void) {
#if DEMO1 == 1
switch(serData) {
default:
serData = serData >> 1;
break;
case 0x20:
serData = serData >> 2;
break;
case 0x02:
serData = 0x80;
break;

}

#elif DEMO1 == 2
switch(serData) {
default:
serData = serData << 1;
break;
case 0x08:
serData = serData << 2;
break;
case 0x80:
serData = 0x02;
break;
}
#elif defined DEMO2
serData = serData << 1;
#if DEMO2 == 1
if(!(0x08 & P1IN)) serData |= 0x01;
#elif DEMO2 == 2
if(!(0x08 & P1IN)) serData |= 0x02;
#endif

#elif defined DEMO3
switch(serData) {
case 0xFF:
serData = 0x00;
break;
default:
serData++;
break;
}

#elif defined DEMO4
switch(y) {
case 0x0A:
y = 0x00;
break;
default:
y++;
break;
}
serData = x[y];
#endif
}

#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A(void) {
USISR = serData;
USICNT |= 8;
}

#pragma vector = USI_VECTOR
__interrupt void USI_TXRX(void) {
USICTL1 &= ~USIIFG;
P1OUT &= ~BIT0;
P1OUT |= BIT0;
}

again, ONLY ONE DEFINE must be used at a time.

pinout:
P1.0(launchpad)->pin12(74HC595)
P1.5(launchpad)->pin11(74HC595)
P1.6(launchpad)->pin14(74HC595)

pin15 + pin1-7(74HC595)->LEDs
pin10(74HC595)->VCC
pin13(74HC595)->GND

(Wala parin yung LED matrix, sorry. Walang kwarta. :D)