FLOWCODE GUIDE FROM RUSSIA

66
AS began to explore MICROCONTROLLER? Gololobov VN 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

Transcript of FLOWCODE GUIDE FROM RUSSIA

Page 1: FLOWCODE GUIDE FROM RUSSIA

AS began to explore MICROCONTROLLER?Gololobov VN

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 inmicroprocessor technology, the stumbling block could be the need to writeprogram, without which the microcontroller is "deaf and dumb." If the scheme is readydevice and boot file, the problem is simplified, but finished the scheme does not alwayssatisfied in full, and some residue of helplessness, stiffness remains.By programming means writing a program codeassembler or high level language: C, Basic, Pascal ... But is this true?

Consider a specific and simplest task. Suppose we want to single outthe 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 thisconclusion of zero (low level). And pause. If all this is repeatedinfinite, then this "easiest" case will use the controlleras a control device, for example, to switch the Christmas treegarlands. Or to generate a square wave. Or it will be an indicator, an audible orlight. Or. . .And, to programming, the program we have already written. Left herimplement.How it will be implemented on, should help people who are startingmaster microcontroller, to feel confident and get rid of hatredprogramming.There is such a computer environment to create and debug programsmicrocontrollers, which is called FlowCode. There is a version of the program for the AVR-production controller Atmel, a version for PIC-controllersproduction Microchip. And there is a very useful feature of the program - the opportunityexport written for AVR-controllers, PIC-IDEcontroller, and vice versa.Installing the program is running normally. During installation, butusual clicks on the Next button and agreeing to license the rightsshould not forget to install an additional file of PPP (for version 3 of thisPPPv3), we need it, at least, to create a "word configuration. Program

Page 2: FLOWCODE GUIDE FROM RUSSIA

there is a demo version, cut down the possibilities, but it is workable forthe manufacturer's website (http://www.matrixmultimedia.com), and in different versionson the amateur sites. Although the program is designed for Windows, it works andLinux under Wine, not completely, but at least sufficient for dating.Below, the story goes in the annex to the microcontroller PIC16F628A, but the fullFlowCode version of the program is working with a very representative number of models andeverything said in the article is not related to the specific choice of model.Novice to master microcontrollers I suggest in the first place to stopyour choice on the model, which can be quickly and easily acquire, there is no needlook 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 bea slight difference in the appearance of drawings.If you have already worked with the program, when running in the dialog box openfile, you can choose whether to work with the new file (Create a newFlowCode flowchart ...), or will continue to work with the old (Open anexisting FlowCode flowchart ...), which can be chosen from the following list.

Page 3: FLOWCODE GUIDE FROM RUSSIA

Fig. 1. Program FlowCode

For those familiar with electronics, a further order of the work should besign: there is a chip that should properly bind a network of wires ina whole, small difficulties arise only when necessarychips have to go to the documentation. In this sense FlowCode equippedtip, and there are examples in the folder «Examples». Very useful to look into thisfolder.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 LEDflashes once per second.On the toolbar on the left, where the elements of the command isbutton with the letter "O" from the word output (output). If you hover your mouse over thethis button, the lights and tip, Output. Hooking command (pressthe left mouse button when the cursor is an icon and holdkeys, move the cursor in the working field circuit), drag it to the lines of communication betweenovals Begin (top) and End (end). The cursor looks likestylized 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 toin other programs.

Page 4: FLOWCODE GUIDE FROM RUSSIA

Fig. 2. Adding an element of the program to diagramAfter adding the element Output chart takes the following form:

Fig. 3. The initial view of the program

Page 5: FLOWCODE GUIDE FROM RUSSIA

Zero in the header of the state of port A implies that all findings arein a state of logical zero (low voltage) or that they willset 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 tolettered «D») Delay (delay) is. Drag it and paste it below the firstTeam Output. By default, the delay specified in milliseconds. But in the propertiesthis element can change the unit of measurement. Double-clicking the leftmouse button on the item at work opens a dialog box whereMany properties are given: the name of the program element, the value that can beset using a variable, and unit of measure.Name of the component is not so important, but when creating large programsshould consider using this feature, as well as names of variables tofacilitate reading and understanding the program themselves and others.

