📄 read_dat.c
字号:
/*read_dat.c*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <process.h>
#define READ_LEN 1000 /*number of data points to read*/
/*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 that is received from the external
device*/
unsigned char input_buffer[1000], low_nib, high_nib, real_byte, 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 read the required data points*/
for(count=0; count<READ_LEN; count++)
{
/*in practice, some sort of synchronization code will go here*/
temp=inportb(cport);
temp=temp | 0x01; /*this makes the external C0* signal low*/
outportb(cport, temp);
low_nib=inportb(sport);
temp=temp & 0xfe; /*make external C0* signal high again*/
outportb(cport, temp);
high_nib=inportb(sport);
low_nib=low_nib >> 4;
/*shift the 4 upper bits to lower 4 positions*/
low_nib = low_nib & 0x0f; /*make sure upper 4 bits are all 0s */
high_nib=high_nib & 0xf0; /*to make lower 4 bits all 0s */
real_byte = high_nib | low_nib; /* OR the two bytes together*/
real_byte=real_byte ^ 0x88;
/*flip the 7th and the 3rd bit and now the real byte is ready*/
/*now store it*/
input_buffer[count]=real_byte;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -