background image

ASURO - 56 -

9. C for ASURO

This chapter is devoted to the programming language C, but explanation will be limited to the 
elements which are needed to control the ASURO system. Obviously the explanation is not a 
complete C-manual, for which other literature may be found on the market

1

.

C has been chosen for its widespread standard and because a C-Compiler is available for almost 
every processor. For ASURO we selected the Gnu-C-Compiler, a freeware program, which 
generates a well optimized code for ASUROs ATmega8 processor.

Whoever is familiar with C will not read anything new in this part of the manual and may proceed 
reading chapter 

9.2. 

We will describe selected elements, absolutely necessary for the ASURO 

control.

Don’t worry: If you take care to use brackets and semicolons, the language C is not too diffi cult at 
all. And of course the ASURO is not a toy!

9.1. Basics in C-Programming

9.1.1. Introduction

Basically the processor executes commands in a C-program step by step from the beginning to 
the end of the program

2

. Parallel processing cannot be provided in ASUROs standard processor, 

so we will have to think in sequential working commands. 

Empty spaces at the beginning of lines in examples, are simply structural reading aids and may be 
left out. Inset spaces however provide excellent programming structure and are extremely helpful 
keeping an overview in extended programs.  

In C each command has to be completed with a semicolon “;”, enabling the compiler to assign all 
elements to the correct command. If commands are to be joined in functions, loops or conditional 
statements, this set of commands will be grouped by placing it inside a pair of special brackets
(“{”, “}”). 

Example:

#include “asuro.h”
int main(void) {
/* All elements between these brackets belong to one set of commands */
}

1For Example: Brian W. Kerninghan, Dennis M. Ritchie: “Programming in C”, 

2Methods to deviate from sequential control in programs ar being named „fl ow control“ and will be     
  described in a later chapter.

Содержание DLR ASURO

Страница 1: ...OBOT KIT Licence by DLR Manufacturer AREXX Zwolle NETHERLANDS JAMA Taichung TAIWAN www arexx com Assembly and Operation MANUAL Model ARX 03 ASURO 1 DLR Germany and AREXX The Netherlands DLR Germany an...

Страница 2: ...ontrolled hobby electronics for projects in schools and universities for studies and adult education centres Special tools which are freeware for private users have been used for all electronic develo...

Страница 3: ...dering 12 4 Electronic assemly 13 4 1 Assembly RS232 Infrared Transceiver 13 4 2 Optional USB Infrared Transceivers 15 4 3 Assembly ASURO PCB 16 4 4 Attachment of the motors 20 4 5 Power supply 20 5 P...

Страница 4: ...ot work 30 6 5 Linentracer T9 T10 does not work 30 6 6 A switch does not work 30 6 6 1 Obviously a combination of switches has been activated 31 6 6 2 Display reacts if switches have been interchanged...

Страница 5: ...tions 65 9 2 1 void Init void 66 9 2 2 void StatusLED unsigned char color 66 9 2 3 void FrontLED unsigned char status 67 9 2 4 void BackLED unsigned char left unsigned char right 67 9 2 5 void Sleep u...

Страница 6: ...on for electronic work approx 20 30 W or a soldering station Solderwire 1 mm for electronic work optionally leadfree Desoldering wick 2 3 mm width just in case solder has to be removed from the print...

Страница 7: ...e motor fully into the cogwheel by placing the cogwheel on a weaker surface eg cardboard and applying the hammer gently to the backside axle of the motor see fig 2 1 Alternatively you may press the co...

Страница 8: ...with this kit Place them on to the 50 10 gear as shown in fig 2 3 Using the sensor markers with 6 black and white segments is recommended for compatibility for compatibility with other ASURO s demo p...

Страница 9: ...teries and power supplies 3 1 Tip solder and temperature Fig 3 2 demonstrates the basics for soldering The hot spot of the soldering equipment should reach ca 360 C with lead solder and ca 390 C for l...

Страница 10: ...to do so Resistors are to be placed vertically in ASURO To do so one leg remains in its original position the other one is to be bent 180 degrees Bending must de done at a curvature of 2 5 mm diamete...