Fig. 4. Properties dialog element DelayNow it suffices to select seconds, to turn in a millisecondsecond. Following a delay of 1 second to add another command Output, asand for the first time, but now, by double clicking the left mouse button on it atworking field circuit, open its properties dialog box:

Page 6: FLOWCODE GUIDE FROM RUSSIA

Fig. 5Changing the properties of output port A dialog box

Replacing 0 in the box, Variable or Value: unity, we will change the status of the findingsport.And, adding to the program one more break, we will almost reach its goals.It remains to make the LED blinks continuously. Such repeated executionprogram fragment in programming is called a cycle (Loop). And suchelement on the left toolbar there, the seventh button from the top. Ifadd it to the end of the program, it certainly will not lead to the goal. But we cantransfer all the commands inside the loop. Simply select an existing teamand move them into place.To select items to be by clicking the left mouse button when the cursoris an empty place on the program, hold down, drawrectangle that includes the entire program, except for the cycle. All that is now highlighted,you can drag to the line connecting the beginning and end of the While loop, marked byas the Loop. In programming, often used cycles, and are they differentspecies, for example, performed by a specified number of times (For. ..) or contingent,performed until until (or will be) satisfied certain conditionwhich can, in turn, checked before the next passprogram contained in a cycle, or after passage, etc.In the properties of the program cycle FlowCode can change the nature of the work cycle,if necessary.

Page 7: FLOWCODE GUIDE FROM RUSSIA

Fig. 6. Program in FlowCode with the cycle

So, we have written (or drawn or collected), the first program, and it is time tocheck if it works. Program FlowCode has good debuggingfunds.To start debugging, it is sufficient in the main menu, select Run andsection Go / Continue from the drop down menu or the main tool menuclick the icon «►», like any player, denotingplayback. However, before doing so, it is useful (or very useful) toDashboard Feature (second from left) click the firstbutton with a number of indicators (LEDs), the promptsthereto LEDs. That is now possible to start debugging. Flashing LEDdesignated as AD, is exactly replicate what you see, collecting breadboard.But ... a small addition: the pause that is entered into the program, depend onclock frequency of the microcontroller. The latter is determined by the methodOrganization of the generator. For the first experiments, most convenient to useinternal oscillator, its frequency is 4 MHz. So, how fast willswitch output for debugging and prototyping, should be aligned withclock frequency. In the main menu there is an item Chip section Clock Speed ...,where, in fact, given clock frequency. If you do not, but bydefault clock frequency is taken equal to 20 MHz, then wait 1 seconddebugging on the breadboard will turn in 5 seconds when using

Page 8: FLOWCODE GUIDE FROM RUSSIA

internal clock generator.For the first program will be useful to try to change the state of port A insecond team Output, blend with different numbers. They will all be displayedstates the conclusions of port A in a form that can be called the code 1-2-4-8, orbinary form.

Fig. 7. The first debugging program launch

As you can see, write a small program for the microcontrollermuch easier than gathering scheme for a analogue, digital, whether the elementsthat 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 programmerworking with her. In this case, you can directly insert the chip into the socketprogrammer and-translated the first program to load it intomicrocontroller to move it to a development board and make sure it works (the wordconfiguration, which is discussed below, for the PIC16F628A take 3F18h).You can use an external program to programmicrocontrollers, for example, PonyProg or ICprog. Scheme programmers enough for themeasy even for beginners assembly. For PIC controllers are inexpensive

Page 9: FLOWCODE GUIDE FROM RUSSIA

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 portTherefore diagram below to connect nowhere, but perhaps converter USB-(COM or LPT for other programmers) can do it, though betterconsult with those who did or tried to doit.Scheme in the figure below is designed for programming only somePIS models controllers. For the first experiments, it is usually sufficientrequirement for the programmer. A remake scheme, when there will be work experience and termsinterest to extend, will not make much effort.

