home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / UTSPKON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  2.0 KB  |  69 lines

  1. /**
  2. *
  3. * Name        utspkon -- Turn on the speaker
  4. *
  5. * Synopsis    utspkon(freq);
  6. *
  7. *        unsigned freq      The frequency of the sound wave to
  8. *                  produce.
  9. *
  10. * Description    This function turns the speaker on so that it produces a
  11. *        sound wave with a specified frequency.    The resulting
  12. *        sound is produced until UTSPKOFF is called or until
  13. *        another call is made to UTSPKON.
  14. *
  15. * Method    The 8253 Programmable Interrupt Timer expects a "latch
  16. *        register value" which when multiplied by the wave
  17. *        frequency is the clock frequency, 1.19318 Mhz.    The
  18. *        latch value is computed and the 8253 is programmed
  19. *        accordingly.
  20. *
  21. * Returns    (None.    Function return type is void.)
  22. *
  23. * Version    3.0 (C)Copyright Blaise Computing Inc. 1984, 1986
  24. *
  25. * Version    3.02 March 24, 1987
  26. *        Removed a strong typing warning (no change in object
  27. *            code).
  28. *
  29. **/
  30.  
  31. #include <butility.h>
  32.  
  33. #if LAT300
  34. #include <dos.h>              /* Declare inp() and outp().    */
  35. #endif
  36. #if MSC300
  37. #include <conio.h>              /* Declare inp() and outp().    */
  38. #endif
  39.  
  40.                       /* The following are hardware   */
  41.                       /* port addresses needed to ac- */
  42.                       /* cess the 8255 (speaker) and  */
  43.                       /* 8253 (timer) chips.          */
  44.  
  45. #define PB8255      0x61              /* Port B of the 8255 chip      */
  46.  
  47. #define LTC8253   0x42              /* Latch register 8253 (timer)  */
  48. #define CMD8253   0x43              /* Command register of 8253     */
  49.  
  50. #define CLKFREQ   1193180L
  51.  
  52. void utspkon(freq)
  53. unsigned freq;
  54. {
  55.     unsigned latch;
  56.  
  57.     outp(PB8255,inp(PB8255) | 3);     /* Enable speaker data and      */
  58.                       /* timer gate signals on PortB. */
  59.  
  60.    /* Now program channel 2 of the 8253 timer to generate a square    */
  61.    /* wave of frequency "freq" Hz.                                    */
  62.  
  63.     outp(CMD8253,0x0b6);
  64.     latch = (unsigned) (CLKFREQ/freq);/* The value to place in the    */
  65.     outp(LTC8253,utlobyte(latch));    /* latch register.  The least   */
  66.     outp(LTC8253,uthibyte(latch));    /* significant byte followed by */
  67.                       /* the most significant byte.   */
  68. }
  69.