Current location - Education and Training Encyclopedia - Graduation thesis - Kneel for graduation thesis of university single chip microcomputer
Kneel for graduation thesis of university single chip microcomputer
Design of Intelligent Multi-channel Serial Data Acquisition/Transmission Module

Guangzhou Optoelectronic Engineering Research Center UnionPay

Guanqiang Guangzhou fangtong biology science and technology co., ltd

introduce

With the continuous development of electronic technology, it is now possible to detect and control various physical quantities. Microcomputer detection control system is not only used in industrial process control, such as aerospace, robotics, textile machinery, food processing and so on. , and has become the main component of various household appliances. Among them, A/D equipment plays a very important role. In this way, a system will need more A/D equipment. Generally, it is realized by expanding one or more A/D acquisition cards. When the analog signals such as temperature and pressure are few or slowly changing, it is not the most suitable and economical scheme to adopt bus A/D card. This paper introduces a sampling module based on AT89C205 1 single chip microcomputer and adopting TLC2543L 12-bit serial A/D converter. The sampling data of this module is converted from the serial port level of the single chip microcomputer to the serial port of the PC (COM 1 or COM2), thus forming the way of serial data acquisition and serial data transmission.

Function introduction of main components

AT89C205 1 Single Chip Microcomputer

AT89C205 1 is a cost-effective 8-bit single-chip microcomputer introduced by ATMEL Company, and its instruction system is completely compatible with MCS-5 1 series. Pin arrangement is shown in figure 1.

TLC2543L serial analog-to-digital converter

TLC2543L adopts SPI serial interface bus proposed by Motorola. It is a three-wire synchronous interface, including synchronous signal, input signal and output signal. In addition, the chip also has a chip line selection, and the single chip microcomputer gates TLC2543L through the chip line selection. Among them, CLK is the synchronous clock pulse, CS is the chip selection, DIN is the data output of MCU and the data input line of TLC2543L, and DOUT is the data input line of MCU and TLC2543L. Fig. 2 is a timing diagram of TLC2543L. TLC2543L is full duplex, that is, it can send and receive data at the same time. If only data is written to TLC2543L, the single chip microcomputer can discard the read data at the same time; On the other hand, if you read only data, you can write any data after the command byte. Data transmission takes byte as unit and adopts high-order priority format.

The module adopts TLC2543L 12-bit serial A/D converter of TI company, and the A/D conversion process is completed by switched capacitor successive approximation method. Serial input structure can greatly save I/O resources of 5 1 series single chip microcomputer, and the price is moderate. It is characterized in that:

(1) 1 1 analog input channels;

(2) The conversion time is10s;

(3) 12 bit resolution A/D converter;

(4) 3-way built-in self-test mode;

(5) The sampling rate is 66kbps;;

(6) Linear error+1LSB (maximum)

(7) There is an EOC output;

(8) with unipolar and bipolar output;

(9) Programmable MSB or LSB preamble;

(10) Programmable output data length. The pin arrangement of TLC2543L is shown in Figure 3. In figure 3, ain0 ~ ain 10 are analog inputs; Select the end of the chip; DIN is a serial data input terminal; DOUT is the tri-state serial output of A/D conversion result; EOC is the end point of transformation; CLK is the input and output clock; REF+ is the positive reference voltage terminal; REF- is the negative reference terminal; VCC is the power supply; GND is grounded.

Level shifter MAX232C

MAX232C is an RS-232 transceiver, which is simple and easy to use. It is powered by a single power supply of +5V, and only a few external capacitors are needed to complete the conversion from TTL level to RS-232 level. The pin arrangement is shown in Figure 4.

hardware design

The hardware circuit is shown in Figure 5.

Single chip microcomputer AT89C205 1 is the core of the whole system. TLC2543L collects the input analog signal, and the microcontroller receives the conversion result through P3.5 (pin 9). Channel selection and mode data of AD chip are input into 8-bit address and control register through P3.4 (pin 8), and the data collected by microcontroller is converted into RS232 level through serial port (pin 3 and pin 2) through MAX232C.

Software design of single chip microcomputer

The MCU program mainly includes the system information, channel number, acquisition period and communication protocol definition of serial data acquisition/transmission module, as well as the standard subroutine of data acquisition and transmission.

The channel selection and mode data of TLC2543L is 8 bits, and its functions are as follows: D7, D6, D5 and D4 are used to select the channel to be converted, D7D6D5D4=0000 selects 0 channel, D7D6D5D4=000 1 select 1 channel, and so on; D3 and D2 are used to select the output data length. This program selects the output data length as 12 bits, that is, D3D2=00 or d3d2 =10; D 1, D0 selects the leading position of the input data, and D 1D0=00 selects the leading position of the high bit.