The programmer only a small and fairly easy to use, requires nodeficient parts. To build enough piece of breadboard. IfZener diode D6 to replace a similar voltage to 5.1 and add two LEDs,Yes AL307A in direct placement (or one LED and diode withappropriate voltage stabilization), the application process to the programmer canmonitored visually. The first steps in this direction, at times, appearnot as successful as hoped, and no additional indication will not besuperfluous.

Page 10: FLOWCODE GUIDE FROM RUSSIA

My programmer is connected daisy chain cable about a meter in length toit was convenient to work at the computer, the COM port. It looks like this:

Fig. 9. Appearance ProgrammerBefore programming a chip, a program from the previous sectionthe story you want to turn into a hex-file. This is the file that is loaded intoprogram to work with the programmer, and which will go into the microcontroller.Penultimate key main tool menu with a hint Compileto HEX, as seen from the figure, must perform the translation, but in a folderprogram will be required hex-file. If at my disposal wasprogrammer is connected via USB to a computer and knows how to "talk" withFlowCode, then the next button is the main tool menu icon micro-

Page 11: FLOWCODE GUIDE FROM RUSSIA

Fig. 10. Broadcast program in hex-codeAt our first meeting with the procedure of creating a program for the microcontrollerYou can not worry about the kind of program, content received "bydefault names, but in future it may interfere. When you look at previousfigure is difficult to understand the purpose of instruction. This is easily fixable. Double-clickingon command opens a dialog box where the Display name can be writtenthat later will help the program easier to read. Better if it would benames in English, but you can do on Latin for yourself friendlythe name of the item.Besides being able to name elements of the program easy to understandway into it you can add comments (also better than Latin). To insertComments are using the latest toolbar button commands. All commentsshould be ignored when compiling the program, and from this point of view of language,which will be written comment should not affect the workprogram. You can experiment with Russian commentary, butBeware that this may cause problems.

Page 12: FLOWCODE GUIDE FROM RUSSIA

Fig. 11. Change the name of the program elementNot to return to the issue of appointment of panel elements, I willdescriptions 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, therun):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

Page 13: FLOWCODE GUIDE FROM RUSSIA

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-segmentindicator), LED7Seg4 (block of 4 seven-segment indicators), Buggy (componenttoys), followed by a number of standard interfaces TCP_IP, Bluetooth, RS232,IrDA, AddDefines (add definition), LinMaster (leading to localnet), Custom (custom component), EEPROM (reprogrammed memory), Alarm(Security device), Thermometer (Thermometer), PWM (Pulse Widthmodulator), SPI (serial external interface), Webserver (web-server), CAN(Network Service Access), KeyPad (keyboard), LinSlave (slave inLocal Area Network), FormulaFlowCode (components of the game), I2C (bus connection between the IP).FlowCode program allows you to quickly create programs ratherinteresting devices.We'll see how easy it is to upgrade the program to generate a square wavewith 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 addtwo software element input (Input). But after dragging commandsworking field and attempts to close the properties window command displays the message:

Page 14: FLOWCODE GUIDE FROM RUSSIA

Fig. 14. Post program FlowCodeOperation input only works with variables. You must either select orcreate a variable using the key Variables.FlowCode, like any programming environment should have the whole setelements needed to build the program. Although FlowCode specific,microcontroller programming environment, it must be variables.Pressing this key in the Properties window for the Input dialog openscreate a variable that has a key Add New Variable ..., which opensThe following window, where the self and a new variable, for whichfit the name "toga", more. Byte variable type must be completely arranged.

Fig. 15. Creating a new variable in FlowCodeAs is often the programs are not the only way to createvariables. In the main menu under Edit there is an item Variables ..., where you canopen a dialog box with the variables and create just the rightvariables. Later, when the need arises to work with established

Page 15: FLOWCODE GUIDE FROM RUSSIA

variables, they can choose from a list or properties dialog softwareelement or the dialog of working with variables.

Fig. 16. Dialog box with variablePressing the Use Variable returns to the Properties dialog boxProgramme Element Input. For the second input element, as seen in the figure above,selected variable name less (lower). The program at this point looksas follows:

Page 16: FLOWCODE GUIDE FROM RUSSIA

Fig. 17. Program with input elementsInput elements in a program outside the loop. This is not the final result, butwhere and how they are placed, can consider later.In order not to overwrite many times, the same program fragment

Page 17: FLOWCODE GUIDE FROM RUSSIA

Programmers have long come up with such convenient means as a subroutine, orprocedure 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 dialogueworking with macros.

Fig. 18. Dialog box to work with macrosButton Create New Macro ... (Create a new macro), I think,good start to create the necessary routines.

Page 18: FLOWCODE GUIDE FROM RUSSIA

Fig. 19. Set the properties sub

The name of the «multi» in the Name of new macro: - it is an obligatory attribute of the macro.And while "just in case, I added the option« freq ». I still do not know if II use this option as I can do but removetoo much I could always (if not forget, as usually happens). Addparameters required to establish another variable «freq_ch», but stilltroubles ever end, and, finally, there is routine. Rather,blank for her.

Page 19: FLOWCODE GUIDE FROM RUSSIA

Fig. 20. Creating a preset for the subroutineNow you can transfer the entire cycle of the output from the main programsubroutine. Let me remind you, as in many image editors, to highlightenough, clicking the left mouse button, circle the items you want. Then, inmainly from the Edit menu select Cut (cut), to move into the working fieldroutines, and click on the link operator brackets Begin-End,arrow appears, finally, in the main Edit menu, choose Paste (insert).Subroutine looks like the program looked at the time of commencement of work.Think about how to change the frequency of the multivibrator, and routine in the finalaccount, and there multivibrator. Operation easily done by changing the length of pauses.Therefore, the properties of a pause (double-click on the first, then the second elementDelay routines), we replace the number "1" to the variable «freq_ch», created byearlier. While the program does not become a "skyscraper", it can be verified.

Page 20: FLOWCODE GUIDE FROM RUSSIA

Pre-add in the main program (from which the deleted cycle) afterInput two elements the new element, called Calculation(Calculation). Its properties define the desired initial value of frequencymultivibrator. That is, the initial duration of the pauses.A slight digression. Previously, it occurred to me that the chip looks likeaccustomed to when she left inputs and outputs on the right. And this has led tothat the yield has moved to port B.

Fig. 21. Entering the starting frequency of the multivibratorTo check, simply click on the button «►» main toolpanel of the program, but the debug LEDs to bind to port B and not A,as it was before.

Page 21: FLOWCODE GUIDE FROM RUSSIA

Fig. 22. The line of LEDsThe first button on the main panel LEDs (O) - to access the properties throughpull-down menu where you can select Component Connections ... and replacebind to the port.

Fig. 23. Change the port of registry "LEDsAfter the changes the program starts checking keyMain toolbar FlowCode.

Page 22: FLOWCODE GUIDE FROM RUSSIA

Fig. 24. Check the operation of sub

Page 23: FLOWCODE GUIDE FROM RUSSIA

Check finds no difference in the program compared withprevious 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». WhenPressing the button "more", this variable must be divisible by 2. Check this out.Add the first element Calculation second similar. And in it we writefreq_ch = freq_ch / 2. Run the program ...... To see if something goes wrong, as it should. The program nowlooks (main program):

Fig. 25. Form the main program at the momentLED instead of flashing quickly, or blinks, or not -

Page 24: FLOWCODE GUIDE FROM RUSSIA

unclear. But there is a simple way to check, but I think the problem lies in thevariable «freq_ch», to check what happens with it. It is sufficient toroutine to include a breakpoint on an element of, say, Output (the firstappeal to the port B). To do this, click the right mouse button on theelement and the drop-down menu click on the item Toggle Breakpoint. Launchprogram displays a window of observation variables and their significance.

Fig. 26. Okno observations in vklyuchenii points ostanova

