Embedded Electronics Blog

AVR : Tutorial 1: Introduction to AVR

2015-08-12-AVR_Tips_Input_output_small

AVR microcontrollers from ATMEL are very good choice for designing mid-range embedded systems.They are 8Bit RISC controllers. They come in many verities and most of them gives 16MIPS (Mega Instructions Per Seconds) throughput at 16MHz . Unlike most of the popular PIC microcontrollers, AVRs have powerful instruction set, most executing in 1 cycle. Recently ATMEL has introduces some new controllers with speed upto 20MHz and USB support. (actually we can overclock AVR, which is characterised to run at 16MHz, upto 24MHz !! I will tell you how to do it sometimes later).

Which AVR ?

Most common AVRs are ATmega8 and ATmega16. They are available at Lamington road for Rs60 and Rs100 respectively.We will use ATmega16 AVR throughout these tutorials.

Which compiler ?

AVRs can be programmed directly in assembly. We have to use standard assembler provided by ATMEL. However, if you choose writing programs into assembly, you won’t be able to write complex programs, it will drive you nuts and half of your development time will be wasted in recollecting what you have done last time, why this line I have written, which register I am using for this variable, Oh my god now how can I do 32bit integer multiplication/divisions, etc. problems. The solution is simple…use C cross-compilers !

C cross-compilers(or to be simple call it as compilers) provide you facility to write programs in C and then they convert it to equivalent assembly code, which is then assembled by standard assembler provided by ATMEL. All happens at the background and you get HEX file at the output. Hex file actually contains machine code, which uC (i.e. microcontroller) will execute.

We will be using CodeVisionAVR C compiler.This is extremely user friendly and the best C compiler available for AVRs. Though it is commercial, its evaluation version can compile C code which should not result into HEX file having size more than 2KB. Later on once you are well versed with cvavr (i.e. CodeVisionAVR) and overall C programming methodology for uCs, you can switch to free GCC compiler for AVR.

How to put HEX file into uC ?

To program(or burn !) our code into uC. We need to use programmer hardware and programmer software. We will use simple parallel port programmer hardware and PONYPROG200 programmer software. To know how to build simple AVR programmer hardware and how to use PONYPROG2000 see Ultra simple AVR programmer.

 

Exit mobile version