AVR-GCC ABC [1]

This time I decided to lay down some information on using AVR-GCC compiler. I am not going to rewrite what’s in documentation is already written, but just write down some issues, what can help you start using this amazing tool. Introduction Probably the most AVR programmers had a question in their mind what compiler to use for their designs. The choice is really big. You can use commercial ones like IAR, CodeVision, ImageCraft. These compilers come with convenient GUI’s, code generators. But you have to buy license to use them. So if you are going to make low budget project, the best choice is to use open source compiler GCC . This is the most successful open source compiler in the world. For AVR platform it is called AVR-GCC. The compiler itself has no graphical interface everything can be done in MSDOS command line or in Linux command line. To make it easier to compile project there are makefiles used. GNU compilers as usually are using UNIX style make files. This file can be run with make.exe program. In reality you don’t have to write makefiles – there are ready templates to use. Everyone maybe agrees that use of compiler…

Continue reading

C language Operators and expressions

The main thing what microcontrollers does is operates with data. There are four main operations that microcontrollers does: adds, abstracts, multiplies and divides (+,-,*,/). division can be split in division “/” and modulus operation “%”. For instance i1/i2 is integer division. Other part of operators is Relation operators. They are used for boolean conditions and expressions. Expressions with these operators return true or false values. Zero is taken as false and non zero value as true. Operators may be as follows: <, <=, > >=, ==, !=. The priority of the first four operators is higher than that of the later two operators. These operators are used in relational expressions such as: 7 > 12 // false 20.1 < 20.2 // true ‘b’ < ‘c’ // true “abb” < “abc” // true Note that the equality operator is == and not =. ‘=’ is an assignment operator. If you want to compare a and b for equality then you should write a == b, not a = b because a = b means you are assigning the value of b to a, as shown in. Next part of operators are logical operators. With logical operators results may be combined to…

Continue reading

Constants in C language

Constant value is understandable as non changeable value like PI=3.141592… value in math. Usually you use constants in your programs, but don’t realize that they are constants. For instance: x=x+3; The number 3 is a constant which will be compiled directly in addition operation. Constants can be character or string. Like in function printf(“Hello World\n”); “Hello World” is a string constant which is placed in program memory and will never changes. It is usually recommended to declare constants by using identifier with reserved word const: const int No=44; By identifying the variable as constant will cause compiler to store this variable in program memory rather than in RAM, thus saving space in RAM. If special functions used, then constants can be also stored in EEPROM memory. Few words for the numeric constants. Numeric constants can be declared in many ways indicating their base. Decimal integer constants (base 10) consist of one or more digits, 0 through 9, where 0 cannot be used as the first digit. Binary constants (base 2) begin with a 0b or 0B prefix, followed by one or more binary digits (0, 1). Octal constants (base 8) consist of one or more digits 0 through 7, where…

Continue reading

The very basics of C

C language is function based programming language. C program itself is a function. Usually parameters to C function are passed as arguments. Function consists of a name followed by the parentheses enclosing arguments or an empty pair of parentheses if there are not arguments required. If there are several arguments, they are separated by commas. The mandatory part in C program is main function. This function must be included in every program because this is a first function which is run after execution of program. Lets take an example: #include <stdio.h> int main(void) { printf(“Hello world!\n”); return 0; } This is a very basic C program, but it contains all necessary elements of it. Lets examine a little bit what we have written here…

Continue reading

Microcontroller C programming

There is no doubt that everyone faces C language when programming microcontrollers. This is most popular language among hardware programmers. There are plenty books about this language – you just have to open and read. This article is not about language basics, but there is effectiveness of c language in embedded systems touched. Quite often you can find good examples of effective algorithms: faster code performance and code size as well. In order to write good optimal algorithm you have to know structure of compiler. Of course we are not going to analyze compilers, but we can look through few rules and tricks and achieve optimal algorithm. Begining What to do when limit of program size is overrun or there is not enough speed in some cases. Of course you will say, that these parts it is best to write in assembler, but is this a solution? Maybe there is a way to do this with C? Not a secret, that the same result can be achieved in different ways, e.g. some programmers like to use dynamic variables other arrays, some like to use case other if statements. This is a Programming Style and mostly everyone has its own style.…

Continue reading

GNUARM for ARM microcontrollers

In this article you’ll find some information about how to configure GNUARM toolset for compiling ARM7 microcontrollers. GNUARM is the open source toolset for ARM7 MCUs. It has GCC compiller and debugger. Our purpose now is to set up tools in Windows environment and compile one project. First of all download compiled toolset from https://www.gnuarm.com: Select the newest [GCC-4.0 toolchain] located bellow Cygwin. After it is downloaded, start the installation: Start window Accept license agreement. Select folder where do you want GNUARM to be installed: Select the components. You can select all of them. Chose Start menu folder name – just leave as it is. Select desktop shortcut to be placed. I higly recoment to check Cygwin DLL, because despite I had cygwin installed, but I had to copy DLLs to copy manually. If this option ischecked, DLL files will be copied without bothering you. And press install.. Select checkbox in order to create system variable: PATH=c:\gnuarm\bin After we have GNUARM installed, download binutils from https://optimize.ath.cx/ARM7/src/utils.zip. Download this archive and unpack all contents to c:\gnuarm\bin folder. Also download https://optimize.ath.cx/ARM7/src/cygncurses-8.dll and put it in c:\gnuarm\bin folder. Now we are set to start compillation. Lets try test compillation. Jus download project from…

Continue reading

ARM7-Base development board for LPC2148

After ARM mini board for LPC2148 is created its time to develop development board. I want to make board as universal as possible. So I decided to put I2C, SPI, COM and JTAG on board. I decided to use external voltage adapter as there is needed 5V and 3.3V DC sources. For my experiments I can use those voltages straight from PC source. 5V there is used to supply MAX232IC.I decided to use it instead of MAX3232 because it is easer to get them in market. Of course I left ability to use and MAX3232 by changing jumper. All other free pins I made accessible by adding pinheads in board. I made 100x100mm double sided PCB PCB Bottom image PCB top image (when printing – use mirror function) And real world images. PCB Bottom Completed soldered board with ARM mini board on top. And of course I put Eagle3D traced board images. Best regards to Matthias Weißer from www.matwei.de did great job to do such job. The first read/write tests I run with Philips Flash Utility were successful. Next time I’ll post few articles how to get this board running by writing C code, compiling and flashing the ARM7 LPC2148.…

Continue reading