It is seen that after dividing the variable into azero. The first thing that comes to mind, change the type ofvariable to int (integer). And do not set the value of "1", and1000. And the change in routine in the properties of a pauseseconds to milliseconds. Now, after dividing into twovariable is equal to 500 and the LEDregularly blinks. Timely inspection.So. We have created a routine operationmultivibrator. We have added two input element (for the two buttonscontrol). And, finally, figured out the mechanismchanging the frequency of future multivibrator.^ "Fig. 27. View the program at this stageCertain convenience FlowCode program thatexternal elements can be added to the debug paneladditional elements, and start debuggingdirectly in the development environment without translation file.Therefore, adding an element Switches, I start debugging,to make sure ...... The program does not respond to my attempts to modifyoscillator frequency.Use the method that we've used:set a breakpoint (right mouse button and ToggleBreakpoint in the dropdown menu) to the second branch.The program stops, but after re-run no longer falls into the breakpoint. And where is she

Page 25: FLOWCODE GUIDE FROM RUSSIA

lives?There is one place where she can be -subprogram. Sub-program - is an infinite (in thistime) cycle. Once in his post "vanishing" from the pointbreakpoint, the program is more of it is not refundable.There are two options for how to quickly fix the omission.The first is the easiest. Add to the variable«Lp» (loop, loop). Before entering the subroutine will assignits value to "1". Change the condition of the While looplp = 1, and the end of the subroutine will assign thisvariable value "0".Now we get into a routine and return from

Page 26: FLOWCODE GUIDE FROM RUSSIA
Page 27: FLOWCODE GUIDE FROM RUSSIA

it, which can be verified using breakpoints, creating them inroutines and beyond.

Fig. 28. Revised program fragmentThe second way - to poll the keyboard routine. However, in thismeaning sub is completely lost, leaving nothing program. However,to the contemplation of the structure of the program, you can return later, but now Debuggingprogram reveals one more thing: changing the variables "toga" and «less», I think aboutincreasing and decreasing frequency, and me with the pauses, that is,period. All up "to the contrary." Timely notice. Change (replaceoperations on the reverse) is a pair of clicks.Let's move on. I check the keyboard (the "toga") condition ifmore = 0, as conceived "tighten" input resistors, and click

Page 28: FLOWCODE GUIDE FROM RUSSIA

"To land" them. However, the program FlowCode external element in Switchesopen 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 beforefirmware!).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 carefullymake changes in the orderly sequence "of his mistakes on the horizon(Mentally) loomed another issue.

Page 29: FLOWCODE GUIDE FROM RUSSIA

Fig. 29. Corrected subroutineWhat is the problem? The problem rests on the one hand, and the problem of polling timeon the other. Keys change the frequency (more-less) - is now the timeintervals are large and easy to debug - you have to hold down for long.The reason is that the program must "go through a pause." While she was "restingin the pauses, it does not pay attention to the keystroke. But when we giveduration to the real needs of, say, the frequency in the range of 1-10 kHz,depression, a natural for us, not make a program at a rate givenrate increase this frequency? During the time of holding the keys, for example, in onesecond, the program can read the keystroke so many times.First things first, there is a problem in reality?In this case, it may not. Why?Because of the bounce. This bounce will be neutralized. And thesimple way to neutralize - add a pause after the poll button states,if it has changed, and once again, after a pause, to verify this condition.Another slight digression. The idea to make inputs on the left (port A), and outputsright (port B) was, perhaps, not bad. But it later emerged that thisleads to some inconvenience. Entrances and exits again had to changeplaces. How to dispose of port activities, as sensible to organize the findingsport - a particular problem, but that is definitely important in this environment FlowCodesolved quickly and easily. When the device is conceived, notalways immediately apparent final decision, and sometimes in the process of debuggingchanging not only the details of the solution, but had to be revised and basicapproaches. Availability of suitable debugging tools in a development environment helps to successfullyidentify the causes of problems, and convenient means of modifyingprograms - a pledge rapid progress towards the target. In this regard,FlowCode quite favorable to the user.At the moment construction program, approximately, as follows.

Page 30: FLOWCODE GUIDE FROM RUSSIA

