/************************************************************************
* *
* 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_IO.rar_Parallel_IO_parallel_并口_并口输入输出
版权申诉
122 浏览量
2022-09-23
23:03:05
上传
评论
收藏 2KB RAR 举报
APei
- 粉丝: 63
- 资源: 1万+
最新资源
- 基于Arduino Nano的红外循迹小车源码(高分课设).zip
- 将MS SQL数据库表里的数据内容生成SQL执行语句
- 基于MATLAB的钢板表面缺陷检测系统
- MS SQL里生成行政区域县区信息表和相应数据
- delphi实现DBGrid全选和反选功能
- 25C11F41-2B2A-4D1A-AAA8-7C654526B129.pdf
- Android Studio Jellyfish(android-studio-2023.3.1.18-cros.deb)
- MVC+EF框架+EasyUI实现权限管理源码程序
- python第66-75天,Day66-75.rar
- python后端服务project-of-tornado.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