[ATMEL logo]

Atmel AVR Page

Introduction.

This page is intended to share some knowledge about the ATMEL AVR Microcontroller. Since I have programmed the 8051 quite a bit, I will try to highlight some differences between the two species. As I only use assembly, most of this might be meaningless for them "high level" chaps.

AVR <--> 8051.

AVR stands for the core of the new line of microcontrollers ATMEL is producing. It's a RISC concept, which means long instruction opcodes (16 bit) which execute in a single clock cycle. This makes them very fast, although more instructions are needed sometimes. Say a simple case statement:

    ATMEL:                           8051:
            CPI     R16, CASE1               CJNE    A, CASE1, SKIP1
            BRNE    SKIP1                    ..case 1 in only 1 instruction..
            ..so 1 is the case..     SKIP1:    
    SKIP1:
            etc.

Or I/O register initialisation:

    ATMEL:                           8051:
            LDI     R16, 23                  MOV     I_O1, R16
            OUT     I_O1, R16


Or in loops:

    ATMEL:  DEC     R1               8051:
            BRNE    ATMEL                    DJNZ    LOOPCONT, 8051

But a benefit is the large register file, 32 registers in all. With small projects, no RAM is needed for variable storage. Ram addressing is quite sophisticated, 3 pointer registers exist, together with pre-increment, post-decrement and more, addressing modes.

Bit manipulation is less extensive with the AVR than with the 8051. The 8051 contains a boolean processor, which allows you to copy a single bit from a register to a bitposition in another register. It's a bit harder to do this with the AVR, but it isn't used that often.

ATMEL pitfalls.

Here's a list of things that were quite frustrating during development, you might benefit from my mistakes here...

AT90S8515. Usage of timer0 together with toggling line PB0 (T0). Unwanted transitions of the PB0 line were shown, unexplained yet. The problem was solved by using another line.

The manual suggests a max. fclk of 20Mhz. I have devices AT90S8515-8PC, which means 8Mhz clock max. They run at 18Mhz though, but fail to program using SPI at 18Mhz.

Only the last 16 registers can be used with instructions using immediate data.

Only the first 32 I/O registers can be used in conjunction with the bit-set/clear instructions.

ATMEL suggests it's save to leave the reset line inconnected, as an internal pullup is present, and reset circuitry is integrated as well. I noticed spurious resets whenever one touches the ground plane. Better connect it to +5V I'd say.

This one considers the eeprom master lock feature. Before writing to the eeprom, the "eeprom master write enable" bit has to be set. This is a feature not present with the 90S1200. With 8515def.inc, filedate 01-24-90, size 5831 bytes, EEMWE is undefined. Add ".equ EEMWE = 2" above the line containing ".equ EEWE = 1". With application note avr100.asm, Accessing the EEPROM, the routine EEWrite should be changed to incorporate the EEMWE flag.

I've had some problems with the EEPROM, some bytes get overwritten at power up (or down, I can't check that..). It appears that ATMEL is aware of this problem as well. Check this URL: http://www.atmel.com/atmel/acrobat/doc1051.pdf

I got a report of internal pullup resistors that blow easily with the 8515.

Voltages applied to I/O pins prior to reset seem to hamper the reset process.

Code efficiency.

As I switched form 8051 to AVR, I did some recoding of the same applications. Here's.

                  8051         AVR
Application     Code size   Code size 
                (bytes)     (bytes)    
7SEG counter    204         286         
Switchbank ctl  810         724

More to follow.

I can't say much about performance, in both cases the processor had ample resources to complete the job. I never had to optimize code because of speed.

I received questions whether an application written in 8051 assembly could be converted into AVR within the same size. I think it is possible, though it will be quite a bit of work. If one makes a direct translation, code size will grow. By taking advantage of the new adressing modes, the extra peripherals etc. of the AVR, you are likely to save some program memory though.

Links.

If you live in The Netherlands, en dus een beetje nederlands kunt, you can get a free CDROM with a wealth of tools and datasheets for most of the ATMEL product line. Contact Alcom Electronics, phone 010-2882500.

There is an ATMEL AVR discussion list. To join, send text 'JOIN' to atmel-request@pic.co.za.

ATMEL Datasheets
ATMEL assember (DOS + Win3.11) and a simulator (Win3.11)
SPI code uploader and programmer schematics
Another programmer.


[Next Page] [Goto Index]
[Contact Form]


This article was written by Arian van Dorsten jwasys@xs4all.nl
The most recent version can be found on: http://www.xs4all.nl/~jwasys