Page 294 - Programming Microcontrollers in C
P. 294

Timer Operations    279

                          This sequence repeats each half second until in_process is set to
                          TRUE. Whenever a character is read in through the serial port,
                          in_process is set to TRUE to disable the continual output from
                          the system while a new input speed value is being entered. If there is
                          a new character in the input buffer, this character is read in and the
                          RDRF flag is reset. The new character is immediately echoed back to
                          the sending device as part of full duplex operation. If the new character
                          is a digit it is processed, if it is a line feed it is also processed, and any
                          number string is converted to an integer so that it can be used by the
                          computer. The size of the number is tested to be certain that it is
                          within the acceptable speed limits for the motor, and if it passes all
                          of the tests, it is placed in the variable location motor_speed to
                          indicate that a new motor speed is here and should be processed.

                   #include “hc11e9.h”


                   #define DIVIDE_8_SHIFT                     3
                   #define COUNT_8                            8
                   #define COUNT_MAX                          3300
                   #define COUNT_MIN                          1600
                   #define COUNT_ONE_QUARTER                  32
                   #define COUNT_ONE_SECOND                   128
                   #define PERIOD                             0X1000
                   #define TIME_ON                            0x0800
                   #define IMPOSSIBLE                         3500
                   #define TOO_LOW                            100
                   #define RPM_MIN                            1000
                   #define RPM_MAX                            11000
                   #define CR                                 0x0d
                   #define LF                                 0x0a


                   /*function prototypes */
                   @port void IC1_Isr(void);
                   @port void OC2_Isr(void);
                   @port void OC3_Isr(void);
                   int putchar(char new_character);
                   void dprint (unsigned int c);
                   void do_crlf(void);
                   long limit(long );
   289   290   291   292   293   294   295   296   297   298   299