The digital voltmeter based on STC89C51 one-chip computer is designed

0 foreword

Already there are a lot of types and styles in design and development of the digital voltmeter, the traditional digital voltmeter has one’s own characteristics, they are suitable for doing hand dipping on the scene, and should finish long-range measurement and step forward the metric data, using the traditional digital voltmeter can’t be finished. For this reason, this text has designed the digital voltmeter based on that PC communicated, this table can already finish measuring machine format transmission, can measure machine format treatment through PC. So, the digital voltmeter of this kind is no matter on function and real application, have incomparable advantage of a traditional digital voltmeter, this makes its development both have a good prospect with employing.

The zero-one system forms

This system is mainly formed by two parts of hardware and software, the hardware mainly includes the data acquisition circuit, the minimum data collecting system of the one-chip computer, the interface circuit of one-chip computer and PC,etc.. The software mainly has data acquisition procedures of one-chip computers, one-chip computer and signal procedure of the upper computer, and upper computer data handling program.

2 data acquisition circuit theories

The metric voltage type of this new-type digital voltmeter is the direct current, the measurement limit is 0- 5 V, the one-chip computer that the lower-position unit adopts is STC89C51, what AD transformed and is adopted is the most common ADC0809, can carry on communication through RS232 serial port and PC, in order to convey the metric direct-current volts data. It is the data acquisition circuit of this digital voltmeter that Fig. 1 shows. The design of the circuit has already minimized, namely has not made interface circuit with any additional logical device, can realize the one-chip computer changes the operation of the chip to ADC0809. ADC0809 in Fig. 1 is that 8’s modulus transforms the chip, there are simulation gating switches of No. 8 and corresponding passway that latch the decoder circuit on-chip, it is probably 100& mu to transform time; About s. In the circuit is employed, should appoint the communications link of ADC0809 first, after the external voltage enter the chip, STATR signal by high to low, begins to be changed on the pulsing negative edge ADC0809, the base pin EOC level becomes low at the same time, show that transforms going on, after transforming and finishing, the level of the base pin EOC becomes high, represent once to transform and is over.

3 software programming

The software program of this system mainly includes data acquisition procedure of the lower-position unit, visual interface procedure, serial port of the one-chip computer and PC of upper computer communicate etc.. The one-chip computer can adopt C51 programming, the upper computer can adopt VC ++6 to operate. 0 carries on visual programming, so, when the serial port is debugged, can rely on ” Debugging assistant of the serial port ” The tool, and efficient use, this tool, improves, the whole system efficiency.

3. An one-chip computer programming

The function played is to control ADC0809 to transform the data in the one-chip computer is in this system, and send the data transformed to the upper computer through the serial port. Because it is not very strong that the one-chip computer does the ability of data processing, so, send the transforming amount of data gathered to the PC, reuse the strong data-handling capacity of the PC, must publish the desired result finally. Because CLOCK of ADC0809 needs to connect the clock signal (generally connect 500 kHz) ,This clock signal frequency can be produced with the canonial resonator, can produce with TO or T1 mouth attached of one-chip computer too. For the minimization that is designed, that originally designed adopting is that TO mouth attached offer the clock signal. Its procedure is as follows:

3. 2 upper computer programming

The upper computer adopts VC ++6. 0 communication functions of realizing visual interface and and lower-position unit. VC ++ is programming language tools based on Windows operating system, can adopt API function to realize the communication with the lower-position unit directly, but this kind of method should involve much lower to set up, so, what this literary grace is used is that ActiveX technology that Microsoft introduces realize the communication of serial port, namely the utility program visits the ActiveX control with interface that the ActiveX control offers directly. Microsoft Communications Control (hereafter referred to as MSComm) The ones that are offered by Microsoft Company can be simplifying Windows and playing the ActiveX control of programming of serial communication, it has offered for utility program and received and dispatched the machine format simple and convenient method through the serial interface. Particularly, it has offered two kinds to deal with communication problem method: First, the incident drives (Event2driven) The method, second, inquiry method. It was an inquiry method that originally designed adopting, this kind of method is suitable for the minor utility program. In this case, after whenever employ a certain serial port of program execution to operate, check the intersection of MSComm and the intersection of CommEvent and attribute of controlling part constantly, in order to check, carry out result or check a certain incident take place. If the utility program is minor and establishing one’s own system, this kind of method may be more desirable. So more desirable to this design. MSComm controlling part has a lot of important attribute, among them several primary are set out in Table 1.

