Using VC ++ to collect computer data

Source: Internet
Author: User
AbstractThe A/D conversion interface circuit is made by using the ready-made functions provided by VC ++ to directly control and read and write standard interfaces. It features no need to open the chassis, low development costs, and convenient production.

  Keywords Computer Parallel port; modulus conversion; VC ++

  Preface

The connection between the computer and peripheral devices has multiple interface methods: serial, USB, SCSI, parallel, etc. Each interface method has its advantages and disadvantages. Due to the anti-interference of the serial and USB interfaces Capability Strong, the transmission distance is far, so the above two methods are used in data communication. However, in some applications, such as CCD and video data acquisition cards, the transmission distance is near. At this time, parallel interfaces are used, and such applications will increase with the increase of data processing speed.

In addition, when the computer is used for analog signal detection, You need to configure the/D conversion interface circuit, Product The cost of data acquisition card is relatively expensive, and you develop a set of traditional Data collection The card requires a lot of knowledge, especially the development of low-layer drivers, which is difficult.

  Define the foot position of a parallel interface

1. Physical Interface Description

Computer port adapter or Data The acquisition card uses a multi-mode control chip. The operating mode of the parallel adapter can be set in CMOS. The operating modes of parallel interfaces include standard parallel interfaces (SPP), simple bidirectional interfaces (PS/2), enhanced parallel interfaces (EPP1.9), and extended functional interfaces (ECP.

The physical interface adopts the Dsub25 needle internal-hole connector described in the IEEE1284 standard. Pin signal Work Different modes are also different. The SPP mode is used by default below (see table 1 ).

S corresponds to the Status Register and C corresponds to the control register. Their corresponding addresses are base address (378 H) + 1 and base address (378 H) + 2.

Table 1 physical connection and output direction in parallel port SPP Mode

  

2. Register description

Figure 1 shows the control register of the printer adapter, which uses only the lower five digits.

  

Figure 1 control register

Figure 2 shows the Status Register of the printer adapter, which uses only the 5-bit high.

  

Figure 2 Status Register

Table 1 shows the relationship between each user and the pin.

1. ad7820 pins and functions

Ad7820 is a high-speed 8-bit ADC chip compatible with the microprocessor. It uses a single + 5 V power supply without external clock and has a sampling and holding circuit, the conversion time reaches 1.36 μs. Pin 3

Pin features:

VIN Simulation Signal Transmission personnel;

  

Figure 3 ad7820 pin chart

DBO-DB7 three-state data output;

/Rdy write control/output ready;

Mode mode selection, internal pull through a 50μa Current Source Low, mode = 0 to activate the Read mode, mode = 1 to activate the write read mode;

Read control, low-power access Data ;

Interrupt output control bit. Low Power Consumption usually indicates the end of The adswitch;

Gnd Power Supply location;

Vref (1) reference voltage negative end (1), zero-code input analog voltage, range: Gnd ≤ vref (1) ≤ vref (10 );

Vref (+) refers to the positive end of the voltage (10). The analog voltage is input at full scale. The range is vref (1) ≤ vref (10) ≤ VDD;

Segment selection and input, when reading or writing, must be low;

Overflow flag;

NC traffic control foot;

VDD Power Supply + 5 V.

2. Circuit Implementation

  

Figure 4 A/D conversion interface circuit

As shown in principle 4 of A/D conversion interface circuit, AD7820 starts data conversion when A negative pulse is generated in read-only mode. The required control signal is generated by the 14-pin C1-bit output line of the printer control port, and A negative pulse is output to the pin. the/D conversion starts and ends after 1.36 μs, the data lock exists in the three-state output data lock in the chip, and the pin outputs a low level. The pin is connected to the 11-pin socket corresponding to the S7-bit printer status port. You can check whether the switch is complete by querying the S7-bit status port.

In Figure 4, 74LS157 is a four-two-choose-1 data selector that sends the result to the S3 ~ of the printer status port twice ~ S6 bits are connected to the printer pins 15, 13, 12, and 10. The control signal of the printer is controlled by the C2 16-pin control port. Computer Obtain data from the printer status port twice.

  Software Implementation

After the/D conversion interface circuit is configured on the PC, the analog electrical signal can be detected. The input range of the analog electrical signal is 0 ~ 4.98 V. Coupled with sensors, it can be used for non-electrical analog detection.

Below is a small section Program Written in VC ++. The input/output of the port in VC ++ can be achieved through the port I/O function in p and ou tp. The function is included in the conio. h library.

.................

-Outp (0x37a, 3); // clear the port

-Outp (0x37a, 0); // start a/d Conversion

Do {datainput =-Indium (0x379) & 0x80 };

While (datainput! = 0x80); // wait until the conversion ends.

Data =-Indium (0x379); // input four low-Bit Data

Data = Data & 0x78;

Data1 = Data> 3;

-Outp (0x37a, 0x4); // The 16-pin control is high.

Data =-Indium (0x379); // The input height is four digits.

Data = Data & 0x78;

-Outp (0x37a, 3); // stop A/D Conversion

Data = Data <1;

Data = Data | Data1 // 8-bit binary merge

............ // Further data processing

  Conclusion

This system can be applied in some systems with low real-time requirements. Computing The expansion slots of the microcomputer are not used, which are small in size and cost-effective, and break through the traditional microcomputer. Data collection Makes the interface between the data collection device and the microcomputer more flexible and convenient.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.