Страница 11: ...t the same time you will have to add a small quantity of solder While melting the solder will flow into the metallized hole Add some more solder until the hole is filled completely see fig 3 4 Now rem...

Страница 12: ...f they have been placed too close 3 4 De soldering When ocassionally a part has landed on a spot where it does not belong then you have to remove such a part The ASURO as you could expect has a double...

Страница 13: ...volt pay attention to polarity C2 C4 100nF ceramic capacitor imprint 104 C3 680pF ceramic capacitor imprint 681 Q1 BC547 A B or C or BC548 A B or C R1 R5 20k _ red black orange gold R2 4 7k yellow vio...

Страница 14: ...fig 4 1 Assembled IR Transceiver Electronics When the RS 232 IR transceiver is ready assembled with the parts it will look like the above picture...

Страница 15: ...Electronics Fig 4 2 USB Infrared Transceiver Fig 4 3 Component side USB Infrared Transceiver Fig 4 4 Bottom side USB Infrared Transceiver 4 2 Assembled USB IR transceiver...

Страница 16: ...ying flat at the length of the slide Wet the soldering tip with some solder and press the tip onto the axle After heating the axle you must add solder at the soldering pads beside the axles After the...

Страница 17: ...symbols on the PCB K1 K2 K3 K4 K5 K6 Sensor switches which must be mounted flat to the PCB surface Q1 Resonator 8MHz D1 D2 D3 D4 D5 D6 D7 D8 Diode 1N4148 Pay attention to polarity D9 1N4001 Pay attent...

Страница 18: ...lack red brown C1 C8 Elco 220_F 10V or higher values Pay attention to polarity IC2 SFH5110 36 Infrared receiver IC bend the legs with long nose pliers Pay attention to polarity the side with dome shap...

Страница 19: ...e from the PCB D11 LED 5 mm red red or reddisch case Pay attention to polarity short leg must be inserted at the mark Fig 4 6 gives an overview of the PCB with all parts inserted up to this phase in t...

Страница 20: ...e must be soldered into the ML port the black wire into the ML port the red wire of the motor on the right side must be soldered into the MR port the black wire into the MR port Next we have to attach...

Страница 21: ...by which the transceiver has been connected in the previous step Then press OK and choose the following settings Bits pro Second 2400 Databits 8 Parity none Stopbits 1 Flowcontrol none Press OK again...

Страница 22: ...rmal serial port After starting the Hyperterminal program you will be asked to define a name for the connection You may choose ASURO USB or any other symbol In the next window you choose connect by an...

Страница 23: ...ro Second 2400 Databits 8 Parity none Stopbits 1 Flowcontrol none Press OK again for confirmation It is possible that root rights are necesary Maybe you need to declare read and write rights for the u...

Страница 24: ...to insert all legs into the contact holes of the socket This can be done easily if you take the IC and press the side with all legs on the row parallel on the surface of a flat table Processor IC1 AT...

Страница 25: ...t the bottomside of the ASURO Back LED D15 left Back LED D16 right All display elements together If an error occurs switch OFF ASURO immediately and start error checking and removal see paragraph 6 4...

Страница 26: ...olds are active on the left and on the right side the odometers are OK If an error occurs the selftest may be continued anyway Error removal may be postponed 5 3 5 The engine Both back LEDs D15 D16 ar...

Страница 27: ...program reports jk Key 3 is activated terminal program reports 34 In case of errors see chapter 6 9 5 3 7 ready If an error has occurred switch the system OFF and remove the batteries Trace and elimi...

Страница 28: ...results the bad part has to be traced with the help of the schematic see Appendix B and an adequate measurement device multimeter or oscilloscope In most cases one of the components IC1 IC2 Q1 D4 may...

Страница 29: ...ack black red brown 6 4 A display element does not work Has the processor been inserted correctly Polarity 6 4 1 Status LED D12 does not work Check polarisation of LED D12 Check resistors R10 R31 470...

Страница 30: ...be activated red If this test is succesful 1 either the processor may be defective or 2 a track of the PCB may be broken interrupted 6 5 Linetracer sensor T9 T10 does not work Check polarisation of T9...

