码迷,mamicode.com
首页 > 其他好文 > 详细

QNX LPT Port Programming

时间:2014-05-26 22:04:49      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:c   tar   a   int   get   art   

#include <stdio.h> 
#include <unistd.h> /* for sleep() */ 
#include <stdint.h> /* for uintptr_t */ 
#include <hw/inout.h> /* for in*() and out*() functions */ 
#include <sys/neutrino.h> /* for ThreadCtl() */ 
#include <sys/mman.h> /* for mmap_device_io() */ 

/* The Neutrino IO port used here corresponds to a single register, which is 
* one byte long */ 
#define PORT_LENGTH 1 

/* The first parallel port usually starts at 0x378. Each parallel port is 
* three bytes wide. The first byte is the Data register, the second byte is 
* the Status register, the third byte is the Control register. */ 
#define DATA_ADDRESS 0x378 
#define CTRL_ADDRESS 0x37a 
/* bit 2 = printer initialisation (high to initialise) 
* bit 4 = hardware IRQ (high to enable) */ 
#define INIT_BIT 0x04 

#define LOW 0x00 
#define HIGH 0xFF 

#define MAX_COUNT 60 


/* ______________________________________________________________________ */ 
int 
main( ) 

int privity_err; 
uintptr_t ctrl_handle; 
uintptr_t data_handle; 
int count; 

/* Give this thread root permissions to access the hardware */ 
privity_err = ThreadCtl( _NTO_TCTL_IO, NULL ); 
if ( privity_err == -1 ) 

fprintf( stderr, "can‘t get root permissions\n" ); 
return -1; 


/* Get a handle to the parallel port‘s Control register */ 
ctrl_handle = mmap_device_io( PORT_LENGTH, CTRL_ADDRESS ); 
/* Get a handle to the parallel port‘s Data register */ 
data_handle = mmap_device_io( PORT_LENGTH, DATA_ADDRESS ); 

for ( count = 0; count < MAX_COUNT; count++ ) 
{
/* Output a byte of lows to the data lines */ 
out8( data_handle, LOW); 
out8( ctrl_handle, (LOW & 0x0f ) ); 
printf( "Low\n" ); 
sleep( 1 ); 

/* Output a byte of highs to the data lines */ 
out8( data_handle, HIGH ); 
out8( ctrl_handle, (HIGH & 0x0f )); 
printf( "High\n" ); 
sleep( 1 ); 


return 0; 

QNX LPT Port Programming,布布扣,bubuko.com

QNX LPT Port Programming

标签:c   tar   a   int   get   art   

原文地址:http://www.cnblogs.com/zhhkang/p/3745388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!