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

📄 expandop.c

📁 这是《并行口编程指南》的附盘的源代码 很有参考价值哦
💻 C
字号:
/*expandop.c*/
/*program to provide extra digital output ports (max 4) on the
standard parallel port.*/

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <process.h>

#define BUF_DEPTH 100 /* 100 data points to send to each port*/

/*Global variables that store the addresses of the three ports of the
standard printer adapter*/
unsigned int dport, cport, sport;

/*routines to generate pulse on each of the 4 control port pins*/
void pulse_c0(void);
void pulse_c1(void);
void pulse_c2(void);
void pulse_c3(void);

void pulse_c0(void) /*generates a low to high pulse on C0 pin*/ 
{
unsigned char temp;

temp=inportb(cport);
temp=temp | 0x01;
outportb(cport, temp);
delay(1);
temp=temp & 0xfe;
outportb(cport, temp);
delay(1);
}

void pulse_c1(void) /*generates a low to high pulse on C1 pin*/ 
{
unsigned char temp;

temp=inportb(cport);
temp=temp | 0x02;
outportb(cport, temp);
delay(1);
temp=temp & 0xfd;
outportb(cport, temp);
delay(1);
}

void pulse_c2(void) /*generates a low to high pulse on C2 pin*/ 
{
unsigned char temp;

temp=inportb(cport);
temp=temp & 0xfb;
outportb(cport, temp);
delay(1);
temp=temp | 0x04;
outportb(cport, temp);
delay(1);
}

void pulse_c3(void) /*generates a low to high pulse on C3 pin*/ 
{
unsigned char temp;

temp=inportb(cport);
temp=temp | 0x08;
outportb(cport, temp);
delay(1);
temp=temp & 0xf7;
outportb(cport, temp);
delay(1);
}


main()
{
/*the following array stores data to be transfered to the external 
ports, port_0, port_1, port_2 and port_3*/
unsigned char port_0_buf[100], port_1_buf[100],port_2_buf[100],
port_3_buf[100], 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_DEPTH; count++)
         {
              /*transfer data to port 0*/
              /*first output data to the DATA port*/
              outportb(dport, port_0_buf[count]);
              /* now generate a pulse on CONTROL port pin C0 */
              pulse_c0();

              /*transfer data to port 1*/
              /*first output data to the DATA port*/
              outportb(dport, port_1_buf[count]);
              /* now generate a pulse on CONTROL port pin C1 */
              pulse_c1();

              /*transfer data to port 2*/
              /*first output data to the DATA port*/
              outportb(dport, port_2_buf[count]);
              /* now generate a pulse on CONTROL port pin C2 */
              pulse_c2();

              /*transfer data to port 3*/
              /*first output data to the DATA port*/
              outportb(dport, port_3_buf[count]);
              /* now generate a pulse on CONTROL port pin C3 */
              pulse_c3();


         }
return 1;

}

⌨️ 快捷键说明

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