Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Chapter 7 To communicate between LabVIEW and the single chip 8051

Overview

Previous chapter we have completed a 8051 serial port experiment, this circuit already has

the prototype with serial port interface of general remote instrument, as long as to expand I/ O

port of 8051 in order to connect with lots of sensors or control systems. This is a ideal practice

circuit for LabVIEW serial port communication, due to 8051 user friendly development, low price,

and the flexibility of program design. The practice of the chapter is constructed under this

criterion, to use internal timer of 8051 continuously accumulate the counter, and to make

command interactive mode of LabVIEW read out value from serial port in order to simulate

operation of a general instrument.

Objective

„ To writing an 8051 program starts the internal counter, and to construct an interface of

interactive command simulate the output data of the general measuring system.

„ On LabVIEW to design an interactive program communicates with 8051 in order to

receive and display the data.

Keyword

„ Interactive command control

„ Explanation of control
Path ControlshText ControlshText Ring
The control item of Text Ring, text input to be divided into a few
items, and with the order of sequence number represents each
Explanation
item, starting from 0 to count. The user can arbitrarily add the
contents of its item.
Path ControlshText ControlshText Ring
The indication item of Text Ring, with same function as control
Explanation item explained above, only change their function from the control
into the indication.
7-1
Path ControlshGraph IndshWaveform Graph
Waveform Graph, can display the curve of chart from the numeric
Explanation data of variable, and have the capability of memory function,
almost the same as the paper tape for recording signals.

