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

📄 parallel_io.c

📁 并口测试程序
💻 C
字号:
/************************************************************************
*								 	*
*    File name	 : Parallel_IO.c				 	*
*    Function	 : This file  execute the functions of test	 	*
*		   PC's parallel controller Data states	              	*
*		   该程序用于测试计算机并口控制器数据线			*
*    Created by  : Wang ZhenQuan			    	 	*
*    Modified by : 				   	 	 	*
*    Language	 : Borland C V3.1				 	*
*    Called by	 : none 					 	*
*								 	*
************************************************************************/

/*****************************************************************
	所包含的库文件include files
*****************************************************************/
#include	<stdio.h>
#include 	<conio.h>
#include 	<dos.h>

/*****************************************************************
	程序中定义的常量,Parallel_Addr主要是用来IO口的脉冲输出
假定:Parallel_Addr:第7位 C轴方向 0:正向,1:负向
		     第6位 Z轴方向 0:正向,1:负向
		     第5位 Y轴方向 0:正向,1:负向
		     第4位 X轴方向 0:正向,1:负向
		     第3位 C轴脉冲输出
		     第2位 Z轴脉冲输出
		     第1位 Y轴脉冲输出
		     第0位 X轴脉冲输出			
*****************************************************************/
#define	ENTER	13

int Parallel_Addr;
int Parallel_Reg;
char	a;
char 	choice;     //定义choice以储存用户的选择
int 	quit_now=0;//定义quit_now来决定是否结束程序,quit_now为1是退出				

/*****************************************************************
	程序中定义的函数
*****************************************************************/
void    init_parallel_IO(void);//界面初始化
void	Test_X_Positive(void);//X+ pulse
void	Test_X_Negative(void);//X- pulse
void	Test_Y_Positive(void);//Y+ pulse
void	Test_Y_Negative(void);//Y- pulse
void	Test_Z_Positive(void);//Z+ pulse
void	Test_Z_Negative(void);//Z- pulse
void	Test_C_Positive(void);//C+ pulse
void	Test_C_Negative(void);//C- pulse
/*****************************************************************
	the main porgram
	主程序
*****************************************************************/
int main(void)
{
	Parallel_Addr = peek(0x0040,0x0008);//得到计算机并口地址
	Parallel_Reg  = 0x00;
	clrscr();//清屏
	init_parallel_IO();//测试并口输入输出状态

	return 0;
}

/*****************************************************************
	init the window of the program
	界面初始化
*****************************************************************/
void 	init_parallel_IO(void)			
{
	clrscr();//清屏			
	//下面是程序的界面设置
	printf("%20s////////////////////////////////////////////////\n"," ");
	printf("%20s//					          //\n"," ");
	printf("%20s//   PC controller Test Program		  //\n"," ");
	printf("%20s//					          //\n"," ");
	printf("%20s//	     1> Test X_axis +                     //\n"," ");
	printf("%20s//	     2> Test X_axis -		 	  //\n"," ");
	printf("%20s//       3> Test Y_axis +			  //\n"," ");
	printf("%20s//	     4> Test Y_axis -			  //\n"," ");
	printf("%20s//       5> Test Z_axis +	                  //\n"," ");
	printf("%20s//       6> Test Z_axis -	                  //\n"," ");
	printf("%20s//       7> Test 4_axis +	                  //\n"," ");
	printf("%20s//       8> Test 4_axis -	                  //\n"," ");
	printf("%20s//	     q> Quit		                  //\n"," ");
	printf("%20s//					          //\n"," ");
	printf("%20s////////////////////////////////////////////////\n"," ");
	printf("please input your choice(1--q):");
	quit_now = 0;
	choice=getchar();		
	//得到用户的选择
	do{
		switch(choice)
		{
		case '1':
			Test_X_Positive();//X+
			break;
		case '2':
			Test_X_Negative(); //X-
			break;
		case '3':
			Test_Y_Positive();//Y+
			break;
		case '4':
			Test_Y_Negative();//Y-
			break;
		case '5':
			Test_Z_Positive();//Z+
			break;
		case '6':
			Test_Z_Negative(); //Z-
			break;
		case '7':
			Test_C_Positive();//C+
			break;
		case '8':
			Test_C_Negative(); //C-
			break;	
		case 'q':		//exit test program.
			quit_now=1;
			break;
		default:
			init_parallel_IO();//Repeat enter.
			break;
		}
	choice = 0;
	}while(quit_now!=1);
}

