Page 298 - Programming Microcontrollers in C
P. 298

Timer Operations    283

                       while(SCSR.TDRE==OFF);
                       SCDR=CR;
                       while(SCSR.TDRE==OFF);
                       SCDR=LF;
                   }


                   /* send a single character to the serial port */

                   int putchar(char new_character)
                   {
                       while(SCSR.TDRE==OFF);
                   /* wait until transmit buffer empty */
                       SCDR=new_character;
                   /* send out byte and reset TDRE */
                   }


                   /* convert an integer and send it to the serial
                       port as a string */

                   void dprint (unsigned int c)
                   {
                   if ( c/10) /* recursively determines if */
                    dprint(c/10); /* a zero has been reached and then */
                   putchar(c%10+’0'); /* sends out the characters */
                   }


                   /* The asynchronous service portion of the program */

                   @port void IC1_Isr( void)/*the motor speed
                                                        measurement*/
                   {
                       static int i;
                       int j;
                       time2=TIC1;
                       TFLG1=IC1F; /* reset IC1 interrupt flag */
                       mparray[i]=time2-time1;
                       if (++i==COUNT_8)
                       {
                          i=0;
   293   294   295   296   297   298   299   300   301   302   303