Professional Documents
Culture Documents
1111
1111
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
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.
Keyword
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
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.
set
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)
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
First, in order to explain the simple concept of instruction set we design a simple
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
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.
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
ret
7-6
How to construct LabVIEW interface?
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
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
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.
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.
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
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
7-11
10、Next input the instruction “Is 8051 on line?” and you will get the return
7-12
Practice 7-2 To simulate temperature measuring system
According to the structure of the above practice, this new practice simulates a temperature
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
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 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
7-14
Program of LabView
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 :
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
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
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
timer 0”. If there is a response, click the keypad one more times to get more data.
7-19
Exercise and discussion
1、In the practice 1, the instruction sets what we designed is regarded the return
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
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
7-20