Fig. 30. "Antidrebezgovy" program blockTime "antidrebezgovoy" pause, therefore, the time required retentionbutton when changing the frequency can be chosen to be second or two, whenperformance of other units are required. And there is nothing we will not interfereadd another pause a second or more before calling the subroutine. Weeliminate contact bounce, it, in any case need to fix, and will not allowprogram at this point to do something that would prevent the "right"switching frequency. You can use other techniques, such as waitingTrip button (with "antidrebezgom). Thus, in reality, does not threaten usmanifold increase (or decrease) the frequency generator with a singlebutton.Below, I use a program element Connection Point (junction) and LED at pin A7 to indicate the process of changing frequency. CoupleConnection Point - this in a more familiar shape, the pair formed by the label andoperator Goto (go to label).

Page 31: FLOWCODE GUIDE FROM RUSSIA
Page 32: FLOWCODE GUIDE FROM RUSSIA

Fig. 31. Possible solution to stop the program to poll the buttonsAnd 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 programelement Interrupt. Assigning variables "toga" and «less» introduce into theInterrupt handling routine.

If you open the properties of Interrupt (interrupt), we can seelist of available interrupts.

Fig. 32. The list of possible interruptions in FlowCodeInterrupt timer now, perhaps, not relevant, and start the experimentpossible with an external interrupt RBO / INT.The program takes the form shown below.

Page 33: FLOWCODE GUIDE FROM RUSSIA

Fig. 33. Program using interrupt

Endow interrupt handling routine breakpoint toto see whether we find ourselves in a subroutine, the button is pressed IN.

Page 34: FLOWCODE GUIDE FROM RUSSIA

Fig. 34. Interrupt subroutineRunning program after clicking on the button while stopped, asintended, at the breakpoint.

Page 35: FLOWCODE GUIDE FROM RUSSIA

Fig. 35. The work program with the interruptionIf this interrupt (RBO / INT) was the only available mechanisminterruption, and even then would be to use: instead of two buttonsThere will be three, two for the change in frequency, the third button, the changes to takeforce. But ...List of staff interruptions, the proposed program FlowCode, continuesinterruption in RB Port Change (change of state interrupt port B). Indescription of the microcontroller PIC16F628A can find that the change of stateinputs RB4-RB7 can trigger an interrupt, if enabled. Selectioninputs to connect to the buttons controlling the frequency is not fundamentalnature can be easily replaced input RBO on RB4, a RB1 for RB5. Not difficultchange 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 betteruse the methods of work, which give the desired effect, better jobdevice and well you know and understand, when you quite clearly

Page 36: FLOWCODE GUIDE FROM RUSSIA

imagine why choose one or the other option. Similar considerationsYou are guided, and in selecting the type and model of the microcontroller.

For starters, when it's time to choose a microcontroller, I suggestedto draw attention to the presence of model description in Russian. Farall ready to read several hundred pages in English, but the description ofmanufacturers have to go often enough, specifying certainproperties of the controller.Form the main program and interrupt routines is shown below.

Page 37: FLOWCODE GUIDE FROM RUSSIA

Fig. 36. A program that uses interrupts to change the status of the port in

Page 38: FLOWCODE GUIDE FROM RUSSIA
Page 39: FLOWCODE GUIDE FROM RUSSIA

Fig. 37. Sub-interruptIn addition to changing the oscillator frequency, we intend to reflect this changeon the seven-segment display. Add it to the program, after removingLEDs.

Fig. 38. Seven-segment indicator of a set of additional elementsAs with other elements, the light has properties. To accessproperties of the connection indicator is a button on the front panel next to the buttonclosing. When you press it from the dropdown menu to select itemComponent Connections ...By default, the anode of LED connected to pin 3 port A. In the sequelThis conclusion should be made in the program output and establish a statehigh level.Connection properties can be changed, for example:

Page 40: FLOWCODE GUIDE FROM RUSSIA

Fig. 39. Changing the properties of the indicatorThe anode is now connected to the output in. And in order to switch Switches notprevented us to dispose of the conclusions of the port in our sole discretion, may changeits properties. Switches and LED line default serviceport as a whole, that is connected to all eight ports conclusions. Often thisconvenient. But not always. If there is a need for change, they can beperform 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 twoI / O ports of eight outputs each. Such amount to the firstopinion is more than enough, but as the complexity of the scheme was originallydistributed according to the output port are mixed, some of these conclusions haveused internally, quartz is connected to quite definite conclusionsfor networking, too, are predetermined conclusions. When in doubt, asaffect binding of the findings when the program to byte-rulers LEDstransitions or switches, unnecessary conclusions can be immediately disabled

Page 41: FLOWCODE GUIDE FROM RUSSIA

Fig. 40. Changing the properties of the switchA7 port pin is connected to a point on the seven-segment display thatallows a program block "of the multivibrator" to use this bit foroutput display signal, replacing the former sub output AO.After starting the program all the elements of the indicator light up and flash pointwith the chosen speed.In order not to complicate the view of the program, but it is clear that the procedure works with indicatorwhen displaying the frequency of, say, in the range of 1.9 kHz, it is no more thanrepetition of the same program fragments, I will focus on basicfrequency of 2, and the buttons are smaller and more switching frequency of 1 and 4 (cell division andmultiplication by 2 previously pledged).Service indicator can be made into a subroutine. We call it«Indicator». And the first extinguish the indicator, "writing of unity" in all bitsport. You can then, using the branch, to serve all planned by the valuesfrequency, sparking the desired segment (by setting the corresponding bit to "0").

Page 42: FLOWCODE GUIDE FROM RUSSIA

Fig. 41. Modifying the program to work with indicatorAt this stage, and the program more "grown up" to quantify, it is possiblecheck and correct mistakes if they are, we can add these fragmentsas the frequency output from a given range, for example, flashing an "E" onindicator. You can compare the design with one that could be obtainedwithout using a microcontroller. The device is simple enough, it can berealized by using a digital counter and a clock on the valves. Acan be pleased with the progress and move on to the breadboard and externaldesign of the device.Possible and to continue developing, introducing yet another seven-segment display forexpanding the range of frequencies.The main thing you have started work with a microcontroller, creating the first device, andyou 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 lightdiode, a first step, led to the end, that is, to a layout boardmicrocontroller and a flashlight, you will need a lot of ideas on how tousefully microcontroller. By implementing these ideas, you will learn more aboutProgram FlowCode, learn to work with her. But perhaps a slight feeling of

Page 43: FLOWCODE GUIDE FROM RUSSIA

dissatisfaction does not leave you. Connoisseurs, hardly it comes tomicrocontrollers, with one voice say, need to program in assembly language.

Page 44: FLOWCODE GUIDE FROM RUSSIA

Fig. 42. Fragment subroutine service indicatorI do not belong to the connoisseurs. Working device, and good. As writtenprogram - what's the difference?But if it bothers you, then I would suggest, of course, if you're not "on

Page 45: FLOWCODE GUIDE FROM RUSSIA

short leg "with programming languages, use the FlowCode,as a handy tutorial on programming. First, in C language. Languages moreHigh-level, and therefore easier than assembler. Yes, and moreuniversal. So.

We turn to the most simple program - LED blinked. Even simplifytask - light emitting diode.The program is a graphical representation looks like.

Fig. 43. The prototype program for broadcast in code in C languageThe next thing we do, we choose the main menu section of Chip, whichclick Compile to S. .. (Compiled in C). After successfulcompilation can open the file in the C language in the notebook by choosing View S. .. Facebooksame section, Chip the main menu. A significant portion of the file, all linesstarting with a double slash / / is a comment, that is, the explanation forreads the file, all comments are ignored during further translation of a codeprogram.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 programFlowCode, the text of the program on the assembler and later in the download code, everything wasdefined and identified. What exactly should be measured, depends on yourneeds to be written as a program and compiler specific.There is another function word «# include» - insert designed toadding to the program of other files, most header files, which are activelyused 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 sameIn short, as its graphical representation.

Page 46: FLOWCODE GUIDE FROM RUSSIA

void main (){/ / Initializecmcon = 0x07;/ / Output: 1 -> PORT Atrisa = 0x00;porta = 1;}To work with programs in C and assembler and PIS controllers II think the best development environment, MPLAB. A small correction, which dependsby the compiler and program in C, resulting in FlowCode,will work in MPLAB. Similarly, we can proceed with the program onassembler.

Easily create working devices in the programming environment FlowCodemay leave the wrong impression that it is only good for very simpledevices. But it is not. Means of calculation, the ability to add ready-madeblocks of the program written in C language, all of this, along with thoughtfula set of built-in commands, enables us to solve, if not all, it is sufficientchallenges in the development of devices based on microcontrollers.Quite often, these devices are organized in a system where the hospitalitydevices are connected to the network. For network applications in manymicrocontroller module added networking USART. Where it can be useful for this functioncontroller?We assume that the controller performs a certain program related to the processingsensor state. In this case, as a rule, the sensor and controller can beseparated by some distance. Or, for example, remote control andPerform a device, they too may be in different places. And let the remoteManagement has only two or three buttons, and between the remote and control modulea distance of several meters, for communication between them convenient to useBuilt-in transceiver USART. As the network interface I would givepreference RS485: only two wires, a good protection against externalelectromagnetic effects caused by small disturbances, allowable long-distancefor one module of an IC interface RS485. Not the most complex andnot the most expensive solution.Let's see how you can use the USART for the problem of the connection module (withone-click) management executable (one LED).The program for the first module may look like (I use FlowCode)as follows:

Page 47: FLOWCODE GUIDE FROM RUSSIA

Fig. 44. Program for Management Module

RKrome already familiar software components, after adding an additionalelement RS232 (with additional elements of the dashboard), Iusing the program element Component Macro, appearing as a subroutine call,processing treatment to the embedded USART. Subroutine itself is already writtenproducer FlowCode, is only setting.

Page 48: FLOWCODE GUIDE FROM RUSSIA

Fig. 45. Configuration dialog box component RS232Selecting the box to Component: I needed extra element RS232 (0), selectingwindow Macro: I needed the kind of work SendRS232Char (sending the symbol ofRS232), I create a new variable "operator" (such as Byte), which is a branchprogram (to call the subroutine to send a character) with softwareCalculate the component assign a value '1 '.At this writing the program for the first module can be completed and checkthe program.By clicking on the element AB Switches (0), we can see in the windowCharacters sent element RS232 (0) units appear (in the program are not removed"Chatter", and every click can send a few units). Windowmonitor this process in the program FlowCode black and green symbols, but theypoorly visible in the figure, so in a graphics editor GIMP (beforehow 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.

Page 49: FLOWCODE GUIDE FROM RUSSIA

Fig. 4 6. Check the program of the first module

Page 50: FLOWCODE GUIDE FROM RUSSIA

Fig. 47. The program of the second module, receiving

Here, too, use a Component Macro for RS232.

^ Fig. 48. Dialog Boxconfiguring RS232Start a program componentRS232 (0) Characters in a boxqueue by pressing the icon"+" To open the input windowthe desired character, as if wethe symbol sent from the firstmodule.

Page 51: FLOWCODE GUIDE FROM RUSSIA

^ Fig. 49. Input window,who will receive the second moduleIf you press the OK button, thenprogram must light the LEDat pin RBO.

Page 52: FLOWCODE GUIDE FROM RUSSIA

Fig. 50. Verification of the second module

Immigration Characters received again "Improved the" The Gimp, so that you cansee the received symbol in the figure. And, what's next? You can, of course, "sew"program in the controllers and verify that is called "alive", but ...Is there such a program (also for Windows), which is called Proteus. ThanIt is now interesting is the fact that it is possible to simulate the performance of twomicrocontrollers.Adding to the editor Proteus ISIS two PIC16F628A microcontroller and allnecessary external components, you must configure the controllers:

Page 53: FLOWCODE GUIDE FROM RUSSIA

Fig. 51. Configure the first controllerFig. 52. Customize second controller

Page 54: FLOWCODE GUIDE FROM RUSSIA

Setting direction is reduced to a clock frequency, word configuration and locationLocation hex-files.Now, pressing the button in the assembled circuit, check that everything reallyshould work.

Fig. 53. Check the operation of the two controllers in the ProteusSo "talk" two of the microcontroller.Will not disturb them.

Page 55: FLOWCODE GUIDE FROM RUSSIA

Fig 27

Page 56: FLOWCODE GUIDE FROM RUSSIA

Next start from page