The data read by TLC2543L in each I/O cycle is the result of the last conversion, and the current conversion result is shifted out in series in the next I/O cycle. Due to internal adjustment, the first reading may be inaccurate, so it should be discarded.

The data acquisition procedure is as follows:

sbit datain=p 1^ 1;

sbit clock=p 1^0;

sbit dataout=p 1^2;

sbit cs=p 1^3;

Bit data in_a_bit0 ()

{bit m = 0;;

data out = 1;

m = DATAOUT

DATAIN = 0;

nop();

Clock =1;

nop();

Clock = 0;

Return (m);

}

Bit data in_a_bit 1 ()

{bit m = 0;;

data out = 1;

m = DATAOUT

DATAIN = 1;

nop();

Clock =1;

nop();

Clock = 0;

Return (m);

}

Single chip microcomputer generates serial clock through programming, sends and receives data bits according to time sequence, and completes the writing of channel mode/channel data and the reading of conversion results. The plan is as follows:

Unsigned integer Tlc2543L (unsigned character channel)

{unsigned char i, chch = 0;; & ltbr & gt unsigned int xdataxxx = 0; & ltbr & gt unsigned int xdatay = 0; & ltbr & gtCS = 0; & ltbr & gtChch = ch & lt& lt4; & ltbr & gtY = chch& ltbr & gtY & lt& lt=8; & ltbr & gtI = 0; & ltbr & gtWhile (I<12) < br & gt{ if((y & amp; 0x 8000)= = 0)& lt; br & gt{ if(data in _ a _ bit 0()= = 0)XXX & amp; = 0xfffe& ltbr & gtelse XXX | = 0x 000 1; & ltbr & gt If (I! = 1 1)XXX & lt; & lt= 1; & ltbr & gt}

other

{ if(data in _ a _ bit 1()= = 0)XXX & amp; = 0xfffe& ltbr & gtelse XXX | = 0x 000 1; & ltbr & gt If (I! = 1 1)XXX & lt; & lt= 1; & ltbr & gt}

y & lt& lt= 1;

I+= 1;

}

CS = 1;

Return (XXX);

}

The serial data transmission module includes a serial initialization subroutine and a data transmission subroutine, and each subroutine is as follows. Among them, data transmission adopts query mode, and it can also be changed to interrupt mode conveniently.

Void rs232init()

{ TMOD = 0x 20; & ltbr & gtth 1 = 0x FD; & ltbr & gttr 1 = 1; & ltbr & gtSCON = 0x 50; & ltbr & gt}

void receandtran()

{unsigned char da& ltbr & gt and (! RI)& lt; br & gtRI = 0; & ltbr & gtda = sbuf & ltbr & gtsbuf = = da & ltbr & gt and (! TI); & ltbr & gtTI = 0; & ltbr & gt}

The C language program used by the upper computer to receive data includes initialization subroutine and receiving subroutine. Each subroutine is as follows:

void cominit(void)

{

outportb(0x3fb,0x 80);

outportb(0x3f8,0x 18); /The baud rate is 9600bps*/

outportb(0x3f9,0x 00);

outportb(0x3fb,0x 03); /8 data bits, 1 stop bits, no parity */

outportb(0x3fc,0x 03); /* The modem control register is set to enable DTR and RTS outputs */

outportb(0x3f9,0x 00); /* Set the interrupt enable register to disable all interrupts */

}

Void data_rece(void) /* Query mode data receiving subroutine */

{

And (! kbhit())

{

And (! (inportb(0x3fd) and amp0x01)); /* If the receive register is empty, wait */

printf("%x ",in portb(0x3f 8)); /* Read the result and display */

}

getch();

}

Application of intelligent serial acquisition/transmission module in PCR instrument

In the circuit design of PCR instrument, there are many signals to be detected, including the temperature detection of thermal cover, radiator, cavity, air flow and optical signal. In order to simplify the circuit, save the cost and reduce the size, TLC2543 of SPI bus is selected when selecting the A/D conversion circuit. The chip has as many as 1 1 analog signal input terminals.

conclusion

The intelligent serial data module introduced in this paper can be directly used in any microcomputer control and detection system to replace the original analog-to-digital conversion design. Practice shows that the module has low power consumption, high sampling accuracy, good reliability and simple interface, and has high practical value. The software and hardware of the intelligent module have been successfully applied to the design and practice of the life science instrument "thermal cycler". The instrument is easy to use, simple and feasible, saves cost, and can meet most data sampling applications. Source: www.lw372 1.com