/*****************************************************************
	测试X轴正向脉冲输出
*****************************************************************/
void	Test_X_Positive(void)
{
	int  i;
	printf("now test X_axis +\n");
	Parallel_Reg &= 0xef;
	outportb(Parallel_Addr, Parallel_Reg);//set direction.
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Reg |= 0x01; 	
			outportb(Parallel_Addr, Parallel_Reg);
			delay(0.5);
			Parallel_Reg &= 0xfe;
			outportb(Parallel_Addr, Parallel_Reg);
			delay(0.5);
			printf("\rX_axis+: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

/*****************************************************************
	测试X轴负向脉冲输出
*****************************************************************/
void	Test_X_Negative(void)
{
	int  i;
	printf("now test X_axis -\n");
	Parallel_Reg |= 0x10;
	outportb(Parallel_Addr, Parallel_Reg);
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Reg |= 0x01; 	
			delay(0.5);
			Parallel_Addr &= 0xfe;
			delay(0.5);
			printf("\rX_axis-: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

/*****************************************************************
	测试Y轴正向脉冲输出
*****************************************************************/
void	Test_Y_Positive(void)
{
	int  i;
	printf("now test Y_axis +\n");
	Parallel_Addr &= 0xdf;
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Addr |= 0x02; 	
			delay(0.5);
			Parallel_Addr &= 0xfd;
			delay(0.5);
			printf("\rY_axis+: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

/*****************************************************************
	测试Y轴负向脉冲输出
*****************************************************************/
void	Test_Y_Negative(void)
{
	int  i;
	printf("now test Y_axis -\n");
	Parallel_Addr |= 0x20;
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Addr |= 0x02; 	
			delay(0.5);
			Parallel_Addr &= 0xfd;
			delay(0.5);
			printf("\rY_axis-: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

/*****************************************************************
	测试Z轴正向脉冲输出
*****************************************************************/
void	Test_Z_Positive(void)
{
	int  i;
	printf("now test Z_axis +\n");
	Parallel_Addr &= 0xbf;
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Addr |= 0x04; 	
			delay(0.5);
			Parallel_Addr &= 0xfb;
			delay(0.5);
			printf("\rZ_axis+: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

/*****************************************************************
	测试Z轴负向脉冲输出
*****************************************************************/
void	Test_Z_Negative(void)
{
	int  i;
	printf("now test Z_axis -\n");
	Parallel_Addr |= 0x40;
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Addr |= 0x04; 	
			delay(0.5);
			Parallel_Addr &= 0xfb;
			delay(0.5);
			printf("\rZ_axis-: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}
/*****************************************************************
	测试第四轴正向脉冲输出
*****************************************************************/
void	Test_C_Positive(void)
{
	int  i;
	printf("now test 4_axis +\n");
	Parallel_Addr &= 0x7f;
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Addr |= 0x08; 	
			delay(0.5);
			Parallel_Addr &= 0xf7;
			delay(0.5);
			printf("\rC_axis+: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

/*****************************************************************
	测试第四轴负向脉冲输出
*****************************************************************/
void	Test_C_Negative(void)
{
	int  i;
	printf("now test 4_axis -\n");
	Parallel_Addr |= 0x80;
	while (kbhit()==0)
	{
		for(i=0;i<=10;i++)
		{
			Parallel_Addr |= 0x08; 	
			delay(0.5);
			Parallel_Addr &= 0xf7;
			delay(0.5);
			printf("\rC_axis+: %d  ",i);
		 }
	}
	a=getch();
	if(a==ENTER)    choice='0';
}

⌨️ 快捷键说明

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