#include const int dec_digit_to_7_seg_led [10] = {0x03,0x9f,0x25,0x0d,0x99,0x49,0xc1,0x1f,0x01,0x19}; int buffer_line_to_leds [8] = {0xff80,0xc140,0x2520,0x0d10,0x9908,0x4904,0x4102,0x1f01};// "0.014r" on the screen. Firsf byte - image, second - position int lest_8_inervals_bt_g_pulses [8] = {1000,1000,1000,1000,1000,1000,1000,1000}; void push_16bit_to_display (int); //Subprogram to push 16 bit to 74hc273 (one car.+position) via 'data' & 'clock' lines void update_time_in_buffer(void); void update_inerval_btw_g_pulses(void); int position_on_screen; int ticks_between_pulses, counter_for_time_fill; int ticks_for_clock, count_seconds_for_clock, count_minutes_for_clock=46, count_hours_for_clock=20; int main(void) { // Set int. clock to 8 MHz to prevent flicker BCSCTL1 = CALBC1_1MHZ; // Set pre-calibrated 'range' for 8MHz DCOCTL = CALDCO_1MHZ; // Set pre-calibrated 'DCO step + modulation' for 8MHz WDTCTL = WDT_ADLY_1_9; //Set WDT as interrupt source (8ms/8(MHz)=1ms or 1000/sec. IE1 |= WDTIE; // Enable WDT interrupt P1DIR |= 0x0E; // Set P1.1,2,3 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 == 8) position_on_screen=0; //if pos. is 5 (all showed) - start from 0 ticks_between_pulses++; if(ticks_between_pulses == 2500) update_inerval_btw_g_pulses(); //update current time ticks_for_clock++; if(ticks_for_clock == 491) {count_seconds_for_clock++; ticks_for_clock = 0;} if(count_seconds_for_clock == 60) {count_minutes_for_clock++; count_seconds_for_clock = 0; update_time_in_buffer();} if(count_minutes_for_clock ==60) {count_minutes_for_clock=0; count_hours_for_clock++;} if(count_hours_for_clock == 24) count_hours_for_clock=0; } void push_16bit_to_display (int Data) {int bit_number; for (bit_number = 0; bit_number < 16; bit_number++) // Loop 16 bits to write to 74hc273 {P1OUT = 0x00; // Set 'data' (P1.3) 'low' if((Data >> bit_number) & 0x01) P1OUT |= 0x04; // If ==1 then 'data' (P1.3) bit is a 'hi' P1OUT |= BIT3; P1OUT &= ~BIT3;} // cycle 'clock' (P1.4) 'hi'-'low' P1OUT |= BIT1; P1OUT &= ~BIT1;} // cycle 'push to out' (P1.2) 'hi'-'low' void update_time_in_buffer(void) {int buffer_time_dec, t4; buffer_time_dec = count_hours_for_clock*100 + count_minutes_for_clock; for (t4=4;t4!=0;t4--) { buffer_line_to_leds [t4-1] = ((dec_digit_to_7_seg_led [buffer_time_dec % 10])<<8) + (0x01<<(8-t4)); //buffer_line_to_leds [t4+3] = ((dec_digit_to_7_seg_led [buffer_time_dec % 10])<<8) + (0x01<<(4-t4)); buffer_time_dec = buffer_time_dec / 10; } buffer_line_to_leds[2] = buffer_line_to_leds [2] & 0xFEFF; if((buffer_line_to_leds[0] & 0xFF00) == 0x0300) buffer_line_to_leds [0] = 0xFF00; } void update_inerval_btw_g_pulses(void) { lest_8_inervals_bt_g_pulses [counter_for_time_fill] = ticks_between_pulses; ticks_between_pulses=0; counter_for_time_fill++; if(counter_for_time_fill == 8) counter_for_time_fill=0; }