codestep
驱动牛犊
驱动牛犊
  • 注册日期2002-10-11
  • 最后登录2009-02-08
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1404回复:2

如何用vc编程使用giveio.sys访问并口

楼主#
更多 发布于:2003-08-29 13:33
如何用vc编程使用giveio.sys访问并口
grant
驱动老牛
驱动老牛
  • 注册日期2001-05-14
  • 最后登录2007-04-13
  • 粉丝0
  • 关注0
  • 积分350分
  • 威望35点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-08-29 15:08
/*********************************************************************

Author:     Dale Roberts
Date:       8/30/95
Program:    TSTIO.EXE
Compile:    cl -DWIN32 tstio.c

Purpose:    Test the GIVEIO device driver by doing some direct
            port I/O.  We access the PC\'s internal speaker.

*********************************************************************/
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <conio.h>

typedef struct {
short int pitch;
short int duration;
} NOTE;

/*
 *  Table of notes.  Given in half steps.  It\'s a communication from
 * the \"other side.\"
 */
NOTE notes[] = {{14, 500}, {16, 500}, {12, 500}, {0, 500}, {7, 1000}};

/*********************************************************************
  Set PC\'s speaker frequency in Hz.  The speaker is controlled by an
Intel 8253/8254 timer at I/O port addresses 0x40-0x43.
*********************************************************************/
void setfreq(int hz)
{
hz = 1193180 / hz; // clocked at 1.19MHz
_outp(0x43, 0xb6); // timer 2, square wave
_outp(0x42, hz);
_outp(0x42, hz >> 8);
}

/*********************************************************************
  Pass a note, in half steps relative to 400 Hz.  The 12 step scale
is an exponential thing.  The speaker control is at port 0x61.
Setting the lowest two bits enables timer 2 of the 8253/8254 timer
and turns on the speaker.
*********************************************************************/
void playnote(NOTE note)
{
_outp(0x61, _inp(0x61) | 0x03); // start speaker going
setfreq((int)(400 * pow(2, note.pitch / 12.0)));
Sleep(note.duration);
_outp(0x61, _inp(0x61) & ~0x03); // stop that racket!
}

/*********************************************************************
  Open and close the GIVEIO device.  This should give us direct I/O
access.  Then try it out by playin\' our tune.
*********************************************************************/
int main()
{
int i;
HANDLE h;

    h = CreateFile(\"\\\\\\\\.\\\\UserPort\", GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if(h == INVALID_HANDLE_VALUE) {
        printf(\"Couldn\'t access giveio device\\n\");
        return -1;
    }
CloseHandle(h);

for(i=0; i < sizeof(notes)/sizeof(int); ++i)
playnote(notes);

return 0;
}

助人乃快乐之本 有人给分就更快乐了 :-)
grant
驱动老牛
驱动老牛
  • 注册日期2001-05-14
  • 最后登录2007-04-13
  • 粉丝0
  • 关注0
  • 积分350分
  • 威望35点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-08-29 15:08
这是giveio带的例子。
助人乃快乐之本 有人给分就更快乐了 :-)
游客

返回顶部