
/* abridged code for doing tachometer with SH-1 */
/* only important parts relevant to setting up the ITU in the SH-1 are displayed */

void tach_init_itu() 
{ /* tach_init_itu */
  /* locals */

  /* body */
  /* using TIOCA3/B3, TCLKA */
  TIOR3 = 0x5D;  /* 0101 1101 */ /* grb, gra capture falling edge */
  TCR3 = 0x2C;  /* 0010 1100 */ /* ext clock A, falling edge, clear on capt */
  TFCR = 0x4F;  /* 0100 1111 */ /* normal mode with buffering on GRA/B */
  TMDR = 0x00;  /* 0000 0000 */
  TSNC = 0x60;  /* timers operate asynchronously */
  TSTR = 0x68;  /* start unit 3 counting */
} /* tach_init_itu */


#define TCLKA_FREQ (19531)    /* in hertz */
#define RPM_MAX  6000

  while(1) {
      for( x = 0; x < 8; x++ ) {
	for( j = 0; j < 128; j++ ) {
	  bitmap[x][j] = 0;
	} /* for */
      } /* for */

      /* calculate rpm */
      ticks = BRA3;
      rpm = (15 * TCLKA_FREQ) / ticks;
      rpm = rpm * 2; /* double RPMs because both edges are ignition */
      rpmsample += rpm;

      if( rpm < 6 ) 
	rpm = 0;   /* handle 0 case */
      /* rpm actually only goes down to like 4 */

      /* figure out graphic position */
      rpmbar = ((rpm * (x2 - x1)) / RPM_MAX) + x1;

      vfd_draw_rect( bitmap, x1, y1, x2, y2 );
      vfd_draw_filled_rect( bitmap, x1, y1, rpmbar, y2 );
      vfd_draw_num( bitmap, xtext, ytext, rpm, BLT_XOR );
      vfd_display_bitmap( bitmap );
  } /* while */
