/* No responsibility whatsoever. Free for everything. Simple serial data exchange with 74hc273 through P1.4(data)& P1.5(clock). Send/update streeng "0.014r" to/on '7-segment x 5' screen. See skootsone.yolasite.com/msp430-7segment for schematic diagramm. */ #include const int buffer_line_to_leds [5] = {0xc07f,0x40bf,0xf9df,0x99ef,0xAFf7}; // "0.014r" on the screen. Firsf byte - image, second - position void push_16bit_to_display (int); //Subprogram to push 16 bit to 74hc273 (one car.+position) via 'data' & 'clock' lines int bit, position_on_screen; int main(void) { // Set int. clock to 8 MHz to prevent flicker BCSCTL1 = CALBC1_8MHZ; // Set pre-calibrated 'range' for 8MHz DCOCTL = CALDCO_8MHZ; // Set pre-calibrated 'DCO step + modulation' for 8MHz WDTCTL = WDT_MDLY_8; //Set WDT as interrupt source (8ms/8(MHz)=1ms or 1000/sec. IE1 |= WDTIE; // Enable WDT interrupt P1DIR |= 0x30; // Set P1.4,5 to output direction __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt return 0; } // Next, executed every time when interrupt occurred. 8msec==125 time per sec. At 8 MHz => 1000 times per sec. #pragma vector=WDT_VECTOR __interrupt void watchdog_timer(void) { push_16bit_to_display (buffer_line_to_leds [position_on_screen]); //Call to subprogram. position_on_screen++; //upd. position for the next call if(position_on_screen == 5) position_on_screen=0; //if pos. is 5 (all showed) - start from 0 } void push_16bit_to_display (int Data) { for (bit = 0; bit < 16; bit++) // Loop 16 bits to write to 74hc273 { P1OUT = 0x00; // Set 'data' (P1.4) 'low' if((Data >> bit) & 0x01) P1OUT |= 0x10; // If ==1 then 'data' (P1.4) bit is a 'hi' P1OUT |= BIT5; // Set 'clock' (P1.5) 'hi' P1OUT &= ~BIT5; // Set 'clock' (P1.5) 'low' }}