• 您的位置我爱Aspx >> VC.Net >> 实战DeviceIoControl 之六:访问物理端口
  • 实战DeviceIoControl 之六:访问物理端口

  • 作者:aspxer  来源:internet  日期:2007-5-21 23:48:04  关键字:
  • 有了ReadPortByte和WritePortByte这两个函数,我们就能很容易地操纵CMOS和speaker了(关于CMOS值的含义以及定时器寄存器定义,请参考相应的硬件资料): // 0x70是CMOS索引端口(只写) // 0x71是CMOS数据端口 BYTE ReadCmos(BYTE index) { BYTE data; ::WritePortByte(0x70, index); data = ::ReadPortByte(0x71); return data; } // 0x61是speaker控制端口 // 0x43是8253/8254定时器控制端口 // 0x42是8253/8254定时器通道2的端口 void Sound(DWORD freq) { BYTE data; if ((freq >= 20) && (freq <= 20000)) { freq = 1193181 / freq; data = ::readportbyte(0x61); if ((data & 3) == 0) { ::writeportbyte(0x61, data | 3); ::writeportbyte(0x43, 0xb6); } ::writeportbyte(0x42, (byte)(freq % 256)); ::writeportbyte(0x42, (byte)(freq / 256)); } } void nosound(void) { byte data; data = ::readportbyte(0x61); ::writeportbyte(0x61, data & 0xfc); } // 以下读出CMOS 128个字节 for (int i = 0; i < 128; i++) { byte data = ::readcmos(i); ... ... } // 以下用c调演奏“多-来-米” // 1 = 262 hz ::sound(262); ::sleep(200); ::nosound(); // 2 = 288 hz ::sound(288); ::sleep(200); ::nosound(); // 3 = 320 hz ::sound(320); ::sleep(200); ::nosound();

    我对这篇文章有话说?
  • 广告位招租,广告代号:content_468_15
  • 上一篇:获取系统当前打开的端口(tcp。udp)状态,以及连接方的ip。端口
    下一篇:By value? Or by reference?
  • 相关文章