home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_03 / 9n03064a < prev    next >
Text File  |  1991-01-17  |  2KB  |  55 lines

  1. /* Modulename:  io.c
  2.  *
  3.  * Description: This module contains routines 
  4.  *        for the serial I/O interface and 
  5.  *        timers of the 8052.
  6.  *        Compiler option : -C51
  7.  */
  8.  
  9. #ifndef _CC51
  10. #include "reg51.h"
  11. #endif
  12. #include "clock.h"
  13.  
  14. /*    function prototypes     */
  15.  
  16. void out_char( char );
  17. void reset_serial( void );
  18. void init_timer( void );
  19.  
  20. void
  21. out_char( char c )
  22. {
  23.     while ( !TI )  /* Output port ready? */
  24.            ;       /* No: keep looping   */
  25.     TI = 0;         /* Reset flag        */
  26.     SBUF = c;       /* Put character     */
  27. }
  28.  
  29. void
  30. reset_serial( void )
  31. {
  32.     RI   = 0;       /* clear receive and transmit 
  33.                        interrupt flag  */
  34.     TI   = 0;       
  35.     TH1  = 0xFD;    /* Initialize serial port: */
  36.     SCON = 0xDA;    /*    9600 baud, 8 bits  */
  37.                     /*    no parity, 1 start bit, */
  38.                     /*    2 stop bits             */
  39.                /* Cristal frequency: 11.0592 Mhz. */
  40. }
  41. void
  42. init_timer( void )
  43. {
  44.  
  45.     TR1  = 1;     /* set timer 1 in run mode           */
  46.     TMOD = 0x21;  /* timer 1 in 8 bit auto reload mode,*/
  47.                   /* timer 0 in 16 bit timer mode      */
  48.     TL0  = ( TIME_FACTOR % 256 );
  49.     TH0  = ( TIME_FACTOR / 256 );
  50.     PT0  = 1;  /* timer 0 at interrupt priority level 0 */
  51.     ET0  = 1;  /* enable timer 0 overflow interrupt     */
  52.     EA   = 1;  /* enable all interrupts                 */
  53.     TR0  = 1;  /* set timer 0 in run mode               */
  54. }
  55.