_outp, _outpw

Description

Outputs a byte (_outp) or a word (_outpw) at a port.

#include <conio.h> Required only for function declarations  

int _outp( unsigned port, int databyte );

unsigned _outpw( unsigned port, unsigned dataword );

port Port number  
databyte Output value  
dataword Output value  

Remarks

The _outp and _outpw functions write a byte and a word, respectively, to the specified output port. The port argument can be any unsigned integer in the range 0 – 65,535; byte can be any integer in the range 0 – 255; and dataword can be any value in the range 0 – 65,535.

Return Value

The functions return the data output. There is no error return.

Compatibility

Standards:None

16-Bit:DOS

32-Bit:None

See Also

_inp, _inpw

Example

/* OUTP.C: This program uses _inp and _outp to make sound of variable tone

* and duration.

*/

#include <conio.h>

#include <stdio.h>

#include <time.h>

void Beep( unsigned duration, unsigned frequency ); /* Prototypes */

void Sleep( clock_t _wait );

void main ( main )

{

Beep( 698, 700 );

Beep( 523, 500 );

}

/* Sounds the speaker for a time specified in microseconds by duration

* at a pitch specified in hertz by frequency.

*/

void Beep( unsigned frequency, unsigned duration )

{

int control;

/* If frequency is 0, Beep doesn't try to make a sound. */

if( frequency )

{

/* 75 is about the shortest reliable duration of a sound. */

if( duration < 75 )

duration = 75;

/* Prepare timer by sending 10111100 to port 43. */

_outp( 0x43, 0xb6 );

/* Divide input frequency by timer ticks per second and

* write (byte by byte) to timer.

*/

frequency = (unsigned)(1193180L / frequency);

_outp( 0x42, (char)frequency );

_outp( 0x42, (char)(frequency >> 8) );

/* Save speaker control byte. */

control = _inp( 0x61 );

/* Turn on the speaker (with bits 0 and 1). */

_outp( 0x61, control | 0x3 );

}

Sleep( (clock_t)duration );

/* Turn speaker back on if necessary. */

if( frequency )

_outp( 0x61, control );

}

/* Pauses for a specified number of microseconds. */

void Sleep( clock_t _wait )

{

clock_t goal;

goal = _wait + clock();

while( goal > clock() )

;

}