Страница 31: ...sors odometer is working Check resistor R22 470 yellow violet brown orange Check rotation of D13 and D14 D13 and D14 are rose or grey colored bipoled components with a small spot at one side The spot...

Страница 32: ...C327 40 or BC328 40 BC337 40 or BC338 40 1K brown black red gold 6 8 4 One motor turns in the reversed direction Check the cables which connect the motor to the system These connections should be inte...

Страница 33: ...rials must be avoided Vinyl gloves may protect your hands If protection fails clean body parts intensively and immediatedly with soap and water Instant glues originally have been developed for chirurg...

Страница 34: ...ely to see if the motors in the transmission are working well If the position of the motor has been checked keep the system tightly fixed while you put a small amount of instant glue between motor and...

Страница 35: ...and a Compiler WinAVR will be installed 3 An example program s will be copied from CDRom to your hard disk 4 We will create in program editor PN2 a menu input for Make and Clean files 8 1 WINDOWS 8 1...

Страница 36: ...ASURO 36 Software Now this screen will show up Click I Agree This screen appears Click Next...

Страница 37: ...ASURO 37 Software The next screen appears Click Install and the next screen appears Wait...

Страница 38: ...rammers Notepad 2 PN2 editor with the README txt screen appears Close the screen programmers notepad 2 On the DESKTOP the programmers notepad 2 Symbol appears The program editor and the compiler are i...

Страница 39: ...omething like this C ASURO_src When the data source is secured click with the right mouse button on the file go to properties and deactivate the security Setup a menu input for the compiler in the pro...

Страница 40: ...ASURO 40 Software Select on the rigth side C C C C is selected Click Add to insert a new tool...

Страница 41: ...ake Command C ASURO_src FirstTry Test all bat Folder C ASURO_src FirstTry Click OK A new PN2 tool with the name make is now available in the tools main menu When we activate this tool it will run a ba...

Страница 42: ...ASURO 42 Software Setup a clean file In the program editor menu In the main menu Tools again Options and then select the C C again Click Add to add a new tool...

Страница 43: ...C ASURO_src FirstTry Test clean bat Folder C ASURO_src FirstTry Click OK A new PN2 tool with the name clean is now available in the tools main menu When we activate this tool it will run a batch file...

Страница 44: ...ASURO 44 Software In the options screen under tools you will now find the make and clean files which we have made in the previous steps Click OK...

Страница 45: ...ASURO 45 Software Just for try we will open the file C ASURO_src FirstTry test c Click Open...

Страница 46: ...ASURO 46 Software File test c will be opened When you choose tools you will find the new tools make and clean in the menu bar Click on make...

Страница 47: ...he batch file Test all bat this batch file contains a list with command lines which are executed line after line In Test all bat the command make all will be executed make will create a make file whic...

Страница 48: ...file and you only copy it you should always name your own program test c When you want to know all about make files This is not absolutely necessary for operating the ASURO you can find more backgrou...

Страница 49: ...ASURO 49 Software When you open it you will see all the generated data files Click Cancel and after you run the clean command...

Страница 50: ...es are removed What did happen The menu input clean calls for the batch file Test clean bat Make started this with the parameter clean Now the input in the make file is executed in the name of clean a...

Страница 51: ...l and demand the root with su 8 2 1 Flash The ASURO programming tool Start the program from the CD software menu and copy the two flash tools asuroflash and asurocon from the folder linux tools into t...

Страница 52: ...The Installation is quite simple Just give the command rpm i paket rpm in your root directory Ready For Editors you can use Exmacs Kate or Kedit For trial you can copy the demo programs from the CD Yo...

Страница 53: ...ful you may observe how the file Test hex is being transferred to ASURO in the status indicator and display The program file will be stored in the Flash memory inside the processor where the program r...

Страница 54: ...ied ten times In case of failure the flash procedure will be aborted If Checksum Errors are being indicated regularly while Flashing you may switch off or dim some lights in the room especially fluore...

Страница 55: ...the Flash Tool select the newly created program test hex and the correct COM interface Place ASURO near the IR Transceiver activate the Programm button and wait until the transfer of the file has bee...

