⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prin_dat.c

📁 这是《并行口编程指南》的附盘的源代码 很有参考价值哦
💻 C
字号:
/*prin_dat.c*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <process.h>


#define BUF_LEN 1000

/*Global variables that store the addresses of the three ports of the
standard printer adapter*/

unsigned int dport, cport, sport;


main()
{
/*the following array stores data to be transfered to the external 
device*/
unsigned char print_buffer[1000], temp;

unsigned int count;

/*Get LPT1 port addresses */
dport = peek(0x40,0x08);
if(dport ==0)
        {
        printf("\n\n\nLPT! not available... aborting\n\n\n");
        exit(1);
        }
printf("\nLPT1 address = %X", dport);
cport = dport +2; 	/* control port address */
sport = dport + 1;	/* status port address */

/*this statement puts all the CONTROL port signals to logic 1*/
outportb(cport, 0x04);

/*setup a loop to transfer the required data points*/
for(count=0; count<BUF_LEN; count++)
         {
          /*First check if the external device is not BUSY*/
/*the BUSY signal is the msb of the status port, so read the status
port, isolate the 7th bit and wait till it becomes 1. Since the bit 
is inverted, a BUSY low means that the register bit is 1. In the 
following example some sort of timeout feature must be included for
practical use*/
          temp=inportb(sport);
	  temp=temp & 0x80;
          while(temp != 0x80)
             {
              temp=inportb(sport);
	      temp=temp & 0x7f;
             }

/*OK, now the external device is ready so pump some data*/
            outportb(dport, print_buffer[count]);

/*now pulse the nSTROBE signal low and then high again*/
/*make sure that the other CONTROL signals are not disturbed*/
temp=inportb(cport);
temp=temp | 0x01; /*this makes the external signal low*/
/*nSTROBE occupies the lsb of the CONTROL port register*/

outportb(cport, temp);

temp=temp & 0xfe; /*make it high again*/
outportb(cport, temp);
         }
return 1;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -