Você está na página 1de 56

c 

  
  

On microcontrollers already discussed in previous issues zhurnala1.
Modern microcontrollers - a well-designed device, to significantly simplify the construction of
circuits. Very often, in their composition, they have built-in comparators, ADC, the network
module or USART radio channel RF.
For electronics enthusiasts and professionals who do not specialize in
microprocessor technology, the stumbling block could be the need to write
program, without which the microcontroller is "deaf and dumb." If the scheme is ready
device and boot file, the problem is simplified, but finished the scheme does not always
satisfied in full, and some residue of helplessness, stiffness remains.
By programming means writing a program code
assembler or high level language: C, Basic, Pascal ... But is this true?

Consider a specific and simplest task. Suppose we want to single out


the findings of the controller to set a high level (with supply voltage of 5 V,
it will be almost 5 B). After some time (pause) the voltage on this
conclusion of zero (low level). And pause. If all this is repeated
infinite, then this "easiest" case will use the controller
as a control device, for example, to switch the Christmas tree
garlands. Or to generate a square wave. Or it will be an indicator, an audible or
light. Or. . .
And, to programming, the program we have already written. Left her
implement.
How it will be implemented on, should help people who are starting
master microcontroller, to feel confident and get rid of hatred
programming.
There is such a computer environment to create and debug programs
microcontrollers, which is called FlowCode. There is a version of the program for the AVR-
production controller Atmel, a version for PIC-controllers
production Microchip. And there is a very useful feature of the program - the opportunity
export written for AVR-controllers, PIC-IDE
controller, and vice versa.
Installing the program is running normally. During installation, but
usual clicks on the Next button and agreeing to license the rights
should not forget to install an additional file of PPP (for version 3 of this
PPPv3), we need it, at least, to create a "word configuration. Program
there is a demo version, cut down the possibilities, but it is workable for
the manufacturer's website (http://www.matrixmultimedia.com), and in different versions
on the amateur sites. Although the program is designed for Windows, it works and
Linux under Wine, not completely, but at least sufficient for dating.
Below, the story goes in the annex to the microcontroller PIC16F628A, but the full
FlowCode version of the program is working with a very representative number of models and
everything said in the article is not related to the specific choice of model.
Novice to master microcontrollers I suggest in the first place to stop
your choice on the model, which can be quickly and easily acquire, there is no need
look for the cheapest, you're not going to be replicated by the device,
and for which we can quickly assemble a programmer or buy affordable.
So, the first launch of the development environment and debugging FlowCode.
Because when you write articles the program runs in Linux, can be
a slight difference in the appearance of drawings.
If you have already worked with the program, when running in the dialog box open
file, you can choose whether to work with the new file (Create a new
FlowCode flowchart ...), or will continue to work with the old (Open an
existing FlowCode flowchart ...), which can be chosen from the following 
Fig. 1. Program FlowCode

For those familiar with electronics, a further order of the work should be
sign: there is a chip that should properly bind a network of wires in
a whole, small difficulties arise only when necessary
chips have to go to the documentation. In this sense FlowCode equipped
tip, and there are examples in the folder «Examples». Very useful to look into this
folder.
Problem described above can be brought to the test on the breadboard,
where the microcontroller will control the LED, soldered to, say,
zero Port pin A (just in case, through a resistor), and let the LED
flashes once per second.
On the toolbar on the left, where the elements of the command is
button with the letter "O" from the word output (output). If you hover your mouse over the
this button, the lights and tip, Output. Hooking command (press
the left mouse button when the cursor is an icon and hold
keys, move the cursor in the working field circuit), drag it to the lines of communication between
ovals Begin (top) and End (end). The cursor looks like
stylized icon that appears on the left and the arrow-pointer.
In passing, we note that user interface is standard for the operating system, Windows, and all
operations very similar to
in other programs.
4c  !
  
c  ! "
"#! $!  %  &

Fig. 3. The initial view of the program


Šero in the header of the state of port A implies that all findings are
in a state of logical zero (low voltage) or that they will
set to 0.
Flashing something - a change the state, but that flash was seen,
need to pause. Such an element (an icon on the left toolbar to
lettered «D») Delay (delay) is. Drag it and paste it below the first
Team Output. By default, the delay specified in milliseconds. But in the properties
this element can change the unit of measurement. Double-clicking the left
mouse button on the item at work opens a dialog box where
Many properties are given: the name of the program element, the value that can be
set using a variable, and unit of measure.
Name of the component is not so important, but when creating large programs
should consider using this feature, as well as names of variables to
facilitate reading and understanding the program themselves and others.

Fig. 4. Properties dialog element Delay


Now it suffices to select seconds, to turn in a millisecond
second. Following a delay of 1 second to add another command Output, as
and for the first time, but now, by double clicking the left mouse button on it at
working field circuit, open its properties dialog box:
Fig. 5
Changing the properties of output port A dialog box


#'! (    "&")(%% #!!" ! 

 
c(!
   $(%%   #! 
 $!* $#"" ) "#! 
 #"

  
 # #)# +
,c"#!
 !    ! (!!" !
 
! !
 (#  )%  ! -"%#
    !#! 
 
) # 
!
#
 #)# #$!  ""%!!#"  

)
#!
 (! %( %
# !# "! 
 ( #
  !#)# c !%!! !(
)"# ! ##! !.!  
( $)
!

 ( "#)# ( !)  

#(   
(
  )
# "  +4 , #(

  " " + % , # #


%!#!#(" (#!#$  ! 


 ##)# (   
(#
!

  !
 #)# 4 %##!!"  !% $#)# (
 # )
Fig. 6. Program in FlowCode with the cycle

(%!% +  % # #,(!  


 (
#!#$ % $/  4 %!"
"
 "(" #!"( #"
#0" ! 
%" ! "
# #$!#123( $)
) (

)#$4% (  (" " +  )" " ,


*! 4" +#   ,# #$!  
"%!"  # +*,(!


! *!%
  "4 !*
c*( # ) 
#%!)"(# #  
-" &!
"! !
 (

# #$ 5"#) !# #   !   )!!
 6 !  4 !  
 (#"
  #  ( 5"#)7 46 (!% % 
%#!"
"  "
)
(!"  %!
# #$ 5"#)!"! !
# #$
(
%! ( #(# #$ 5"#) )"(")
 " # #$ 5"#)$5" ' 46(!%8#
"!  % " 9#%!"
  # #$  
4 !  
 % " "  )#!! 
 c
#"
"( %!  " !)%  
)
!## " 
 c  !## !#8::7:;( 
 )  

Fig. 7. The first debugging program launch

As you can see, write a small program for the microcontroller


much easier than gathering scheme for a analogue, digital, whether the elements
that causes the LED to blink. But this program is easy to correct,
to make it perform more complex operations.
If you bought the program FlowCode, it may be bought and programmer
working with her. In this case, you can directly insert the chip into the socket
programmer and-translated the first program to load it into
microcontroller to move it to a development board and make sure it works (the word
configuration, which is discussed below, for the PIC16F628A take 3F18h).
You can use an external program to program
microcontrollers, for example, PonyProg or ICprog. Scheme programmers enough for them
easy even for beginners assembly. For PIC controllers are inexpensive
Programmer EXTRA-PIC, which can be ordered by mail at the agency "Dessie".
Today many people use notebooks that do not have any COM or LPT port
Therefore diagram below to connect nowhere, but perhaps converter USB-
(COM or LPT for other programmers) can do it, though better
consult with those who did or tried to do
it.
Scheme in the figure below is designed for programming only some
PIS models controllers. For the first experiments, it is usually sufficient
requirement for the programmer. A remake scheme, when there will be work experience and terms
interest to extend, will not make much effort.

The programmer only a small and fairly easy to use, requires no


deficient parts. To build enough piece of breadboard. If
Šener diode D6 to replace a similar voltage to 5.1 and add two LEDs,
Yes AL307A in direct placement (or one LED and diode with
appropriate voltage stabilization), the application process to the programmer can
monitored visually. The first steps in this direction, at times, appear
not as successful as hoped, and no additional indication will not be
superfluous.
My programmer is connected daisy chain cable about a meter in length to
it was convenient to work at the computer, the COM port. It looks like this:

Fig. 9. Appearance Programmer


Before programming a chip, a program from the previous section
the story you want to turn into a hex-file. This is the file that is loaded into
program to work with the programmer, and which will go into the microcontroller.
Penultimate key main tool menu with a hint Compile
to HEX, as seen from the figure, must perform the translation, but in a folder
program will be required hex-file. If at my disposal was
programmer is connected via USB to a computer and knows how to "talk" with
FlowCode, then the next button is the main tool menu icon micro-
Fig. 10. Broadcast program in hex-code
At our first meeting with the procedure of creating a program for the microcontroller
You can not worry about the kind of program, content received "by
default names, but in future it may interfere. When you look at previous
figure is difficult to understand the purpose of instruction. This is easily fixable. Double-clicking
on command opens a dialog box where the Display name can be written
that later will help the program easier to read. Better if it would be
names in English, but you can do on Latin for yourself friendly
the name of the item.
Besides being able to name elements of the program easy to understand
way into it you can add comments (also better than Latin). To insert
Comments are using the latest toolbar button commands. All comments
should be ignored when compiling the program, and from this point of view of language,
which will be written comment should not affect the work
program. You can experiment with Russian commentary, but
Beware that this may cause problems.
Fig. 11. Change the name of the program element
Not to return to the issue of appointment of panel elements, I will
descriptions of the panels.
The first left-hand toolbar - this is the command bar.

The list of teams (from left to right in the figure, top-down, the
run):
Input (input), Output (output), Delay (pause), Decision (branch)
Connection Point (two points of connection), Loop (loop), Macro (macro)
Component Macro (macro component is added to the program), Calculation
(Computing), String Manipulation (string operations), Interrupt
(Interruption), C Code (the block of code in C language), Comment (comment).
The second instrument panel for additional external components.
Fig. 12. The toolbar commands
Fig. 13. The toolbox of additional items

Components (from left to right)


LEDs (light emitting diodes), Switches (switches), LCDDisplay
(Liquid Crystal Display), ADC (ADC, if there is a port of the ADC), LED7Segl (seven-segment
indicator), LED7Seg4 (block of 4 seven-segment indicators), Buggy (component
toys), followed by a number of standard interfaces TCP_IP, Bluetooth, RS232,
IrDA, AddDefines (add definition), LinMaster (leading to local
net), Custom (custom component), EEPROM (reprogrammed memory), Alarm
(Security device), Thermometer (Thermometer), PWM (Pulse Width
modulator), SPI (serial external interface), Webserver (web-server), CAN
(Network Service Access), KeyPad (keyboard), LinSlave (slave in
Local Area Network), FormulaFlowCode (components of the game), I2C (bus connection between the
IP).
FlowCode program allows you to quickly create programs rather
interesting devices.
We'll see how easy it is to upgrade the program to generate a square wave
with a frequency of 0.5 Hz. We complicate it:
ͻ Introduce two buttons controlling the frequency.
ͻ Use these buttons to double the frequency and reduce by half.
ͻ Display the frequency on the seven-segment display.
Introduce two buttons to control on a program meant to add
two software element input (Input). But after dragging commands
working field and attempts to close the properties window command displays the message:
487/
 4 %

 
" )% $%!  <""!  # 
#   "!$)  
4 %( $)
  !" !!%! 
 " !
 c !"!4 %
# #(
# #   
  ("  
/ !$)!/ 
 %%  !
" 

#   !!$)c%  (%!#!

!  %%%(%! ! %  (  %!#!
!==( -)  )
"#
 ) 

Fig. 15. Creating a new variable in FlowCode


As is often the programs are not the only way to create
variables. In the main menu under Edit there is an item Variables ..., where you can
open a dialog box with the variables and create just the right
variables. Later, when the need arises to work with established
variables, they can choose from a list or properties dialog software
element or the dialog of working with variables.

48>*  %!  


/ !?   " !/ 
   
/   
"4 !#
" (! " (
 #   + % ,!
 !
 $
  %&
Fig. 17. Program with input elements
Input elements in a program outside the loop. This is not the final result, but
where and how they are placed, can consider later.
In order not to overwrite many times, the same program fragment
Programmers have long come up with such convenient means as a subroutine, or
procedure or function, and in this case, program element Macro.
Drag it to the program elements below Input. He appears in the program,
as Call Macro (macro call), and double-clicking on it opens a dialogue
working with macros.

48;*  % $%!# 


-" % # + %# ,(!$(
 # !# ) "
Fig. 19. Set the properties sub

! !1" 3! %# &:  ) " !# 
c%! =@"#(!
1 53 $% 
"!
#" 
"#!#"  %)+   ("" )!

,c

   5"  !!   1 5A#!3(" 


 "  ((  )(!  "! (
 $  ! 
4' 
  !" "
%)"#   ! #)#  !"
" !
 
" " )"() (!! !
"!(# #$!  ""(# # !)"%!(
 ) !" #"+#",(!% $  
"(# #$! $
   #$-:(
 %

 (  )(!"(#!/+ ,


" " $ $!
  $! ## % $
!$"!%#!! 5"#) !"   ( "!  
##"(! "   
  ))#!! ! 
"
!   (!

  
"+" :# #$!  (!!# 
* ) ",(% 
#!" =8=!  1 5A#!3(# )
  .! !
 #=$)# 
 =(#  
Pre-add in the main program (from which the deleted cycle) after
Input two elements the new element, called Calculation
(Calculation). Its properties define the desired initial value of frequency
multivibrator. That is, the initial duration of the pauses.
A slight digression. Previously, it occurred to me that the chip looks like
accustomed to when she left inputs and outputs on the right. And this has led to
that the yield has moved to port B.

48 !  5"#) !"   


#!#$(
)# #$!"123 

  !
 ("!"*
 -c(
%  
Fig. 22. The line of LEDs
The first button on the main panel LEDs (O) - to access the properties through
pull-down menu where you can select Component Connections ... and replace
bind to the port.

Fig. 23. Change the port of registry "LEDs


After the changes the program starts checking key
Main toolbar FlowCode.
Fig. 24. Check the operation of sub
Check finds no difference in the program compared with
previous inspection. And yet, until an illness is not running, the programs it happens,
Draw another diagnosis.
The change in frequency, in effect, changing the value of the variable «freq_ch». When
Pressing the button "more", this variable must be divisible by 2. Check this out.
Add the first element Calculation second similar. And in it we write
freq_ch = freq_ch / 2. Run the program ...
... To see if something goes wrong, as it should. The program now
looks (main program):

494 !
 !
*  !5"#$ )(  $( :
"#  -"! 
%)#!#$("!$!
  !
  1 5A#!3(#!#$%!!

%!" #
"# " $
  ()("
"+!  


 !
 -,!(# #$! !""!
 ! 
:%"# #$! - $
"#!

 
)%%    !  ##

4>$ $ )"#!




!  !  


6 !  !!#(#!!)
 
  + ,c! " =8=(
8'''c!#! "!

  
"
# #%(  %
  5" 9''!*
"  ) $ )
#
.!#  "
 
"   .!%
" +  !%"
#  ,c(  )( " "!#!
#!! 5"#)  "" "   
B=4C%!
 !
 ##4 %
 !
    #!"
 
  ( "
 # )! 
 %!"    
!   (  %#!( "(
$" 
!
  
)
 )
#   5"#)
?!!!%D"&
 $
+ !"" 
- $
! 
%",!# #!
!
 
("   :
"    ! $
c%! !

! 
#%! !#:
"
  ":
 : +!
,#)# #!
=!= !

 $
(!
     " 
!  %
  !%5"#$ )  !
!  !c!  
1
3+ 
( 
,-   !" "% 
 "=8=!!# !.!  


E8(! !" "% !
   "='=
%% " "  
it, which can be verified using breakpoints, creating them in
routines and beyond.

Fig. 28. Revised program fragment


The second way - to poll the keyboard routine. However, in this
meaning sub is completely lost, leaving nothing program. However,
to the contemplation of the structure of the program, you can return later, but now Debugging
program reveals one more thing: changing the variables "toga" and «less», I think about
increasing and decreasing frequency, and me with the pauses, that is,
period. All up "to the contrary." Timely notice. Change (replace
operations on the reverse) is a pair of clicks.
Let's move on. I check the keyboard (the "toga") condition if
more = 0, as conceived "tighten" input resistors, and click
"To land" them. However, the program FlowCode external element in Switches
open position leaves the entrance to a state of "O", and for the closure of files for input
"1." Urgent fix (and do not forget to return to the original version before
firmware!).
There is another solution to the problem of falling into the trap of an infinite loop -
use interrupt. I would like to try it, but while I carefully
make changes in the orderly sequence "of his mistakes on the horizon
(Mentally) loomed another issue.
4F #" "
.!!
 !
  !!(!
  
 
!! G)#!! 5"#)+ : ,:%!
     )":)"!! %   
! !!
 "=! "!
"=.! !%= 
!
"(
)!$) $-"%!%
" !   ()(! 5"#)!  8:8'$46(

("    "($
  
# ! 5"#)*" ! ! !$)(   
(
#(!
 # !$) $)
4 !  (! 
   )
!#().!)
-#" !"#!"#% "  6c!

%)"  6:
"  !
 "(
 !#!(#(  
"(  )!#
c!  ! !$
"!  +
 c,("
"
!+
 -,%(
 !
(-"   !!
## # !#!

#4%
 
 #(  6! 

 :
 #"  
 ("!  )
 ! 4 %
 5"#$ ) ).!!###(
 %) )

   #(!


# "
#! )!  ! "("! #


#!c  ) " "  


 !

"## " )
 )!#" 
 (#  )

 :
 

 % ! !  (
4 %5"   !" 
c!# "#
 (

  )(  %


4H'=c 6)=
  #$
= 6)=
"(!   (! 5"  
"%!#!! 5"#)##!# %(%!

  # ! "  5" c! !%%   


! 
"#    # !" ".
 ##"#(()#  (%  %

 !
!!%" 
!= !=
%#! 5"#)<"#"! #!5"("#!%
 
"+%!= 6,!"(  )(! "
  # + # ,! 5"#)  %! 
"
- %("
  #/+@"#,LED at pin A7 to indicate the
process of changing frequency. Couple
Connection Point - this in a more familiar shape, the pair formed by the label and
operator Goto (go to label).
Fig. 31. Possible solution to stop the program to poll the buttons
And finally, you can go back to yet another solution to the problem
"Getting into an infinite loop", the variant with the interruption. For this is the program
element Interrupt. Assigning variables "toga" and «less» introduce into the
Interrupt handling routine.

 )"
!

   "
+ "
,(%#
    "


4H!  
  "
4 %
 "
 %(
 !
(  ( !
 

 %!    "


-0
!
 $!  !% %
Fig. 33. Program using interrupt

% "
!  " $

%!! % "  " "(!"

4H7 "
" "
"
   # #$!"%! 

(
(! $

Fig. 35. The work program with the interruption
If this interrupt (RBO / INT) was the only available mechanism
interruption, and even then would be to use: instead of two buttons
There will be three, two for the change in frequency, the third button, the changes to take
force. But ...
List of staff interruptions, the proposed program FlowCode, continues
interruption in RB Port Change (change of state interrupt port B). In
description of the microcontroller PIC16F628A can find that the change of state
inputs RB4-RB7 can trigger an interrupt, if enabled. Selection
inputs to connect to the buttons controlling the frequency is not fundamental
nature can be easily replaced input RBO on RB4, a RB1 for RB5. Not difficult
change the properties of the program element Interrupt.
Sub-Program "of the multivibrator remains the same. And in sub-
Interrupt added polls keys on the inputs B4 and B5.
If necessary, the work can make the above-described "antidrebezgovye"
appendix. But in general, we can say that in different situations better
use the methods of work, which give the desired effect, better job
device and well you know and understand, when you quite clearly
imagine why choose one or the other option. Similar considerations
You are guided, and in selecting the type and model of the microcontroller.

4   (%!D#!# #   ("


 %!
#  # 
"4 
  )   !" 
 !("!# 
 
" #"  ! "!(
# )# 


  !#   
4 !
  "
 "!% %
Fig. 36. A program that uses interrupts to change the status of the port in
Fig. 37. Sub-interrupt
In addition to changing the oscillator frequency, we intend to reflect this change
on the seven-segment display. Add it to the program, after removing
LEDs.

Fig. 38. Seven-segment indicator of a set of additional elements


As with other elements, the light has properties. To access
properties of the connection indicator is a button on the front panel next to the button
closing. When you press it from the dropdown menu to select item
Component Connections ...
By default, the anode of LED connected to pin 3 port A. In the sequel
This conclusion should be made in the program output and establish a state
high level.
Connection properties can be changed, for example:
Fig. 39. Changing the properties of the indicator
The anode is now connected to the output in. And in order to switch Switches not
prevented us to dispose of the conclusions of the port in our sole discretion, may change
its properties. Switches and LED line default service
port as a whole, that is connected to all eight ports conclusions. Often this
convenient. But not always. If there is a need for change, they can be
perform in the properties of the component.

It's enough for the desired bit port, select them in the box Bit:
select Unconnected (not attached). Microcontroller PIC16F628A has two
I / O ports of eight outputs each. Such amount to the first
opinion is more than enough, but as the complexity of the scheme was originally
distributed according to the output port are mixed, some of these conclusions have
used internally, quartz is connected to quite definite conclusions
for networking, too, are predetermined conclusions. When in doubt, as
affect binding of the findings when the program to byte-rulers LEDs
transitions or switches, unnecessary conclusions can be immediately disabled

47'!!

  !%#!
cC
 
##
!:
)!
 %
  #$= !"   ="!  
"
"
) ( 
#!   ""
"c
c   !
  !  !#  !"
 !

%!!#!

  #
#!% !
 ("#  !!
#" % $%!
# 
%!
)! 5"#) ()(!  8F$46( !

 !
  (%  #"#
5"#) (!"    %#! 5"#) 87+# 

" 
#)
" )
,
 ## #" ".# 
1# 3c!   "!!# (=%  ")= 

 <"#!("! #!(  


)! "
5"#)(
 $! +)!# 
='=,
Fig. 41. Modifying the program to work with indicator
At this stage, and the program more "grown up" to quantify, it is possible
check and correct mistakes if they are, we can add these fragments
as the frequency output from a given range, for example, flashing an "E" on
indicator. You can compare the design with one that could be obtained
without using a microcontroller. The device is simple enough, it can be
realized by using a digital counter and a clock on the valves. A
can be pleased with the progress and move on to the breadboard and external
design of the device.
Possible and to continue developing, introducing yet another seven-segment display for
expanding the range of frequencies.
The main thing you have started work with a microcontroller, creating the first device, and
you clearly that the creation of the second and third - the only question your desire.
After the first step, albeit a very simple program with a flashing light
diode, a first step, led to the end, that is, to a layout board
microcontroller and a flashlight, you will need a lot of ideas on how to
usefully microcontroller. By implementing these ideas, you will learn more about
Program FlowCode, learn to work with her. But perhaps a slight feeling of
dissatisfaction does not leave you. Connoisseurs, hardly it comes to
microcontrollers, with one voice say, need to program in assembly language.
474 " " ## 
 !#" . $#(c% 

 :%!D!  #
-" ! )"(!%" "( #" ( )"D =
!  =%!
  "("!4 %(
!)"  
 4 ( "" 
4!:  (!    !  <( 
"   


." !

 :* $
 )
$: !
!
  
!#  
 $ $



Fig. 43. The prototype program for broadcast in code in C language


The next thing we do, we choose the main menu section of Chip, which
click Compile to S. .. (Compiled in C). After successful
compilation can open the file in the C language in the notebook by choosing View S. .. Facebook
same section, Chip the main menu. A significant portion of the file, all lines
starting with a double slash / / is a comment, that is, the explanation for
reads the file, all comments are ignored during further translation of a code
program.
A lot of lines that begin with the icon "#" and the words «define» -
determine. This is a function word followed by what should be defined,
that with further translation by the compiler used by the program
FlowCode, the text of the program on the assembler and later in the download code, everything was
defined and identified. What exactly should be measured, depends on your
needs to be written as a program and compiler specific.
There is another function word «# include» - insert designed to
adding to the program of other files, most header files, which are actively
used in the C language. In this case, as it follows from the comments,
includes the functions necessary to operate the controller.
The program itself (not belittling the importance of everything else) looks almost the same
In short, as its graphical representation.
void main ()
{
/ / Initialize
cmcon = 0x07;
/ / Output: 1 -> PORT A
trisa = 0x00;
porta = 1;
}
To work with programs in C and assembler and PIS controllers I
I think the best development environment, MPLAB. A small correction, which depends
by the compiler and program in C, resulting in FlowCode,
will work in MPLAB. Similarly, we can proceed with the program on
assembler.

 )# % $#!


  4 %
) !% 
! )   )

#-"  # #" (! ) ):
 #$ !
 %  "(  !( %!!"! " 
 " :#( " (  (" #
#! ! 
 ## #   
I" (!#  6)%! !!
 )
# ##!% $4 % $

#)
# #   " % $? c.! #" "   ! "#
#   
."!!#   
  # 
   !
#
 !#( " (! #   #

 )# (   
( #  
/  #(!))  
#c ! 
! )% ! "(%! #  " 
#    (  #"#%!#"
-" : # ? cc!% $ #%" 

  # 7;9& )%% (


#   
 # # ##") " #( %  :#
 "   # 7;9!#
 
!
 "
D!%)"#"!? c  !
  !##" +%!
:# #$, #" +*,
!
   !  " ) $ $+"4 %,
  %&
Fig. 44. Program for Management Module

RKrome already familiar software components, after adding an additional


element RS232 (with additional elements of the dashboard), I
using the program element Component Macro, appearing as a subroutine call,
processing treatment to the embedded USART. Subroutine itself is already written
producer FlowCode, is only setting.
Fig. 45. Configuration dialog box component RS232
Selecting the box to Component: I needed extra element RS232 (0), selecting
window Macro: I needed the kind of work SendRS232Char (sending the symbol of
RS232), I create a new variable "operator" (such as Byte), which is a branch
program (to call the subroutine to send a character) with software
Calculate the component assign a value '1 '.
At this writing the program for the first module can be completed and check
the program.
By clicking on the element AB Switches (0), we can see in the window
Characters sent element RS232 (0) units appear (in the program are not removed
"Chatter", and every click can send a few units). Window
monitor this process in the program FlowCode black and green symbols, but they
poorly visible in the figure, so in a graphics editor GIMP (before
how to insert the picture) color inverted.
After specifying the configuration word (and select the controller model, recall,
main menu Chip) design is translated into hex-file.
Now create another program. It should take the '1'
USART and include LED on pin RB0.
Fig. 4 6. Check the program of the first module
47C!
  !#" ( #

Here, too, use a Component Macro for RS232.

B47;* - 
# "  H
 
 #

 H+',! #  
5"")
!#
=J=
!
"%%
! #! # ( %
!)  !  
" 
B47F
"%%(
%!%  #!#" 
 )"
!G"(!

 " !!*

-
Fig. 50. Verification of the second module

 ! #  #=


!=!
(!)"#
! #) ! " c(%!D <"#( #" (=%=

 !#     )!# = =("


! "#!
 +   .%,(%!#!# / "!
% ! #!
 " !
  # %
# #   
c! / "  %/8>4>;c# #    
# )   #
()""# " !#   &
498 " !  #   
Fig. 52. Customize second controller
Setting direction is reduced to a clock frequency, word configuration and location
Location hex-files.
Now, pressing the button in the assembled circuit, check that everything really
should work.

Fig. 53. Check the operation of the two controllers in the Proteus
So "talk" two of the microcontroller.
Will not disturb them.
Fig 27
Next start from page

Você também pode gostar