4.2 Microcontroller Firmware Building

To build AVR firmware AVR studio 4 is used. It can be downloaded directly from ATMEL corporation web site.

Run AVR Studio. Select New Project menu item from AVR Studio Project menu. In the opened dialog define Project type as Atmel AVR Assembler, type DefendLine4 in Project name field and select source code location which is in defendline/ASM subdirectory. Click Finish button. The project tree should be created and the only initial file DefendLine4.asm should be displayed. By right mouse click on project's Source Files item and choosing Add Files to Project add the rest *.asm files.

Before building the project must be configured to comply with target AVR microprocessor, hardware accessories and desirable user settings. There are a few things to be defined in DefendLine4.asm, please see the code fragment below.

Example 4.1. DefendLine4.asm Settings

.include "m32def.inc"
;.include "m16def.inc"
;#define _EXT_DISPLAY_
;#define _TEST_

First line defines which type of AVR processor should the code be compiled for. Obviously, that .include "m32def.inc" defines ATMega32. By uncommenting #define _EXT_DISPLAY_ external LED matrix display support is enabled. This option is not used in current hardware configuration. And finally, by definition of #define _TEST_ internal tests will be enabled, this feature helps debugging code and do some validation in AVR simulator.


Current AVR source code version is compatible with ATMega32. Nevertheless, the small code footprint potentially fits in AVR16 but some efforts must be made to adapt the code for the latter one while keeping compatibility with ATMega32.

There is one and only one user configuration which must be defined in Config.asm, please see the code fragment below.

Example 4.2. Config.asm Settings

#define _CONF1_

#if defined(_CONF1_)
    .db "0123", 0, 0
    .db "0B912143658709F1", 0, 0;12345678901 - 1st destination phone number 
    .db "0B912143658709F1", 0, 0;12345678901 - 2nd destination phone number 

;--- Textual representation of detector states ---
    .db "IR detector ", 0, 0
    .db "Balcony door ", 0
    .db "Door of verandah ", 0
    .db "Main gate", 0

.EQU REPORT_HOUR            = 0x0;


In our case this user configuration called _CONF1_. Let's enumerate all the configuration parameters. The first one, device_id defines unique 4-character microcontroller unit identifier. It allows to distinguish units which send data to the same server. The second and the third parameters DA_def1 and DA_def2 define mobile phone numbers which will be used as SMS notifications recipients when the unit works in simple mode. Parameters det_infrared, det_balcony_door, det_verandah_door, det_main_gate give more meaningful names to sensors, they make it easier to comprehend unit's reports and notifications. And finally, REPORT_HOUR defines report hour - time, when daily report will be sent. 0x0 means 0:00 or midnight.

The project is ready to be built. Select Build menu item from AVR Studio Build menu. DefendLine4.hex file will be created. Flash it to the target microprocessor by means of any AVR ISP programmer.