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

📄 photo.c

📁 _计算实用教程Visual C++6.0实用教程
💻 C
字号:
/*photo.c*/
/******************************************************************/
/* Program to demonstrate the working of the Photometer interface */
/* through the parallel printer adapter. Connect the interface to */
/* LPT1 & COM1. Connect the photometer to the interface.          */
/******************************************************************/
/*                 Compile with TurboC Ver. 2.0                   */
/******************************************************************/ 


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



int modem_control_reg, dport_lpt1, cport_lpt1, sport_lpt1;

/* Declare the subroutines */
unsigned char get_integ_time(void);
unsigned int get_count(void);



unsigned char get_integ_time(void)
{
int temp;

clrscr();
printf("Character     Integration time\n");
printf("0             00.125 sec\n");
printf("1             00.250 sec\n");
printf("2             00.5   sec\n");
printf("3             01.0   sec\n");
printf("4             02.0   sec\n");
printf("5             04.0   sec\n");
printf("6             08.0   sec\n");
printf("7             16.0   sec\n");

temp=getchar();
switch(temp){
case '0':	return 0;
case '1':	return 1;
case '2':	return 2;
case '3':	return 3;
case '4':	return 4;
case '5':	return 5;
case '6':	return 6;
case '7':	return 7;
default:	return 100;
}
return;

}


unsigned int get_count(void)
{
unsigned char monitor, nib_0, nib_1, nib_2, nib_3;

/* Reset the binary counters U6, U7 & the flipflop U4-A */
/* The Control port bit C0 of the printer adapter is used */
outportb(cport_lpt1,1);
outportb(cport_lpt1,0);



/* Monitor the o/p of flipflop U4-A */


/* Wait in the loop till it is zero */
monitor = 0;
while(monitor == 0) monitor = inportb(sport_lpt1) & 0x08;

/* Now the flipflop has enabled the counters */
/* So, wait till the counting is over  */
monitor = 0x08;
while(monitor == 0x08) monitor = inportb(sport_lpt1) & 0x08;

/* Read the four nibbles*/

/* Nibble 3, the most significant nibble*/
outportb(dport_lpt1,3);
nib_3 = inportb(sport_lpt1);

/* Nibble 2 */
outportb(dport_lpt1,02);
nib_2 = (inportb(sport_lpt1) >>4);

/* Nibble 1 */
outportb(dport_lpt1,1);
nib_1 = inportb(sport_lpt1);


/* Nibble 0, the lest significant */
outportb(dport_lpt1,0);
nib_0 =(inportb(sport_lpt1) >> 4);


/* put all the nibbles in one integer variable */

nib_1 = nib_1 & 0x0f0;
nib_1 = nib_1 | nib_0;
nib_1 = nib_1 ^ 0x88;

nib_3=nib_3 & 0x0f0;
nib_3 = nib_3 | nib_2;
nib_3 = nib_3 ^ 0x88;

/* Return the unsigned integer */
return (nib_3*256 + nib_1);
}



void main(void)
{
unsigned char int_win;

/* Sign ON */
clrscr();
printf("Photometer interface for the IBM PCs & compatibles, Version 1.0");
printf("\nUses the parallel printer adapter for counting");
printf("\n&the RS-232 port for the power supply");
printf("\n\nBy: D.V.GADRE");

/* Get COM1 register address */

modem_control_reg = peek(0x40,0)+4;
if(modem_control_reg == 4)
	{
	printf("\n\n\nCOM1 not available... aborting\n\n\n");
	exit(1);
	}
printf("\n\n\nCOM1 address = %X",peek(0x40,0) );

/*Get LPT1 port addresses */

dport_lpt1 = peek(0x40,0x08);
if(dport_lpt1 ==0)
	{
	printf("\n\n\nLPT1 not available... aborting\n\n\n");
	exit(1);
	}
printf("\nLPT1 address = %X", dport_lpt1);
cport_lpt1 = dport_lpt1 +2; 	/* control port address */
sport_lpt1 = dport_lpt1 + 1;	/* status port address */

/* put power On on COM1 */
outportb(modem_control_reg, 03);
printf("\nPutting Power ON...\n\n\n");
sleep(1);

/* Get the integration time window */
int_win = get_integ_time();

while(int_win<0 || int_win >7) int_win = get_integ_time();
clrscr();

printf("Using integration window %d\n\n", int_win);
while(!kbhit())

		
               {
               /* set integration time */
               outportb(dport_lpt1, int_win);

               /* Get the accumulated count & print it on the screen */
               printf("%u ", get_count());
               }


}

⌨️ 快捷键说明

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