„ Explanation of function
All FunctionshInstrument I/OhI/O
Path
SerialhVISA Configure Serial Port
Explanation Initializes the serial port specified by
VISA resource name to the specified
settings
VISA resource name specifies the
resource to be opened.
Input The parameters need initialization
such as: the baud rate、flow control etc
Output If there is a bug, output the error code
All FunctionshInstrument I/Oh Serial
Path
h VISA Write
Explanation Writes the data from write buffer to
the device or interface specified by
VISA resource name.
VISA resource name specifies the
resource to be opened.write buffer
contains the data to be written to the
Input
device. error in describes error
conditions that occur before this VI or
function runs.
dup VISA resource name is a copy of
the VISA resource name that VISA
functions return. return count
Output
contains the actual number of bytes
written. error out contains error
information.
All FunctionshInstrument I/Oh Serial
Path
( VISA Read
Reads the specified number of bytes
from the device or interface specified
Explanation
by VISA resource name and returns
the data in read buffer.
VISA resource name specifies the
resource to be opened. byte count is
the number of bytes to be read. error in
Input
describes error conditions that occur
before this VI or function runs. The
default is no error.
Output Read in string and output of error code
Path All FunctionshNumerichConversion
Converts a string into an array of
Explanation
unsigned bytes.
Input string is the input string the function
converts.
Output unsigned byte array is the output
array.

7-2
Path All Functions hArray h Index Array

Returns the element or sub-array of


Explanation
n-dimension array at index.
Input n-dimension array can be an
n-dimensional array of any type
index 0..n-1 must be numeric. The
number of index inputs matches the
number of dimensions in n-dimension
array.
Output element or subarray has the same
type as the elements of n-dimension
array.

Brief

In many situations, the communication model of command interactive mode has been

widely used in microcomputer-based automatic control system. The main function among them

is either the boot of control command or the feedback data return. For example, the

communication for the PC peripheral equipment also use command interactive mode for data

transmission, and the MODEM have a command set (AT command) to switch information each

other. This experiment will use the previous chapter 8051 serial port experiment to build a virtual

simulation control system between the PC and 8051, and use self-defined command set to set

communication channel.

Here shows the whole practice structure, and the function of this practice system is shown

as follows.

Command GUI interface


Interface

set

Serial port PC installed LabVIEW


& with serial port

8051 serial port experiment

7-3
General speaking, the design of command is just a series of numeric figures composition,

the reason is just to take “information” derived to machine that did not understand the

information as we do. These kinds of communication mode for machine can save the cost of

communication, the shorter the better. The meaning seems to be the instructions of assembly

language.

The setting of our serial port is defined with each 8 bits as one unit of transmission;

therefore if the instruction set has the width of 8 bits we will have 256 sets instruction (28 = 256)

to assign, in the case of learning it is enough for use.

There is an example of simulation instruction sets to assign as following.


Sending Return
Name of instruction Hexadecimal Return value The meaning of return
Someone in? 01H F0 H Yes!
How are you! 02 H F1H Fine, thanks
Take the side dish 03H F2 H Yes, please.

If you have chance to observe the contents of communication protocol of some automatic

control and measuring system, you will find it much alike the general dialogue of people most of

the time. In fact instrument is the same as people organization (certainly, the instrument is

designed by people), so between the instruments they sent message and received information

frequently, it is similar the example that we mentioned above. Except the message and

information are all restricted, they couldn't announce as freedom as people, they don’t speak too

much and couldn't create the new “words" that people didn’t save inside it. Therefore all these

message are assigned to the restricted numeric numbers to correspond, thus those instruments

use these numbers to communicate each other. In fact each value represented by the instruction

will vary the meaning for different systems; it depends on the user how to define it. Therefore,

the same value but at different systems could have different meaning to explain. OK, are you

ready? Start to do experiment.


7-4
Practice 7-1 Command interactive

‹ How to let the LabVIEW interactive with 8051?

First, in order to explain the simple concept of instruction set we design a simple

instruction table command at 8051 inside.

Sending Return
Instruction Value Return value Meaning of return
01H On-line
Is 8051 on-line? 3FH
None Without connected to 8051
Other value 00H No meaning

On the table the text of instruction is used for people understanding, and the computer only

recognize the value, return back is still a value. We just use LabVIEW human-machine interface

to transfer value into text in order to be understood by people.

‹ How to plan an 8051 program?

What is doing inside the 8051 program? From the following flowchart it is easy to understand.

Start

Some initialization

no Is there any
input?

yes

no 3FH?
Output 00H

yes

Output 01H

7-5
This is the 8051 program that has less modified from program of chapter 6 could achieved

the goal.

The source code is as follows:

org 0h ;Program initial


jmp init

org 30h
init: ;Main program entry point
mov sp,#40h ;Reset stack
call set_bps
clr ri
clr ti
mov r0,#30h ;Setting relative addressing register
start:
jnb ri,$ ;Waiting for input
clr ri
mov a,sbuf
cjne a,#3fh,a1 ;Is the input equal to 3FH?
jmp a2
a1:
mov sbuf,#00h ;Input ≠ 3FH,output 00H
jnb ti,$
clr ti
jmp start
a2:
mov sbuf,#01h ;Input = 3FH,output 01H
jnb ti,$
clr ti
jmp start

set_bps:
mov scon,#01010000B ;Setting serial port

mov tmod,#00100000B ;Setting timer 1


mov th1,#FDH ;Setting timer 1 reset value,offer serial port
communication rate
setb tr1 ;Start timer 1

ret

7-6
‹ How to construct LabVIEW interface?

1、Put a Text Ring on the Front Panel.

2、Please add the following new Items into Text Ring. It doesn't matter how many items

have we added, but remember that it must contain "Is 8051 on-line?" this one, it

means what we want to input the instruction.

3、To create a new Case Structure in the Block Diagram, and connect it with Text Ring

that has just create, and Add Case as many as Items of Text Ring, in order to one to

one correspond. Each Case need to put a String Constant. The display mode of

each String Constant should change to Hex Display, so it could display

hexadecimal format.
7-7
Please remember that the Case which correspond with the item "Is 8051 on-line?"

of Text Ring must put into the value 3FH , this is what the instruction we need. The

constants of the other Case can put any other value, remember don’t repeat with the

value 3FH .

4、Please add a Stacked Sequence Structured and put a VISA Configure Serial

Port.vi in it. To set the parameter of termination char is 1, which means the width

of the instruction set is one byte. Therefore we set the termination char as 1 and the

VISA resource name setting is pointed to your PC COM port for this experiment.

(Here is setted to COM1), setting the baud rate to 19200.

7-8
5、Adding a new page frame after the step 4, we put a VISA Write.vi on it. Connect the

“write buffer” parameter with the Case Structure output of step 3 together. Similarly

the port number setting is pointed to your PC COM port for this experiment. (Here is

setted to COM1).

6、Here is the last step of program block diagram. Put the VISA Read.vi on it first, set its
String to byte array
parameters, and remember to set “byte count” as 1, which means it will be read back

1 byte, and next the output of VI is connected to (String to byte array), why to

do so? Next steps will be explained. Now take out the first element from the new

transferred array.
7-9
7、In the step 6, the new create interface is an indicator item of Text Ring, inside this

Text Ring will be set a few items, and how to do those settings we has practiced in

the step 2. Here the purpose of Text Ring is how to display the return value that is

sent back from 8051 instruction set into the message that people can understand. As

you know what the “VISA Read.vi “read back is text constant, it must be transferred

into value so that the indicator item of Text Ring could display the constant correctly.

This is why we must convert VI (String to Number Conversion) in the step 6.

7-10
8、Finally put the correct message text inside the indicator items of Text Ring on the

Front Panel. What the return value of 8051 instruction is that 00H represents “No

meaning “and 01H represents “On-line”. Therefore the first item of “Text Ring”

indicator is displayed “No meaning ", and the second item of “Text Ring” indicator is

displayed “On-line". Please pay attention, it must be in order, otherwise the output

message will be upside down.

9、OK, let the 8051 serial port experiment and transmission line for ready. Run to

communicate, at first input any instruction that is not what we expect. Yeah! Really

the answer is no meaning.

7-11
10、Next input the instruction “Is 8051 on line?” and you will get the return

response as “On-line”. Bravo!! Success.

The end of practice 7-1

7-12
Practice 7-2 To simulate temperature measuring system

According to the structure of the above practice, this new practice simulates a temperature

measuring system to output the data by means of 8051 internal timer 0.

In the instruction sets of practice 1 please add a new instruction:

Sending Return
instruction Hexadecimal value Return value Meaning of return
01H On-line
Is 8051 on-line? 3FH
None Without connected to 8051
Get the value of timer 0 2BH Arbitrary value The value inside Timer 0
Other value 00H No meaning

Now we can use 2BH to call 8051, we hope to get the value inside the timer 0. Therefore

we have to modify the 8051 source code to add the function of timer 0, and the response of

calling command 2BH .

‹ Program of 8051
The program here is also modified from 8051 program of practice 1 to add extra

code. Start

Initial ization

no Is there
any input?

yes

no no
Output 00H 2BH? 3FH?

yes yes
Output the value
Output 01H
inside timer 0

7-13
Source code of 8051 program is as follows:

org 0h ; Program start point


jmp init

org 30h
init: ; Main program entry point
mov sp,#40h ; Reset the stack
call set_bps
clr ri
clr ti
mov r0,#30h ; Set the relative addressing register
start:
jnb ri,$ ; Waiting for input
clr ri
mov a,sbuf
cjne a,#3fh,a1 ;Input = 3FH or not?
mov sbuf,#01h ;Input = 3FH,output 01H
jnb ti,$
clr ti
jmp start
a1:
cjne a,#2bh,a2 ;Input =2BH or not?
mov a,tl0 ; Input = 3FH,output the value of timer 0
mov sbuf,a
jnb ti,$
clr ti
jmp start
a2:
mov sbuf,#00h ;Input the other value,output 00H
jnb ti,$
clr to construct
‹ How ti LabVIEW interface?
jmp start
The program of LabVIEW still need some modification.
1, Please add a new Waveform Chart on front panel.
set_bps:
mov scon,#01010000B ;Setting serial port

mov tmod,#00100010B ; Setting timer 1


mov th0,#00H ; Setting timer 0 reset value
mov th1,#FDH ; Setting timer 1 reset value,offer serial port
communication rate
setb tr0 ;
setb tr1 ;Start timer 0
setb tr1 ;Start timer 1
ret

7-14
‹ Program of LabView

In the LabVIEW Just modify from practice 7-1 program

1、Create a Waveforms Graph in the Front Panel of Controls Graph Indicators

2、On the Text Control of the Text Ring, create the Control and Indicator item please

add a new choice item on each one to provide the space for new instruction.

7-15
3、Similarly in the Block Diagram we also add a new Case to put the new instruction :

2BH , and setting the baud rate to 19200.

4、Adding a new page frame after the step 4, we put a VISA Write.vi on it. Connect the

“write buffer” parameter with the Case Structure output of step 3 together. Similarly

the port number setting is pointed to your PC COM port for this experiment. (Here is

setted to COM1).
7-16
5、In the last page frame of Sequence, erase away the original object, and put into Case

icons. Setting those two Case, one is default, the other one is“+". ASCII code for

“+" is 2BH .The selecting input of Case is connected as follows.

6、At the default of new Case we put into the original block diagram of page

frame 2.
7-17
7、At the ” +” page frame of new Case we put into the following block diagram, and link

the Waveform Graph of step 1 into here.

8、OK, let the 8051 serial port experiment and transmission line to PC

for ready. Start to communicate, first input the query “Is 8051 on-line?” to check

whether 8051 exists or not.


7-18
9、Very Good. Next ask value of timer from 8051, that is input the query “get the value of

timer 0”. If there is a response, click the keypad one more times to get more data.

The end of practice 7-2

7-19
Exercise and discussion
1、In the practice 1, the instruction sets what we designed is regarded the return

value “00H” as no meaning. It is just for convenience to arrange it, we could

have another arrangement to reach the same goal. In many situations, people

use “FFH” as the return value for no meaning response. Try to change

LabVIEW block diagram in practice 1 and modify the program of single chip

serial port experiment circuit in order to take “FFH” as no meaning response.

2、In practice 2, we use timer 0 0f 8051 to simulate the output data generated by

the temperature measuring system. Can you try to connect it with a real

temperature senor into 8051 circuit to get real data of temperature?

7-20

You might also like