Страница 56: ...ming 9 1 1 Introduction Basically the processor executes commands in a C program step by step from the beginning to the end of the program2 Parallel processing cannot be provided in ASUROs standard pr...

Страница 57: ...ll and may also contain numbers but none of the other special characters Capital letters and noncapital letters will be discerned As an example x and X reference to different variables Normally capita...

Страница 58: ...iable Speed contains a value 43 Speed Speed 2 variable Speed contains a value 86 It is good programming practice to use clear understandable names The variable name speed in this example is self expla...

Страница 59: ...cally by replacement_text For the NAME following define the same naming conventions as for variables have to be applied C programmers are used to writing the symbols eg NAME at the define in capital l...

Страница 60: ...while 1 if PollSwitch 0 StatusLED RED else StatusLED GREEN If one of the collision detector switches has been activated the status LED will be switched on red otherwise in green The other programming...

Страница 61: ...ng at around half speed StatusLED GREEN Turn on Status LED green while PollSwitch 0 As long as there is no collision SerWrite All OK n 10 Feeling groovy MotorSpeed 0 0 Collision Stop immediatedly Stat...

Страница 62: ...at different locations in our programs Of course we might repeat the writing or use a copy paste method for this purpose this is an annoying procedure and turns our program into a mess or we just def...

Страница 63: ...a b calculate c return c returning integer c End of the function Mult Now an example program which will use the Mult function we have defined before int main void Function main always returns an int a...

Страница 64: ...od in an example If the right sensor receives more light than the left sensor command1 should be executed otherwise command2 int lData 2 Provide memory space for measurement results LineData lData Rea...

Страница 65: ...e space must be big enough to contain the expected message SerRead message 13 0 Read 13 characters and wait until 13 characters have been received We now consider the text string Hi here I am has been...

Страница 66: ...Normally the main function will be closed by return 0 marking the end of the program In ASURO however some parts of old programs flashed earlier may still remain in the memory and be executed resultin...

Страница 67: ...unsigned char time72kHz This function will command the processor to wait some time The waiting period may be defined by a parameter unsigned char 4 containing a number of maximal 255 and counting cycl...

Страница 68: ...ring Hello how are you should be sent by IR interface SerWrite Hello how are you 18 9 2 9 void SerRead unsigned char data unsigned char length unsigned int timeout Once you are able to transmit data b...

Страница 69: ...ger location in memory The function will transfer the AD converter values of measurement data by both phototransistors The first integer value represents the converter value of the left T9 the second...

Страница 70: ...the function The first integer value contains the AD value delivered by the left T11 the second integer value contains the AD value delivered by the right T12 phototransistor Maximum brightness is re...

Страница 71: ...it0 1 K6 Bit1 2 K5 Bit2 4 K4 Bit3 8 K3 Bit4 16 K2 Bit5 32 K1 Activating switches 1 3 and 5 will cause the function to return 42 32 8 2 42 To be sure the function may be called several times in sequenc...

Страница 72: ...phototransistors LPT80A 2x Side LEDs IRL80A 1x Crystal 8MHz 2x Elco 220_F at least 10V RM 3 5 10 4x ceramic capacitors 100nF RM 5 08 2x ceramic capacitors 4 7nF RM 2 54 1x 100 1 4 W 5 2x 220 1 4 W 5...

Страница 73: ...circuit board IR RS232 transceiver 3x Diodes 1N4148 1x Zenerdiode ZPD5 1 1x Transistor BC547 A B or C or BC548 A B or C 1x Integrated circuit NE555N 1x IR receiver SFH 5110 36 1x IR LED SFH415 U 1x E...

Страница 74: ...ASURO 74 B ASURO DIAGRAM Appendices...

Страница 75: ...ASURO 75 Appendices C RS 232 Transceiver...

Страница 76: ...ASURO 76 D USB Transceiver Appendices...

Страница 77: ...ASURO 77 E Block diagram ASURO F Block diagram PIC processor Appendices...

Страница 78: ...ASURO 78 G Contents ASURO KIT Appendices...

Отзывы: