www.mikrocontroller.net

Ports benutzen (Windows)

Inhaltsverzeichnis

[Bearbeiten] Allgemein

Nach einem Forenbeitrag von Feadi aus Frankreich.

[Bearbeiten] Beispiel

// v 1.3
// GCC Compiler wg. Inline-ASM
// Installiertes giveio.sys erforderlich (s. Weblinks)
//
#include <windows.h>
#include <stdint.h>
#include <stdio.h>
 
#ifndef __cplusplus
typedef enum {false,true} bool;	// gibt's nicht in C!
#endif
 
uint8_t inb( uint16_t portaddr )
{
  uint8_t value;
 
  asm volatile
  (
    "in %1, %0" :
    "=a" (value) :
    "d" (portaddr)
  );
 
  return value;
}
 
void outb( uint8_t value, uint16_t portaddr )
{
  asm volatile
  (
    "out %1, %0" ::
    "d" (portaddr), "a" (value)
  );
}
 
bool iopl()
{
  bool ret;
 
  HANDLE h;
  h = CreateFile("\\\\.\\giveio", GENERIC_READ,
    0, NULL, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL, NULL);
 
  ret = h != INVALID_HANDLE_VALUE;
  CloseHandle(h);
 
  return ret;
}
 
int main (void)
{
  uint8_t u8=0;
 
  if ( !iopl() )
  {
    // giveio.sys ist auf diesem system nicht installiert
    error( "giveio.sys nicht installiert!" );
    return -1;
  }
 
  u8 = inb(888); // read from the parallel port
  fprintf(stdout,  "Read %hu from port 888.\n", u8 );
  return 0;
}

[Bearbeiten] Serielle Schnittstelle (RS232)

[Bearbeiten] Siehe auch

[Bearbeiten] Weblinks

webmaster@mikrocontroller.netImpressumNutzungsbedingungenWerbung auf Mikrocontroller.net