To the programming of upper computer, should establish a utility program based on communication frame at first, then insert MSComm controlling part, can be an Edit Box (IDC_EDIT_RECEIVE) is put on the resources of the communication frame Reveal the magnitude of voltage, reput two button controlling parts [begin to measure IDC_TEST) And stop measuring (ID_STOP) . Then make communication frame template, the mouse clicks and hits the right key, choose Classwizard, increase member's variable, set as IDC_MSCOMMl related member's variable m_mscomm CMSComm controlling part type, but IDC_EDIT_RECEIVE related member's variable m_receive is not a controlling part type, it is a number value type (float) . Later added the response function of news to the controlling part of two buttons and MSComm separately, this could play automatic adding in Classwizard.

While adding codes, will set up the attribute of MSComm controlling part at first, this can be added in OnInitDialog function. What this literary grace is used is COMl mouth, baud rate is 9600, there are not parity bit, 8 data bits, l a stop bit, receives and dispatches the data with the binary mode. Begin OnTest to measure button ') Add SetTimer(1, 500, NULL) under the function ; Turn on the timer every 500 ms and touch off a timer incident, and is stopping measuring the button OnStop ') Add KillTimer(1) under the function ; The function of the button is to stop timer incident. Then add WM_TIMER news. Can be in OnTimer (UINT nIDEvent) Have and add CByteArray bytoutArr; bytoutArr. Add(0xfd) ; m_mscomm. SetOutput(COleVariant(bytoutArr) ); (Adopt the transmission data 0xfd of the binary mode, 500ms sends once, data that lower-position unit will be transformed only after receiving 0xfd are sent back, this is equivalent to a simple communication protocol too.

Machine format receiving process (a focal point herein too) Can pass, finish by inquiring whether the way is checked to receive the incident to happen in the intersection of MSComm and news response function of controlling part. The concrete code is as follows:

void CCTestVotDlg: : OnOnCommMscomml ()
{VARIANT variant_inp;
COleSafeArray safearray_inp;
LONGlen, k;
BYTE rxdata[1024]; //Set up the byte array
CString strtemp;
if(m_mscomm. GetCommEvent 0 ==2)//Incident value is 2 Show that receives the data
{variant_inp =m_mscomm. GetInput 0; //Read the buffer
safearray_inp =variant_inp;
len =safearray_inp. GetOneDimSize () ; //Receive the valid data length
for(k =0; k <len;k++)
safearray_inp. GetElement(&k, rxdata+k) ; //Transform into the Model BYTE array
m_receive =rxdata[0]; //Entrust to value received
Float variable m_receive =m_receive/255; //The data received are (0, 255) During integer value
m_receive =m_receive*5; //These three steps get magnitude of voltage of 0 to 5V
m_receive =setprecision(m_receive, 3) //The function of this function is to keep the last three of the radix point
}
UpdateData(FALSE) ; //Upgrade the Edit Box, reveal the number value in the Edit Box
}

4 conclusions

The above-mentioned embodiment can well realize the function of the whole prototype machine in practice, in-service use proves, every index of this instrument can reach the desired effect. This text made the analysis that is focused on in using MSComm serial communication method, analyzed ActiveX technical strong function, sufficient flexibility and ease of use at the same time, have certain practice meanings.

Tags: , , ,

Leave a Reply