AVR Assembly Examples
AVR Assembly Examples
;
***************************************************************************
;*
;* "mpy16u" - 16x16 Bit Unsigned Multiplication
;*
;* This subroutine multiplies the two 16-bit register variables
;* mp16uH:mp16uL and mc16uH:mc16uL.
;* The result is placed in m16u3:m16u2:m16u1:m16u0.
;*
;* Number of words :14 + return
;* Number of cycles :153 + return
;* Low registers used :None
;* High registers used :7 (mp16uL,mp16uH,mc16uL/m16u0,mc16uH/
m16u1,m16u2,
;* m16u3,mcnt16u)
;*
;
***************************************************************************
;***** Code
;
***************************************************************************
;*
;* "mpy16s" - 16x16 Bit Signed Multiplication
;*
;* This subroutine multiplies signed the two 16-bit register
variables
;* mp16sH:mp16sL and mc16sH:mc16sL.
;* The result is placed in m16s3:m16s2:m16s1:m16s0.
;* The routine is an implementation of Booth's algorithm. If
all 32 bits
;* in the result are needed, avoid calling the routine with
;* -32768 ($8000) as multiplicand
;*
;* Number of words :16 + return
;* Number of cycles :210/226 (Min/Max) + return
;* Low registers used :None
;* High registers used :7 (mp16sL,mp16sH,mc16sL/m16s0,mc16sH/
m16s1,
;* m16s2,m16s3,mcnt16s)
;*
;
***************************************************************************
;***** Code
mpy16s: clr m16s3 ;clear result byte 3
sub m16s2,m16s2 ;clear result byte 2 and carry
ldi mcnt16s,16 ;init loop counter
m16s_1: brcc m16s_2 ;if carry (previous bit) set
add m16s2,mc16sL ; add multiplicand Low to result
byte 2
adc m16s3,mc16sH ; add multiplicand High to
result byte 3
m16s_2: sbrc mp16sL,0 ;if current bit set
sub m16s2,mc16sL ; sub multiplicand Low from
result byte 2
sbrc mp16sL,0 ;if current bit set
sbc m16s3,mc16sH ; sub multiplicand High from
result byte 3
asr m16s3 ;shift right result and multiplier
ror m16s2
ror m16s1
ror m16s0
dec mcnt16s ;decrement counter
brne m16s_1 ;if not done, loop more
ret
;
***************************************************************************
;*
;* "div8u" - 8/8 Bit Unsigned Division
;*
;* This subroutine divides the two register variables
"dd8u" (dividend) and
;* "dv8u" (divisor). The result is placed in "dres8u" and the
remainder in
;* "drem8u".
;*
;* Number of words :14
;* Number of cycles :97
;* Low registers used :1 (drem8u)
;* High registers used :3 (dres8u/dd8u,dv8u,dcnt8u)
;*
;
***************************************************************************
;***** Code
;
***************************************************************************
;*
;* "div8s" - 8/8 Bit Signed Division
;*
;* This subroutine divides the two register variables
"dd8s" (dividend) and
;* "dv8s" (divisor). The result is placed in "dres8s" and the
remainder in
;* "drem8s".
;*
;* Number of words :27
;* Number of cycles :107/108
;* Low registers used :2 (d8s,drem8s)
;* High registers used :3 (dres8s/dd8s,dv8s,dcnt8s)
;*
;
***************************************************************************
;***** Code
ret ; return
d8s_2: rol drem8s ;shift dividend into
remainder
sub drem8u,dv8s ;remainder = remainder - divisor
brcc d8s_3 ;if result negative
add drem8u,dv8s ; restore remainder
clc ; clear carry to be shifted into
result
rjmp d8s_1 ;else
d8s_3: sec ; set carry to be
shifted into result
rjmp d8s_1
;
***************************************************************************
;*
;* "div16u" - 16/16 Bit Unsigned Division
;*
;* This subroutine divides the two 16-bit numbers
;* "dd8uH:dd8uL" (dividend) and "dv16uH:dv16uL" (divisor).
;* The result is placed in "dres16uH:dres16uL" and the
remainder in
;* "drem16uH:drem16uL".
;*
;* Number of words :19
;* Number of cycles :235/251 (Min/Max)
;* Low registers used :2 (drem16uL,drem16uH)
;* High registers used :5 (dres16uL/dd16uL,dres16uH/dd16uH,
dv16uL,dv16uH,
;* dcnt16u)
;*
;
***************************************************************************
.def drem16uL=r14
.def drem16uH=r15
.def dres16uL=r16
.def dres16uH=r17
.def dd16uL =r16
.def dd16uH =r17
.def dv16uL =r18
.def dv16uH =r19
.def dcnt16u =r20
;***** Code
;
***************************************************************************
;*
;* "div16s" - 16/16 Bit Signed Division
;*
;* This subroutine divides signed the two 16 bit numbers
;* "dd16sH:dd16sL" (dividend) and "dv16sH:dv16sL" (divisor).
;* The result is placed in "dres16sH:dres16sL" and the
remainder in
;* "drem16sH:drem16sL".
;*
;* Number of words :45
;* Number of cycles :252/268 (Min/Max)
;* Low registers used :3 (d16s,drem16sL,drem16sH)
;* High registers used :7 (dres16sL/dd16sL,dres16sH/dd16sH,
dv16sL,dv16sH,
;*
;
***************************************************************************
;***** Code
d16s_4:
ret ; return
d16s_5: rol drem16sL ;shift dividend into
remainder
rol drem16sH
sub drem16sL,dv16sL ;remainder = remainder - divisor
sbc drem16sH,dv16sH ;
brcc d16s_6 ;if result negative
add drem16sL,dv16sL ; restore remainder
adc drem16sH,dv16sH
clc ; clear carry to be shifted into
result
rjmp d16s_3 ;else
d16s_6: sec ; set carry to be
shifted into result
rjmp d16s_3
;
****************************************************************************
;*
;* Test Program
;*
;* This program calls all the subroutines as an example of
usage and to
;* verify correct verification.
;*
;
****************************************************************************
;***** Code
RESET:
;---------------------------------------------------------------
;Include these lines for devices with SRAM
; ldi temp,low(RAMEND)
; out SPL,temp
; ldi temp,high(RAMEND)
; out SPH,temp ;init Stack Pointer
;---------------------------------------------------------------
ldi mc8u,250
ldi mp8u,4
rcall mpy8u ;result: m8uH:m8uL = $03e8 (1000)
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
ret
;
***************************************************************************
;*
;* "mpy16u" - 16x16 Bit Unsigned Multiplication
;*
;* This subroutine multiplies the two 16-bit register variables
;* mp16uH:mp16uL and mc16uH:mc16uL.
;* The result is placed in m16u3:m16u2:m16u1:m16u0.
;*
;* Number of words :105 + return
;* Number of cycles :105 + return
;* Low registers used :None
;* High registers used :6 (mp16uL,mp16uH,mc16uL/m16u0,mc16uH/
m16u1,m16u2,
;* m16u3)
;*
;
***************************************************************************
;***** Code
ret
;
***************************************************************************
;*
;* "div8u" - 8/8 Bit Unsigned Division
;*
;* This subroutine divides the two register variables
"dd8u" (dividend) and
;* "dv8u" (divisor). The result is placed in "dres8u" and the
remainder in
;* "drem8u".
;*
;* Number of words :66 + return
;* Number of cycles :50/58/66 (Min/Avg/Max) + return
;* Low registers used :1 (drem8u)
;* High registers used :2 (dres8u/dd8u,dv8u)
;*
;
***************************************************************************
;***** Code
;
***************************************************************************
;*
;* "div16u" - 16/16 Bit Unsigned Division
;*
;* This subroutine divides the two 16-bit numbers
;* "dd8uH:dd8uL" (dividend) and "dv16uH:dv16uL" (divisor).
;* The result is placed in "dres16uH:dres16uL" and the
remainder in
;* "drem16uH:drem16uL".
;*
;* Number of words :196 + return
;* Number of cycles :148/173/196 (Min/Avg/Max)
;* Low registers used :2 (drem16uL,drem16uH)
;* High registers used :4 (dres16uL/dd16uL,dres16uH/dd16uH,
dv16uL,dv16uH)
;*
;
***************************************************************************
.def drem16uL=r14
.def drem16uH=r15
.def dres16uL=r16
.def dres16uH=r17
.def dd16uL =r16
.def dd16uH =r17
.def dv16uL =r18
.def dv16uH =r19
;***** Code
;
****************************************************************************
;*
;* Test Program
;*
;* This program calls all the subroutines as an example of
usage and to
;* verify correct verification.
;*
;
****************************************************************************
;***** Code
RESET:
;---------------------------------------------------------------
;Include these lines for devices with SRAM
; ldi temp,low(RAMEND)
; out SPL,temp
; ldi temp,high(RAMEND)
; out SPH,temp ;init Stack Pointer
;---------------------------------------------------------------
ldi mc8u,250
ldi mp8u,4
rcall mpy8u ;result: m8uH:m8uL = $03e8 (1000)
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
******************************************************************************
;*
;* FUNCTION
;* muls16x16_32
;* DECRIPTION
;* Signed multiply of two 16bits numbers with 32bits
result.
;* USAGE
;* r19:r18:r17:r16 = r23:r22 * r21:r20
;* STATISTICS
;* Cycles : 19 + ret
;* Words : 15 + ret
;* Register usage: r0 to r2 and r16 to r23 (11
registers)
;* NOTE
;* The routine is non-destructive to the operands.
;*
;
******************************************************************************
muls16x16_32:
clr r2
muls r23, r21 ; (signed)ah *
(signed)bh
movw r19:r18, r1:r0
mul r22, r20 ; al * bl
movw r17:r16, r1:r0
mulsu r23, r20 ; (signed)ah * bl
sbc r19, r2
add r17, r0
adc r18, r1
adc r19, r2
mulsu r21, r22 ; (signed)bh * al
sbc r19, r2
add r17, r0
adc r18, r1
adc r19, r2
ret
;
******************************************************************************
;*
;* FUNCTION
;* mac16x16_32
;* DECRIPTION
;* Signed multiply accumulate of two 16bits numbers
with
;* a 32bits result.
;* USAGE
;* r19:r18:r17:r16 += r23:r22 * r21:r20
;* STATISTICS
;* Cycles : 23 + ret
;* Words : 19 + ret
;* Register usage: r0 to r2 and r16 to r23 (11
registers)
;*
;
******************************************************************************
mac16x16_32:
clr r2
ret
add r16, r0
adc r17, r1
adc r18, r4
adc r19, r5
ret
;
******************************************************************************
;*
;* FUNCTION
;* fmuls16x16_32
;* DECRIPTION
;* Signed fractional multiply of two 16bits numbers
with 32bits result.
;* USAGE
;* r19:r18:r17:r16 = ( r23:r22 * r21:r20 ) << 1
;* STATISTICS
;* Cycles : 20 + ret
;* Words : 16 + ret
;* Register usage: r0 to r2 and r16 to r23 (11
registers)
;* NOTE
;* The routine is non-destructive to the operands.
;*
;
******************************************************************************
fmuls16x16_32:
clr r2
fmuls r23, r21 ; ( (signed)ah *
(signed)bh ) << 1
movw r19:r18, r1:r0
fmul r22, r20 ; ( al * bl ) << 1
adc r18, r2
movw r17:r16, r1:r0
fmulsu r23, r20 ; ( (signed)ah *
bl ) << 1
sbc r19, r2
add r17, r0
adc r18, r1
adc r19, r2
fmulsu r21, r22 ; ( (signed)bh *
al ) << 1
sbc r19, r2
add r17, r0
adc r18, r1
adc r19, r2
ret
;
******************************************************************************
;*
;* FUNCTION
;* fmac16x16_32
;* DECRIPTION
;* Signed fractional multiply accumulate of two 16bits
numbers with
;* a 32bits result.
;* USAGE
;* r19:r18:r17:r16 += (r23:r22 * r21:r20) << 1
;* STATISTICS
;* Cycles : 25 + ret
;* Words : 21 + ret
;* Register usage: r0 to r2 and r16 to r23 (11
registers)
;*
;
******************************************************************************
fmac16x16_32:
clr r2
ret
add r16, r0
adc r17, r1
adc r18, r4
adc r19, r5
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
COPY 102
LPM 108 ;
***************************************************************************
EPROM 100 ;*
SER EPROM ;* "add16" - Adding 16-bit registers
;*
DFLASH AT45
;* This example adds the two pairs of register
FLASH CARD variables (add1l,add1h)
;* and (add2l,add2h) The result is placed in (add1l,
VFX SMIL
add1h).
VFX MEM ;*
SORT 220 ;* Number of words :2
;* Number of cycles :2
CRC 236 ;* Low registers used :None
XMODEM REC ;* High registers used :4
;*
UART 304 ;* Note: The sum and the addend share the same
UART 305 register. This causes the
;* addend to be overwritten by the sum.
UART 128
;*
UART BUFF ;
***************************************************************************
USB 232
AVR ISP ;**** Register Variables
ISP 2313 .def add1l = r16
.def add1h = r17
ISP 1200 .def add2l = r18
AVR SPI .def add2h = r19
I2C 300 ;***** Code
I2C 302 add16: add add1l, add2l ;Add low
bytes
I2C TWI26
adc add1h, add2h ;Add high bytes
I2C/TWI 128 with carry
I2C/TWI AT8 ;Expected result is 0xAC68
DALLAS-1W
DALLAS CRC
;
ETHNET 8019 ***************************************************************************
TEA ;*
;* "addi16" - Adding 16-bit register with immediate
ADC 128 ;*
ADC 10B ;* This example adds a register variable (addi1l,
addi1h) with an
ADC 400
;* immediate 16-bit number defined with .equ-
ADC 401 statement. The result is
THERM 232 ;* placed in (addi1l, addi1h).
;*
IRD 410 ;* Number of words :2
LCD HD44 ;* Number of cycles :2
;* Low registers used :None
LCD 2313 ;* High registers used :2
LCD44 2313 ;*
;* Note: The sum and the addend share the same
KBD 240 register. This causes the
MUX 242 ;* addend to be overwritten by the sum.
;*
KBD PS2
;
KBD PC/128 ***************************************************************************
PS2 EMU
;***** Register Variables
BOOT MG8 .def addi1l = r16
BOOT DR8 .def addi1h = r17
PWM 10K
ENCODE
;
STH-11 ***************************************************************************
ATMEL CORP ;*
;* "sub16" - Subtracting 16-bit registers
AVR
;*
BUTTERFLY ;* This example subtracts two pairs of register
AVR BOOK variables (sub1l,sub1h)
;* from (sub2l, sub2h) The result is stored in
registers sub1l, sub1h.
;*
;* Number of words :2
;* Number of cycles :2
;* Low registers used :None
;* High registers used :4
;*
;* Note: The result and "sub1" share the same
register. This causes "sub1"
;* to be overwritten by the result.
;*
;
***************************************************************************
;***** Code
sub16: sub sub1l,sub2l ;Subtract
low bytes
sbc sub1h,sub2h ;Add high byte with
carry
;Expected result is 0x4646
;
***************************************************************************
;*
;* "subi16" - Subtracting immediate 16-bit number from
a 16-bit register
;*
;* This example subtracts the immediate 16-bit number
subi2 from the
;* 16-bit register (subi1l,subi1h) The result is
placed in registers
;* subi1l, subi1h.
;*
;* Number of words :2
;* Number of cycles :2
;* Low registers used :None
;* High registers used :2
;*
;* Note: The result and "subi1" share the same
register. This causes
;* "subi1" to be overwritten by the result.
;*
;
***************************************************************************
;***** Code
subi16: subi subi1l,low(subi2) ;Subtract
low bytes
sbci subi1h,high(subi2) ;Subtract high byte
with carry
;Expected result is 0x3412
;
***************************************************************************
;*
;* "cp16" - Comparing two 16-bit numbers
;*
;* This example compares the register pairs (cp1l,cp1h)
with the register
;* pairs (cp2l,cp2h) If they are equal the zero flag
is set(one)
;* otherwise it is cleared(zero)
;*
;* Number of words :2
;* Number of cycles :2
;* Low registers used :None
;* High registers used :4
;*
;* Note: The contents of "cp1" will be overwritten.
;*
;
***************************************************************************
;***** Code
cp16: cp cp1l,cp2l ;Compare low byte
cpc cp1h,cp2h ;Compare high byte with
carry from
;previous operation
ncp16:
;Expected result is Z=0
;
***************************************************************************
;*
;* "cpi16" - Comparing 16-bit register with 16-bit
immediate
;*
;* This example compares the register pairs (cpi1l,
cpi1h) with the value
;* cpi2. If they are equal the zero flag is set(one),
otherwise it is
;* cleared(zero). This is enabled by the AVR's zero
propagation. Carry is
;* also set if the result is negative. This means that
all conditional
;* branch instructions can be used after the
comparison.
;*
;* Number of words :3
;* Number of cycles :3
;* Low registers used :None
;* High registers used :3
;*
;*
;
***************************************************************************
;***** Code
cpi16: cpi cp1l,low(cp2) ;Compare low byte
ldi c_tmp,high(cp2) ;
cpc cp1h,c_tmp ;Compare high byte
;
***************************************************************************
;*
;* "neg16" - Negating 16-bit register
;*
;* This example negates the register pair (ng1l,ng1h)
The result will
;* overwrite the register pair.
;*
;* Number of words :4
;* Number of cycles :4
;* Low registers used :None
;* High registers used :2
;*
;
***************************************************************************
;***** Code
ng16:
com ng1l ;Invert low byte ;
Calculated by
com ng1h ;Invert high byte ;
incverting all
subi ng1l,low(-1) ;Add 0x0001, low byte ;
bits then adding
sbci ng1h,high(-1) ;Add high byte ;
one (0x0001)
;Expected result is 0xCBEE
;
***************************************************************************
;*
;* End of examples.
;*
;
***************************************************************************
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
.include "8515def.inc"
.listmac ;split Toggle_mode at AVR
Studio
.cseg ;press Step_Over
etceteras of
rjmp Demo ;trace Registers and
Memory
;
***************************************************************************
;# # # # # # # # # Assign Math32 Symbol and
Notation # # # # # # # # #
;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;*
;* Add32[sign], Sub32[sign], Mul32[b|w|t], Div32[b|w|
t] :
;* operand1
operand2 result
;* r20r21r22r23 +|-|*|/ r16r17r18r19 =
r20r21r22r23[r24r25r26r27]
;*
;* Com32, Neg32 : Bin2BCD20,
BCD2bin20 :
;* operand result
operand result
;* r20r21r22r23 >>> r20r21r22r23 r20r21[r22]
>>> r20r21[r22]
;*
;* BCD3bin, Bin3BCD, Bin4BCD : Bin2BCD16,
BCD2bin16 :
;* operand result
operand result
;* r16...r23 >>> r20r21r22[r23[r24]] r16r17
[r18] >>> r20r21[r22]
;*
;
***************************************************************************
.set ObXXXX=0b1111 ;default load & store memory
variable bitmap upon
;little-endian format of numbers, i.e. abs.address(LSB)
< abs.address(MSB)
;
***************************************************************************
;*
;* Initialize Memory in Math Data Space
;*
;* First 512+127 bytes of data space can be initialize
in 0 or 0xff
;* Limit: if Flag T==1 then EachMemoryByte=0 else
EachMemoryByte=0xff
;*
;
***************************************************************************
.def MathPattern=r28 ;YL
.def MathCounter=r29 ;YH
;
***************************************************************************
;*
;* Registers Load from Math Data Space
;*
;* Load: r16r17r18r19r20r21r22r23 from first 512+3
bytes of data space
;* operand2 operand1 (max starting
address: 0x1ff)
;*
;
***************************************************************************
.def MathBmp=r26 ;only XL,XH from high registers
.def MathTmp=r27 ;do not keep useful data or not
used below
;
***************************************************************************
;*
;* Registers Save to Math Data Space
;*
;* Save: r20r21r22r23r24r25r26r27 to first 512
+7 bytes of data space
;* result (remainder) (max starting
address: 0x1ff)
;*
;
***************************************************************************
.def MathBmp=r0 ;all high registers keep useful
data or used below
sec ;
cpse ZH,ZH ;skip next
instruction
R20MathSave: clc ;
mov MathBmp,ZH ;copy bitmap
cbr ZH,0xfe ;Z points to math
data space
ror MathBmp ;now bitmap have
all 8 bits
ldi YL,20 ;Y points to result
LSB
MathSaveNext: clr YH ;
ld YH,Y+ ;in order to not
use other registers
sbrc MathBmp,0 ;if bit 0 bitmap
not clear
st Z+,YH ; store
result byte to memory
lsr MathBmp ;
brne MathSaveNext ;while not empty
bitmap
ret ;
.equ MathSave=R20MathSave ;default registers save call
;
***************************************************************************
;*
;* Add32 == 32+32 Bit Unsigned Addition
;*
;* add1L::add1H + add2L::add2H = add1L::add1H
;* item item sum
;* r20r21r22r23 + r16r17r18r19 = r20r21r22r23
;*
;
***************************************************************************
.def add20 = r16 ; item 2 byte 0 (LSB)
.def add21 = r17 ; item 2 byte 1
.def add22 = r18 ; item 2 byte 2
.def add23 = r19 ; item 2 byte 3 (MSB)
.def add10 = r20 ; item 1 byte 0 (LSB)
.def add11 = r21 ; item 1 byte 1
.def add12 = r22 ; item 1 byte 2
.def add13 = r23 ; item 1 byte 3 (MSB)
;
***************************************************************************
;*
;* Sub32 == 32-32 Bit Unsigned Subtraction
;*
;* sub1L::sub1H - sub2L::sub2H = sub1L::sub1H
;* minuend subtrahend difference
;* r20r21r22r23 - r16r17r18r19 = r20r21r22r23
;*
;
***************************************************************************
.def sub20 = r16 ; subtrahend byte 0 (LSB)
.def sub21 = r17 ; subtrahend byte 1
.def sub22 = r18 ; subtrahend byte 2
.def sub23 = r19 ; subtrahend byte 3 (MSB)
.def sub10 = r20 ; minuend byte 0 (LSB)
.def sub11 = r21 ; minuend byte 1
.def sub12 = r22 ; minuend byte 2
.def sub13 = r23 ; minuend byte 3 (MSB)
;
***************************************************************************
;*
;* Mul32 == 32x32 Bit Unsigned Multiplication
;*
;* mp32uL::mp32uH x mc32uL::mc32uH = m32uL::m32uH
;* multiplier multiplicand result
;* r20r21r22r23 x r16r17r18r19 =
r20r21r22r23r24r25r26r27
;*
;
***************************************************************************
.def mc32u0 =r16 ; multiplicand byte 0 (LSB)
.def mc32u1 =r17 ; multiplicand byte 1
.def mc32u2 =r18 ; multiplicand byte 2
.def mc32u3 =r19 ; multiplicand byte 3 (MSB)
.def mp32u0 =r20 ; multiplier byte 0 (LSB)
.def mp32u1 =r21 ; multiplier byte 1
.def mp32u2 =r22 ; multiplier byte 2
.def mp32u3 =r23 ; multiplier byte 3 (MSB)
.def m32u0 =r20 ; result byte 0 (LSB)
.def m32u1 =r21 ; result byte 1
.def m32u2 =r22 ; result byte 2
.def m32u3 =r23 ; result byte 3
.def m32u4 =r24 ; result byte 4
.def m32u5 =r25 ; result byte 5
.def m32u6 =r26 ; result byte 6
.def m32u7 =r27 ; result byte 7 (MSB)
.def mcnt32u =r28 ; loop counter
;
***************************************************************************
;*
;* Div32 == 32/32 Bit Unsigned Division
;*
;* dd32uL::dd32uH / dv32uL::dv32uH = dres32uL::dres32uH
(drem32uL::drem32uH)
;* dividend divisor
result remainder
;* r20r21r22r23 / r16r17r18r19 =
r20r21r22r23 r24r25r26r27
;*
;
***************************************************************************
.def dv32u0 =r16 ; divisor byte 0 (LSB)
.def dv32u1 =r17 ; divisor byte 1
.def dv32u2 =r18 ; divisor byte 2
.def dv32u3 =r19 ; divisor byte 3 (MSB)
.def dres32u0 =r20 ; result byte 0 (LSB)
.def dres32u1 =r21 ; result byte 1
.def dres32u2 =r22 ; result byte 2
.def dres32u3 =r23 ; result byte 3 (MSB)
.def dd32u0 =r20 ; dividend byte 0 (LSB)
.def dd32u1 =r21 ; dividend byte 1
.def dd32u2 =r22 ; dividend byte 2
.def dd32u3 =r23 ; dividend byte 3 (MSB)
.def drem32u0 =r24 ; remainder byte 0 (LSB)
.def drem32u1 =r25 ; remainder byte 1
.def drem32u2 =r26 ; remainder byte 2
.def drem32u3 =r27 ; remainder byte 3 (MSB)
.def dcnt32u =r28 ; loop counter
;
***************************************************************************
;*
;* BCD2bin == BCD to 16-Bit Binary Conversion
;*
;* fBCD0:fBCD1:fBCD2 >>> tbinL:tbinH
;* dec hex
;* r16r17r18 >>> r20r21
;*
;
***************************************************************************
.def fBCD0 =r16 ; BCD value digits 0 and 1
.def fBCD1 =r17 ; BCD value digits 2 and 3
.def fBCD2 =r18 ; BCD value digit 4 (MSD is
lowermost nibble)
.def mp10L =r20 : Low byte of number to be
multiplied by 10
.def mp10H =r21 ; High byte of number to be
multiplied by 10
.def tbinL =r20 ; Low byte of binary result
(same as mp10L)
.def tbinH =r21 ; High byte of binary
result (same as mp10H)
.def copyL =r22 ; temporary register
.def copyH =r23 ; temporary register
;
***************************************************************************
;*
;* BCD3bin == BCD to 24-Bit Binary Conversion
;*
;* fBCD0:fBCD1:fBCD2:fBCD3 >>> tbin0:tbin1:tbin2
;* dec hex
;* r16r17r18r19 >>> r20r21r22
;*
;
***************************************************************************
.def fBCD0 =r16 ; BCD value digits 0 and 1
.def fBCD1 =r17 ; BCD value digits 2 and 3
.def fBCD2 =r18 ; BCD value digits 4 and 5
.def fBCD3 =r19 ; BCD value digits 6 and 7
(MSD is 0|1)
.def tbin0 =r20 ; binary value byte 0 (LSB)
.def tbin1 =r21 ; binary value byte 1
.def tbin2 =r22 ; binary value byte 2 (MSB)
;
***************************************************************************
;*
;* Bin2BCD == 16-bit Binary to BCD conversion
;*
;* fbinL:fbinH >>> tBCD0:tBCD1:tBCD2
;* hex dec
;* r16r17 >>> r20r21r22
;*
;
***************************************************************************
.def fbinL =r16 ; binary value Low byte
.def fbinH =r17 ; binary value High byte
.def tBCD0 =r20 ; BCD value digits 0 and 1
.def tBCD1 =r21 ; BCD value digits 2 and 3
.def tBCD2 =r22 ; BCD value digit 4 (MSD is
lowermost nibble)
;
***************************************************************************
;*
;* Bin4BCD == 32-bit Binary to BCD conversion
[ together with Bin2BCD ]
;*
;* fbin0:fbin1:fbin2:fbin3 >>> tBCD0:tBCD1:tBCD2:
tBCD3:tBCD4
;* hex dec
;* r18r19r20r21 >>> r20r21r22r23r24
;*
;
***************************************************************************
.def fbin0 =r18 ; binary value byte 0 (LSB)
.def fbin1 =r19 ; binary value byte 1
.def fbin2 =r20 ; binary value byte 2
.def fbin3 =r21 ; binary value byte 3 (MSB)
.def tBCD0 =r20 ; BCD value digits 0 and 1
(same as fbin2)
.def tBCD1 =r21 ; BCD value digits 2 and 3
(same as fbin3)
.def tBCD2 =r22 ; BCD value digits 4 and 5
.def tBCD3 =r23 ; BCD value digits 6 and 7
.def tBCD4 =r24 ; BCD value digits 8 and 9
(MSD)
;
***************************************************************************
;*
;* Bin4BCD == 32-bit Binary to BCD conversion
;*
;* fbin0:fbin1:fbin2:fbin3 >>> tBCD0:tBCD1:tBCD2:
tBCD3:tBCD4
;* hex dec
;* r16r17r18r19 >>> r20r21r22r23r24
;*
;
***************************************************************************
.def fbin0 =r16 ; binary value byte 0 (LSB)
.def fbin1 =r17 ; binary value byte 1
.def fbin2 =r18 ; binary value byte 2
.def fbin3 =r19 ; binary value byte 3 (MSB)
.def tBCD0 =r20 ; BCD value digits 0 and 1
.def tBCD1 =r21 ; BCD value digits 2 and 3
.def tBCD2 =r22 ; BCD value digits 4 and 5
.def tBCD3 =r23 ; BCD value digits 6 and 7
.def tBCD4 =r24 ; BCD value digits 8 and 9
(MSD)
;
***************************************************************************
;*
;* Bin3BCD == 24-bit Binary to BCD conversion
[ together with Bin2BCD ]
;*
;* fbin0:fbin1:fbin2 >>> tBCD0:tBCD1:tBCD2:tBCD3
;* hex dec
;* r16r17r18 >>> r20r21r22r23
;*
;
***************************************************************************
.def fbin0 =r16 ; binary value byte 0 (LSB)
.def fbin1 =r17 ; binary value byte 1
.def fbin2 =r18 ; binary value byte 2 (MSB)
.def tBCD0 =r20 ; BCD value digits 0 and 1
.def tBCD1 =r21 ; BCD value digits 2 and 3
.def tBCD2 =r22 ; BCD value digits 4 and 5
.def tBCD3 =r23 ; BCD value digits 6 and 7
(MSD)
;
***************************************************************************
;*
;* Bin3BCD == 24-bit Binary to BCD conversion
;*
;* fbin0:fbin1:fbin2 >>> tBCD0:tBCD1:tBCD2:tBCD3
;* hex dec
;* r16r17r18 >>> r20r21r22r23
;*
;
***************************************************************************
.def fbin0 =r16 ; binary value byte 0 (LSB)
.def fbin1 =r17 ; binary value byte 1
.def fbin2 =r18 ; binary value byte 2 (MSB)
.def tBCD0 =r20 ; BCD value digits 0 and 1
.def tBCD1 =r21 ; BCD value digits 2 and 3
.def tBCD2 =r22 ; BCD value digits 4 and 5
.def tBCD3 =r23 ; BCD value digits 6 and 7
(MSD)
;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Demo: ;-)(-:-)(-;-)(-:-)(-;-)(-:-)(-;-)(-:-)(-;-)
(-:-)(-;-)(-:-)(-;-)(-:-)
;
***************************************************************************
;$ $ $ $ $ $ $ $ $ Illustrations with comments
field $ $ $ $ $ $ $ $ $
;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.dseg
Variable: .byte 4
VarWord1: .byte 2
VarWord2: .byte 2
Result: .byte 8
.equ Address1 =VarWord1
.equ Address2 =VarWord2
.equ Address =Variable
.set Constant =0x4321
.cseg
.def Temp =r16
.def TempL =r16
.def TempH =r17
.def Flags =r15
.equ _Flag1 =1
.equ _Flag2 =2
.equ _Flag3 =3
.equ _signResult=0
Operand Variable
Const16 0xffff<<16|0xffff
rcall Mul32 ;
0xffffffff * 0xffffffff
Result2 Result,0b11111111 ;
0xfffffffe00000001
Operand Variable
Const16 0x1010<<16|0x1010
rcall Div32 ;
0xffffffff / 0x10101010
Result2 Result,0b11111111 ; 0xf
(0x0f0f0f0f)
Operand Variable,0b111
Cnst16t 0x00ff<<16|0xffff
rcall Div32t ;
0xffffff / 0xffffff
Result2 Result ; 0x1 (0x0
no rollout)
Operand Variable,0b1100
Cnst16w 0xffff
rcall Div32w ;
0xffff0000 / 0xffff
Result2 Result ; 0x10000
(0x0 no rollout)
stsiw VarWord1,Temp,0x00ff
stsiw VarWord2,Temp,0xff00
rcall Formula ; -
0x125.9249 as result
stsiw VarWord1,Temp,0x0f0f
stsiw VarWord2,Temp,0xf0f0
rcall Formula ; 0x00ce.
a6dc as result
InitMem VarWord1,4,1 ;
0x2349.2392 at the end
ldiw Temp,Demo
pushw Temp ;getting
into demo loop
Formula:
MathR20 VarWord1,0b1100
Const16 0xfff<<16
rcall Sub32sign
Cnst16b 7
rcall Div32b
Result2 16 ;faster than call
MathR16 20
MathR16 20 ;included for
comparison only
MathR20 VarWord2,0b110
rcall Add32sign
bld Flags,_signResult
Result3 Result
.exit
;
***************************************************************************
;*
;* REMARK
;* Sometimes expression as macroparameter must be
enclosed in parentheses,
;* because they not are always present in above
macrocalls
;* (remember about the priority of AVR assembler
operators).
;* Accommodate oneself to ATmega: MOVW instruction e.
g., etc.
;*
;
***************************************************************************
;Feedback: please, include abbr."Math32" in Your e-mail
subject line (!spam)
;from time to time it is possible mailbox overflow &|
shut-down - I am sorry
;to make mention of http://www.i.com.ua/~birua when
occasion offers - Thanks
;All the best & good luck!
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
MATH YX PACKAGE
HOME
RETRO_DAN
;**** A P P L I C A T I O N N O T E A V R 2 0 2
ASM FORUM ************************
ASM MATH ;*
;* Title: 16-bit Arithmetics
TUTORIAL #1
;* Version: 1.1
TUTORIAL #2 ;* Last updated: 97.07.04
TUTORIAL #3 ;* Target: AT90Sxxxx (All AVR Devices)
;*
MATH 200 ;* Support E-mail: [email protected]
MATH 200b ;*
;* DESCRIPTION
MATH 201 ;* This application note lists applications for the
MATH 202 following
;* Add/Subtract/Compare operations:
MATH 32X
;*
MATH YX ;* "add16" ADD 16+16
;* "adddi16" ADD 16+Immediate(16)
DIV16 XX
;* "sub16" SUB 16-16
DIV 24 24 ;* "subi16" SUB 16-Immediate(16)
DIV 3216 ;* "cp16" COMPARE 16/16
;* "cpi16" COMPARE 16/Immediate
FLOAT 128 ;* "neg16" NEGATION 16
SQRT16 ;*
;
MATH 202 ***************************************************************************
MATH 202
.cseg
DEC ASCII
ldi r16,0x12 ;Set up some registers to
INT ASCII show usage of
ldi r17,0x34 ;the subroutines below.
HX2ASC
ldi r18,0x56 ;All expected results are
AVG8 222 presented as
FFT7 ldi r19,0x78 ;comments
COPY 102
LPM 108 ;
***************************************************************************
EPROM 100 ;*
SER EPROM ;* "add16" - Adding 16-bit registers
;*
DFLASH AT45
;* This example adds the two pairs of register
FLASH CARD variables (add1l,add1h)
;* and (add2l,add2h) The result is placed in (add1l,
VFX SMIL
add1h).
VFX MEM ;*
SORT 220 ;* Number of words :2
;* Number of cycles :2
CRC 236 ;* Low registers used :None
XMODEM REC ;* High registers used :4
;*
UART 304 ;* Note: The sum and the addend share the same
UART 305 register. This causes the
;* addend to be overwritten by the sum.
UART 128
;*
UART BUFF ;
***************************************************************************
USB 232
AVR ISP ;**** Register Variables
ISP 2313 .def add1l = r16
.def add1h = r17
ISP 1200 .def add2l = r18
AVR SPI .def add2h = r19
I2C 300 ;***** Code
I2C 302 add16: add add1l, add2l ;Add low
bytes
I2C TWI26
adc add1h, add2h ;Add high bytes
I2C/TWI 128 with carry
I2C/TWI AT8 ;Expected result is 0xAC68
DALLAS-1W
DALLAS CRC
;
ETHNET 8019 ***************************************************************************
TEA ;*
;* "addi16" - Adding 16-bit register with immediate
ADC 128 ;*
ADC 10B ;* This example adds a register variable (addi1l,
addi1h) with an
ADC 400
;* immediate 16-bit number defined with .equ-
ADC 401 statement. The result is
THERM 232 ;* placed in (addi1l, addi1h).
;*
IRD 410 ;* Number of words :2
LCD HD44 ;* Number of cycles :2
;* Low registers used :None
LCD 2313 ;* High registers used :2
LCD44 2313 ;*
;* Note: The sum and the addend share the same
KBD 240 register. This causes the
MUX 242 ;* addend to be overwritten by the sum.
;*
KBD PS2
;
KBD PC/128 ***************************************************************************
PS2 EMU
;***** Register Variables
BOOT MG8 .def addi1l = r16
BOOT DR8 .def addi1h = r17
PWM 10K
ENCODE
;
STH-11 ***************************************************************************
ATMEL CORP ;*
;* "sub16" - Subtracting 16-bit registers
AVR
;*
BUTTERFLY ;* This example subtracts two pairs of register
AVR BOOK variables (sub1l,sub1h)
;* from (sub2l, sub2h) The result is stored in
registers sub1l, sub1h.
;*
;* Number of words :2
;* Number of cycles :2
;* Low registers used :None
;* High registers used :4
;*
;* Note: The result and "sub1" share the same
register. This causes "sub1"
;* to be overwritten by the result.
;*
;
***************************************************************************
;***** Code
sub16: sub sub1l,sub2l ;Subtract
low bytes
sbc sub1h,sub2h ;Add high byte with
carry
;Expected result is 0x4646
;
***************************************************************************
;*
;* "subi16" - Subtracting immediate 16-bit number from
a 16-bit register
;*
;* This example subtracts the immediate 16-bit number
subi2 from the
;* 16-bit register (subi1l,subi1h) The result is
placed in registers
;* subi1l, subi1h.
;*
;* Number of words :2
;* Number of cycles :2
;* Low registers used :None
;* High registers used :2
;*
;* Note: The result and "subi1" share the same
register. This causes
;* "subi1" to be overwritten by the result.
;*
;
***************************************************************************
;***** Code
subi16: subi subi1l,low(subi2) ;Subtract
low bytes
sbci subi1h,high(subi2) ;Subtract high byte
with carry
;Expected result is 0x3412
;
***************************************************************************
;*
;* "cp16" - Comparing two 16-bit numbers
;*
;* This example compares the register pairs (cp1l,cp1h)
with the register
;* pairs (cp2l,cp2h) If they are equal the zero flag
is set(one)
;* otherwise it is cleared(zero)
;*
;* Number of words :2
;* Number of cycles :2
;* Low registers used :None
;* High registers used :4
;*
;* Note: The contents of "cp1" will be overwritten.
;*
;
***************************************************************************
;***** Code
cp16: cp cp1l,cp2l ;Compare low byte
cpc cp1h,cp2h ;Compare high byte with
carry from
;previous operation
ncp16:
;Expected result is Z=0
;
***************************************************************************
;*
;* "cpi16" - Comparing 16-bit register with 16-bit
immediate
;*
;* This example compares the register pairs (cpi1l,
cpi1h) with the value
;* cpi2. If they are equal the zero flag is set(one),
otherwise it is
;* cleared(zero). This is enabled by the AVR's zero
propagation. Carry is
;* also set if the result is negative. This means that
all conditional
;* branch instructions can be used after the
comparison.
;*
;* Number of words :3
;* Number of cycles :3
;* Low registers used :None
;* High registers used :3
;*
;*
;
***************************************************************************
;***** Code
cpi16: cpi cp1l,low(cp2) ;Compare low byte
ldi c_tmp,high(cp2) ;
cpc cp1h,c_tmp ;Compare high byte
;
***************************************************************************
;*
;* "neg16" - Negating 16-bit register
;*
;* This example negates the register pair (ng1l,ng1h)
The result will
;* overwrite the register pair.
;*
;* Number of words :4
;* Number of cycles :4
;* Low registers used :None
;* High registers used :2
;*
;
***************************************************************************
;***** Code
ng16:
com ng1l ;Invert low byte ;
Calculated by
com ng1h ;Invert high byte ;
incverting all
subi ng1l,low(-1) ;Add 0x0001, low byte ;
bits then adding
sbci ng1h,high(-1) ;Add high byte ;
one (0x0001)
;Expected result is 0xCBEE
;
***************************************************************************
;*
;* End of examples.
;*
;
***************************************************************************
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
DIV16 XX PACKAGE
HOME
RETRO_DAN
ASM FORUM ; DIVISION ROUTINES with scaled reciprocals for constants
ASM MATH ; (all functions optimized for speed, ~ <36 cycles w/o push/pop)
TUTORIAL #1
; Target: AVR MCUs with hardware multiplier ("mul" instruction)
TUTORIAL #2 ; Author: Andreas Lenze ([email protected])
TUTORIAL #3 ; Feb. 2003
EPROM 100 ; NOTE: Other divisor constants like /24 etc. can easily be created by
SER EPROM ; modifying the shift count in "Q = Q >> x": add 1 shift right for
; 'divisor x 2' (e.g. for "/24" we need a total of 20 instead of
DFLASH AT45
; the 19 shifts needed for "/12")
FLASH CARD
; If the remainder of the division is not needed, the multiply/subtract
VFX SMIL
; operation after the comment
VFX MEM ;
SORT 220 ; r19:r18 now "Q" (= result >> xx)
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_5"
;* Divides an unsigned 16 bit word (XH:XL) by 5
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xCCCD;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xCCCD) >> 18)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 38 (w. push/pop = 10 words)
;* cycles: 54 (w. push/pop = 20 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_5:
push r2
push r19
push r18
push r17
; Q = A * 0xCCCD
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_6"
;* Divides an unsigned 16 bit word (XH:XL) by 6
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xAAAB;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xAAAB) >> 18)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 38 (w. push/pop = 10 words)
;* cycles: 54 (w. push/pop = 20 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_6:
push r2
push r19
push r18
push r17
; Q = A * 0xAAAB
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_7"
;* Divides an unsigned 16 bit word (XH:XL) by 7
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0x2493;
;* unsigned int Q; /* the quotient */
;*
;* Q = (((A * 0x2493) >> 16) + A) >> 3 -> 17 bits reciprocal!
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 38 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_7:
push r2
push r19
push r18
push r17
; Q = A * 0x2493
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; Q = Q >> 3
ror r19 ; do the last 3 shifts, including
ror r18 ; carry (!) from previous addition
lsr r19
ror r18
lsr r19
ror r18
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_7a"
;* Divides an unsigned 16 bit word (XH:XL) by 7
;* Call with 16 bit number in XH:XL
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* (Equations partly by D. W. Jones)
;*
;* Reciprocal multiplication w. extra precision:
;* (This version uses correction to achieve the required precision)
;* unsigned int R; /* remainder */
;* unsigned int long A; /* dividend */
;* unsigned int long Q; /* quotient */
;*
;* Q = ((A * 0x9249) >> 18)
;*
;* /* Q = A/7 or Q+1 = A/7 for all A <= 65535 */
;* /* correct Q and calculate remainder */
;* R = A - 7*Q
;* if (R >= 7) {
;* R = R - 7;
;* Q = Q + 1;
;* }
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 59 (w. push/pop = 20 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_7a:
push r2
push r19
push r18 ; Tmp3
push r17 ; Tmp2
; Q = A * 0x9249
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_9"
;* Divides an unsigned 16 bit word (XH:XL) by 9
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xE38F;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xE38F) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_9:
push r2
push r19
push r18
push r17
; Q = A * 0xE38F
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_10"
;* Divides an unsigned 16 bit word (XH:XL) by 10
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xCCCD;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xCCCD) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_10:
push r2
push r19
push r18
push r17
; Q = A * 0xCCCD
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_11"
;* Divides an unsigned 16 bit word (XH:XL) by 11
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xBA2F;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xBA2F) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_11:
push r2
push r19
push r18
push r17
; Q = A * 0xBA2F
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_12"
;* Divides an unsigned 16 bit word (XH:XL) by 12
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xAAAB;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xAAAB) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_12:
push r2
push r19
push r18
push r17
; Q = A * 0xAAAB
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_13"
;* Divides an unsigned 16 bit word (XH:XL) by 13
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0x9D89;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0x9D8A) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_13:
push r2
push r19
push r18
push r17
; Q = A * 0x9D8A
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_14"
;* Divides an unsigned 16 bit word (XH:XL) by 14
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0x2493;
;* unsigned int Q; /* the quotient */
;*
;* Q = (((A * 0x2493) >> 16) + A) >> 4 -> 17 bits reciprocal!
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 40 (w. push/pop = 8 words)
;* cycles: 44 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_14:
push r2
push r19
push r18
push r17
; Q = A * 0x2493
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; Q = Q >> 4
ror r19 ; do the last 4 shifts, including
ror r18 ; carry (!) from previous addition
lsr r19
ror r18
lsr r19
ror r18
lsr r19
ror r18
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_15"
;* Divides an unsigned 16 bit word (XH:XL) by 15
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0x8889;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0x8889) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_15:
push r2
push r19
push r18
push r17
; Q = A * 0x8889
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_17"
;* Divides an unsigned 16 bit word (XH:XL) by 17
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xF0F1;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xF0F1) >> 20)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 38 (w. push/pop = 10 words)
;* cycles: 44 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_17:
push r2
push r19
push r18
push r17
; Q = A * 0xF0F1
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_18"
;* Divides an unsigned 16 bit word (XH:XL) by 18
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xE38F;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xE38F) >> 20)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 38 (w. push/pop = 10 words)
;* cycles: 44 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_18:
push r2
push r19
push r18
push r17
; Q = A * 0xE38F
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_19"
;* Divides an unsigned 16 bit word (XH:XL) by 19
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0x6BCA;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0x6BCB) >> 19)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_19:
push r2
push r19
push r18
push r17
; Q = A * 0x6BCB
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_20"
;* Divides an unsigned 16 bit word (XH:XL) by 20
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xCCCD;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xCCCD) >> 20)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_20:
push r2
push r19
push r18
push r17
; Q = A * 0xCCCD
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_21"
;* Divides an unsigned 16 bit word (XH:XL) by 21
;* Call with 16 bit number in XH:XL
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* (Equations partly by D. W. Jones)
;*
;* Reciprocal multiplication w. extra precision:
;* (uses correction to achieve the required precision)
;* unsigned int R; /* remainder */
;* unsigned int long A; /* dividend */
;* unsigned int long Q; /* quotient */
;*
;* Q = ((A * 0xC30B) >> 20)
;*
;* /* Q = A/21 or Q+1 = A/21 for all A <= 65535 */
;* /* correct Q and calculate remainder */
;* R = A - 21*Q
;* if (R >= 21) {
;* R = R - 21;
;* Q = Q + 1;
;* }
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 40 (w. push/pop = 8 words)
;* cycles: 52 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_21:
push r2
push r19
push r18
push r17
; Q = A * 0xC30B
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_22"
;* Divides an unsigned 16 bit word (XH:XL) by 22
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* Equations by D: W. Jones:
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = 0xBA2F;
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * 0xBA2F) >> 20)
;*
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 46 (w. push/pop = 16 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_22:
push r2
push r19
push r18
push r17
; Q = A * 0xBA2F
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
;*
;* Function "Div16_23"
;* Divides an unsigned 16 bit word (XH:XL) by 23
;* Call with 16 bit number in XH:XL
;* Returns quotient in YH:YL and remainder in XL
;*
;* Author: Andreas Lenze ([email protected])
;* (Equations partly by D. W. Jones)
;*
;* Reciprocal multiplication w. extra precision:
;* (uses correction to achieve the required precision)
;* unsigned int R; /* remainder */
;* unsigned int long A; /* dividend */
;* unsigned int long Q; /* quotient */
;*
;* Q = ((A * 0xB215) >> 20)
;*
;* /* Q = A/23 or Q+1 = A/23 for all A <= 65535 */
;* /* correct Q and calculate remainder */
;* R = A - 1*Q
;* if (R >= 23) {
;* R = R - 23;
;* Q = Q + 1;
;* }
;* Uses: high regs: 7 (r17, r18, r19, X, Y)
;* low regs: 3 (r0, r1, r2)
;*
;* words: 36 (w. push/pop = 8 words)
;* cycles: 59 (w. push/pop = 20 cycles)
;*
;* Note: Hardware multiplier required ("mul" instruction)
;*
;***************************************************************************
Div16_23:
push r2
push r19
push r18
push r17
; Q = A * 0xB215
; (r19:r18:r17[:rXX] = XH:XL * YH:YL)
clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to [rXX] is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; XL holds "R"
; YH:YL holds "Q"
pop r17
pop r18
pop r19
pop r2
ret
;***************************************************************************
; macro definition to call/use "division by xx" - module (D16_nn)
macro Div16by
push r20
ldi r20,@0
call D16_nn
pop r20
.endm
;***************************************************************************
;***************************************************************************
;*
;* Function "D16_nn"
;* Divides an unsigned 16 bit word by [2] -> [23]
;* Note: divisor 2, 4, 8, 16 options are provided for remainder calculation
;* and (for ease-of-use) to cover the complete divisors range (2-23)
;*
;* Call with dividend loaded to XH:XL (high/low bytes)
;* Returns quotient in YH:YL and remainder in XL
;*
;* Usage: define the macro "Div16by" prior to using the function,
;* use macro with divisor as parameter, e.g. "Div16by 17" to
;* divide XH:XL by 17 decimal
;*
;* .macro Div16_by
;* push r20
;* ldi r20,@0
;* call D16_nn
;* pop r20
;* .endm
;*
;* Author: Andreas Lenze ([email protected])
;* Feb. 2003
;* Equations mostly by D. W. Jones
;*
;* Reciprocal mul w. extra precision:
;* unsigned int A;
;* unsigned int scaled_reciprocal = xxxx
;* unsigned int Q; /* the quotient */
;*
;* Q = ((A * scaled_reciprocal) >> 16) >> nn
;* or
;* Q = (((A * scaled_reciprocal) >> 16) + A) >> nn -> for /7 and /14
;*
;* /* special case: use correction for Q (e.g. for /21, /23) */
;* if (R >= divisor)
;* R = R - divisor;
;* Q = Q + 1;
;*
;* div. by n: scaled reciprocal: shift count:
;*
;* 2 - 1
;* 3 1010101010101011 AAAB 17
;* 4 - 2
;* 5 1100110011001101 CCCD 18
;* 6 1010101010101011 AAAB 18
;* 7 10010010010010011 19 -> 17 bits req'd,(MSB=1,rest 2493h)
;* 8 - 3
;* 9 1110001110001111 E38F 19
;* 10 1100110011001101 CCCD 19
;* 11 1011101000101111 BA2F 19
;* 12 1010101010101011 AAAB 19
;* 13 1001110110001010 9D8A 19
;* 14 10010010010010011 20 -> 17 bits req'd,(MSB=1,rest 2493h)
;* 15 1000100010001001 8889 19
;* 16 - 4
;* 17 1111000011110001 F0F1 20
;* 18 1110001110001111 E38F 20
;* 19 0110101111001011 6BCB 19
;* 20 1100110011001101 CCCD 20
;* 21 1100001100001011 C30B 20 -> needs correction for accurate
result
;* 22 1011101000101111 BA2F 20
;* 23 1011001000010101 B215 20 -> needs correction for accurate
result
;*
;* Uses: high regs: 11 (r16, r17, r18, r19, r20, X, Y, Z)
;* low regs: 3 (r0, r1, r2)
;* regs 16-20 saved, all others destroyed
;* T-flag destroyed (cleared)
;*
;* words: 97 (incl. 5 words for macro)
;* cycles: 85-111 (w. call/ret & macro), typically 102
;* table bytes: 66
;*
;* Target: AVR MCUs with hardware multiplier ("mul" instruction and
;* "lpm rd,Z/Z+" functionality required)
;*
;***************************************************************************
D16_nT:
; look-up table for D16_nn: 3 bytes per entry, range for divisor "2" to "23"
; data format: 2 bytes scaled reciprocal (word, high/low), 3rd byte
"flags"
.cseg
.db 0x00, 0xFF, 0x01, 0xAA, 0xAB, 0x01, 0x00, 0xFF, 0x02, 0xCC, 0xCD, 0x02,
0xAA, 0xAB
;
by /2 /3 /4 /5 /6
.db 0x02, 0x24, 0x93, 0x13, 0x00, 0xFF, 0x03, 0xE3, 0x8F, 0x03, 0xCC, 0xCD,
0x03, 0xBA
;
by /7 /8 /9 /10 /11
.db 0x2F, 0x03, 0xAA, 0xAB, 0x03, 0x9D, 0x8A, 0x03, 0x24, 0x93, 0x14, 0x88,
0x89, 0x03
;by /12 /13 /14 /15
.db 0x00, 0xFF, 0x04, 0xF0, 0xF1, 0x04, 0xE3, 0x8F, 0x04, 0x6B, 0xCB, 0x03,
0xCC, 0xCD
;
by /16 /17 /18 /19 /20
.db 0x04, 0xC3, 0x0B, 0x04, 0xBA, 0x2F, 0x04, 0xB2, 0x15, 0x04
;by /21 /22 /23
D16_nn:
push r19 ; save scrap regs
push r18
push r17
push r16
ldi ZH,high(D16_nT*2)
ldi ZL,low(D16_nT*2)
clr r2
mov r1,r20
lsl r20 ; x2 (3 bytes per entry)
add r20,r1 ; + org value = x3
add ZL,r20 ; point Z to divisor's data table position
adc ZH,r2
; Q = A * scaled_reciprocal
; (r19:r18:r17:r16 = XH:XL * YH:YL)
D16_1: clr r2
mul XH, YH ; ah * bh
movw r19:r18, r1:r0
mul XL, YL ; al * bl
mov r17,r1 ; r0 to r16 is superfluous
mul XH, YL ; ah * bl
add r17, r0
adc r18, r1
adc r19, r2
mul YH, XL ; bh * al
add r17, r0
adc r18, r1
adc r19, r2
; Q = Q >> 4
D16_3: swap r18 ; 4 normal shifts
swap r19
andi r18,0x0F
eor r18,r19
andi r19,0x0F
eor r18,r19
rjmp D16_9
; Q = (Q + A) >> 3-4
D16_4: set
D16_5: add r18,XL ; (Q + A)
adc r19,XH
ror r19 ; 3-4 "special" shifts, include
ror r18 ; carry from previous addition into 1st shift
D16_6: lsr r19
ror r18
D16_7: lsr r19
ror r18
brts D16_9 ; if T-flag set, skip this shift
D16_8: lsr r19
ror r18
; XL = "R" (remainder)
; /* use correction - can be omitted if /21, /23 are not used */
; if (R >= divisor)
; R = R - divisor;
; Q = Q + 1;
cp XL,r16
brlo PC+3
sub XL,r16
adiw YL,1
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
Atmel AVR From Wikipedia, the free encyclopedia (Redirected from Avr)
Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language Atmel AVR From Wikipedia,
the free encyclopedia (Redirected from Avr) Jump to: navigation, search
The AVRs are a family of RISC microcontrollers from Atmel. Their internal
architecture was conceived by two students: Alf-Egil Bogen and Vegard
Wollan, at the Norwegian Institute of Technology (NTH] and further
developed at Atmel Norway, a subsidiary founded by the two architects.
Atmel recently released the Atmel AVR32 line of microcontrollers. These
are 32-bit RISC devices featuring SIMD and DSP instructions, along with
many additional features for audio and video processing, intended to
compete with ARM based processors. Note that the use of "AVR" in this
article refers to the 8-bit RISC line of Atmel AVR Microcontrollers. The
acronym AVR has been reported to stand for Advanced Virtual RISC. It's
also rumoured to stand for the company's founders: Alf and Vegard, who
are evasive when questioned about it. Contents [hide] 1 Device Overview
1.1 Program Memory 1.2 Data Memory and Registers 1.3 EEPROM 1.4
Program Execution 1.5 Speed 2 Development 3 Features 4 Footnotes 5 See
also 6 External Links 6.1 Atmel Official Links 6.2 AVR Forums & Discussion
Groups 6.3 Machine Language Development 6.4 C Language Development
6.5 BASIC & Other AVR Languages 6.6 AVR Butterfly Specific 6.7 Other
AVR Links [edit] Device Overview The AVR is a Harvard architecture
machine with programs and data stored and addressed separately. Flash,
EEPROM, and SRAM are all integrated onto a single die, removing the need
for external memory (though still available on some devices). [edit]
Program Memory Program instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either 16 or 32 bits in length.
The Flash memory is addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the device itself. For
instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two
memory spaces (000016-001F16) followed by the 64 I/O registers (002016-
005F16). The actual usable RAM starts after both these sections (address
006016). (Note that the I/O register space may be larger on some more
extensive devices, in which case memory mapped I/O registers will occupy
a portion of the SRAM.) Even though there are separate addressing
schemes and optimized opcodes for register file and I/O register access, all
can still be addressed and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM. This is most often used
for long-term parameter storage to be retrieved even after cycling the
power of the device. [edit] Program Execution Atmel's AVRs have a single
level pipeline design. The next machine instruction is fetched as the
current one is executing. Most instructions take just one or two clock
cycles, making AVRs relatively fast among the eight-bit microcontrollers.
The AVR family of processors were designed for the efficient execution of
compiled C code. The AVR instruction set is more orthogonal than most
eight-bit microcontrollers, however, it is not completely regular: Pointer
registers X, Y, and Z have addressing capabilities that are different from
each other. Register locations R0 to R15 have different addressing
capabilities than register locations R16 to R31. I/O ports 0 to 31 have
different addressing capabilities than I/O ports 32 to 63. CLR affects flags,
while SER does not, even though they are complementary instructions.
CLR set all bits to zero and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead CLR is syntactic
sugar for [produces the same machine code as] EOR R,R while SER is
syntactic sugar for LDI R,$FF. Math operations such as EOR modify flags
while moves/loads/stores/branches such as LDI do not.) [edit] Speed The
AVR line can normally support clock speeds from 0-16MHz, with some
devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations
on the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due to the free and
inexpensive development tools available, including reasonably priced
development boards and free development software. The AVRs are
marketed under various names that share the same basic core but with
different peripheral and memory combinations. Some models (notably, the
ATmega range) have additional instructions to make arithmetic faster.
Compatibility amongst chips is fairly good. See external links for sites
relating to AVR development. [edit] Features Current AVRs offer a wide
range of features: RISC Core Running Many Single Cycle Instructions
Multifunction, Bi-directional I/O Ports with Internal, Configurable Pull-up
Resistors Multiple Internal Oscillators Internal, Self-Programmable
Instruction Flash Memory up to 256K In-System Programmable using ICSP,
JTAG, or High Voltage methods Optional Boot Code Section with
Independent Lock Bits for Protection Internal Data EEPROM up to 4KB
Internal SRAM up to 8K 8-Bit and 16-Bit Timers PWM Channels & dead time
generator Lighting (PWM Specific) Controller models Dedicated I²C
Compatible Two-Wire Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,RS-485, and more) Serial
Peripheral Interface (SPI) CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with embedded AVR. Also
freely available low-speed (HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or Three-Wire
Synchronous Data Transfer Analog Comparators LCD Controller Support
10-Bit A/D Converters, with multiplex of up to 16 channels Brownout
Detection Watchdog Timer (WDT) Low-voltage Devices Operating Down to
1.8v Multiple Power-Saving Sleep Modes picoPower Devices Atmel AVR
assembler programming language Atmel AVR machine programming
language Atmel AVR From Wikipedia, the free encyclopedia (Redirected
from Avr) Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language
EPROM 100
SER EPROM
DFLASH AT45
FLASH CARD
VFX SMIL
VFX MEM
SORT 220
CRC 236
XMODEM REC
UART 304 Programming the AVR Microcontrollers in Machine Language
UART 305
UART 128 AVR
UART BUFF << Prev | Ring Hub | Join | Rate| Next
USB 232 >>
© WebRing Inc. Search
AVR ISP
ISP 2313
ISP 1200
Atmel AVR From Wikipedia, the free encyclopedia
AVR SPI
I2C 300
(Redirected from Avr) Jump to: navigation, search
I2C 302 The AVRs are a family of RISC microcontrollers
I2C TWI26
from Atmel. Their internal architecture was
I2C/TWI 128
I2C/TWI AT8
conceived by two students: Alf-Egil Bogen and
DALLAS-1W Vegard Wollan, at the Norwegian Institute of
DALLAS CRC
Technology (NTH] and further developed at Atmel
ETHNET 8019
TEA
Norway, a subsidiary founded by the two architects.
ADC 128 Atmel recently released the Atmel AVR32 line of
ADC 10B
microcontrollers. These are 32-bit RISC devices
ADC 400
ADC 401
featuring SIMD and DSP instructions, along with
THERM 232 many additional features for audio and video
IRD 410
processing, intended to compete with ARM based
LCD HD44
LCD 2313
processors. Note that the use of "AVR" in this
LCD44 2313 article refers to the 8-bit RISC line of Atmel AVR
KBD 240 Microcontrollers. The acronym AVR has been
MUX 242
KBD PS2
reported to stand for Advanced Virtual RISC. It's
KBD PC/128 also rumoured to stand for the company's founders:
PS2 EMU Alf and Vegard, who are evasive when questioned
BOOT MG8
BOOT DR8
about it. Contents [hide] 1 Device Overview 1.1
ALM CLK Program Memory 1.2 Data Memory and Registers
CLOCK 8564 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
90 DAYS
DELAYS
Development 3 Features 4 Footnotes 5 See also 6
CALL ID External Links 6.1 Atmel Official Links 6.2 AVR
DTMF 314 Forums & Discussion Groups 6.3 Machine
PWM 6CH
PWM 10K
Language Development 6.4 C Language
ENCODE Development 6.5 BASIC & Other AVR Languages 6.6
STH-11 AVR Butterfly Specific 6.7 Other AVR Links [edit]
ATMEL CORP
AVR
Device Overview The AVR is a Harvard architecture
BUTTERFLY machine with programs and data stored and
AVR BOOK
addressed separately. Flash, EEPROM, and SRAM
are all integrated onto a single die, removing the
need for external memory (though still available on
some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either
16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the
device itself. For instance, the ATmega64x line has
64Kbytes of Flash. Almost all AVR devices are self-
programmable. [edit] Data Memory and Registers
The data address space consists of the register file,
I/O registers, and SRAM. The AVRs have thirty-two
single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the
first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16).
The actual usable RAM starts after both these
sections (address 006016). (Note that the I/O
register space may be larger on some more
extensive devices, in which case memory mapped I/
O registers will occupy a portion of the SRAM.)
Even though there are separate addressing
schemes and optimized opcodes for register file
and I/O register access, all can still be addressed
and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM.
This is most often used for long-term parameter
storage to be retrieved even after cycling the power
of the device. [edit] Program Execution Atmel's
AVRs have a single level pipeline design. The next
machine instruction is fetched as the current one is
executing. Most instructions take just one or two
clock cycles, making AVRs relatively fast among the
eight-bit microcontrollers. The AVR family of
processors were designed for the efficient
execution of compiled C code. The AVR instruction
set is more orthogonal than most eight-bit
microcontrollers, however, it is not completely
regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each
other. Register locations R0 to R15 have different
addressing capabilities than register locations R16
to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects
flags, while SER does not, even though they are
complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead
CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic
sugar for LDI R,$FF. Math operations such as EOR
modify flags while moves/loads/stores/branches
such as LDI do not.) [edit] Speed The AVR line can
normally support clock speeds from 0-16MHz, with
some devices reaching 20MHz. Lower powered
operation usually requires a reduced clock speed.
All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry.
Because many operations on the AVR are single
cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due
to the free and inexpensive development tools
available, including reasonably priced development
boards and free development software. The AVRs
are marketed under various names that share the
same basic core but with different peripheral and
memory combinations. Some models (notably, the
ATmega range) have additional instructions to make
arithmetic faster. Compatibility amongst chips is
fairly good. See external links for sites relating to
AVR development. [edit] Features Current AVRs
offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-
directional I/O Ports with Internal, Configurable Pull-
up Resistors Multiple Internal Oscillators Internal,
Self-Programmable Instruction Flash Memory up to
256K In-System Programmable using ICSP, JTAG,
or High Voltage methods Optional Boot Code
Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up
to 8K 8-Bit and 16-Bit Timers PWM Channels & dead
time generator Lighting (PWM Specific) Controller
models Dedicated I²C Compatible Two-Wire
Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,
RS-485, and more) Serial Peripheral Interface (SPI)
CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with
embedded AVR. Also freely available low-speed
(HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or
Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D
Converters, with multiplex of up to 16 channels
Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple
Power-Saving Sleep Modes picoPower Devices
Atmel AVR assembler programming language Atmel
AVR machine programming language Atmel AVR
From Wikipedia, the free encyclopedia (Redirected
from Avr) Jump to: navigation, search The AVRs are
a family of RISC microcontrollers from Atmel. Their
internal architecture was conceived by two
students: Alf-Egil Bogen and Vegard Wollan, at the
Norwegian Institute of Technology (NTH] and further
developed at Atmel Norway, a subsidiary founded
by the two architects. Atmel recently released the
Atmel AVR32 line of microcontrollers. These are 32-
bit RISC devices featuring SIMD and DSP
instructions, along with many additional features for
audio and video processing, intended to compete
with ARM based processors. Note that the use of
"AVR" in this article refers to the 8-bit RISC line of
Atmel AVR Microcontrollers. The acronym AVR has
been reported to stand for Advanced Virtual RISC.
It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when
questioned about it. Contents [hide] 1 Device
Overview 1.1 Program Memory 1.2 Data Memory and
Registers 1.3 EEPROM 1.4 Program Execution 1.5
Speed 2 Development 3 Features 4 Footnotes 5 See
also 6 External Links 6.1 Atmel Official Links 6.2
AVR Forums & Discussion Groups 6.3 Machine
Language Development 6.4 C Language
Development 6.5 BASIC & Other AVR Languages 6.6
AVR Butterfly Specific 6.7 Other AVR Links [edit]
Device Overview The AVR is a Harvard architecture
machine with programs and data stored and
addressed separately. Flash, EEPROM, and SRAM
are all integrated onto a single die, removing the
need for external memory (though still available on
some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either
16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the
device itself. For instance, the ATmega64x line has
64Kbytes of Flash. Almost all AVR devices are self-
programmable. [edit] Data Memory and Registers
The data address space consists of the register file,
I/O registers, and SRAM. The AVRs have thirty-two
single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the
first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16).
The actual usable RAM starts after both these
sections (address 006016). (Note that the I/O
register space may be larger on some more
extensive devices, in which case memory mapped I/
O registers will occupy a portion of the SRAM.)
Even though there are separate addressing
schemes and optimized opcodes for register file
and I/O register access, all can still be addressed
and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM.
This is most often used for long-term parameter
storage to be retrieved even after cycling the power
of the device. [edit] Program Execution Atmel's
AVRs have a single level pipeline design. The next
machine instruction is fetched as the current one is
executing. Most instructions take just one or two
clock cycles, making AVRs relatively fast among the
eight-bit microcontrollers. The AVR family of
processors were designed for the efficient
execution of compiled C code. The AVR instruction
set is more orthogonal than most eight-bit
microcontrollers, however, it is not completely
regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each
other. Register locations R0 to R15 have different
addressing capabilities than register locations R16
to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects
flags, while SER does not, even though they are
complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead
CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic
sugar for LDI R,$FF. Math operations such as EOR
modify flags while moves/loads/stores/branches
such as LDI do not.) [edit] Speed The AVR line can
normally support clock speeds from 0-16MHz, with
some devices reaching 20MHz. Lower powered
operation usually requires a reduced clock speed.
All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry.
Because many operations on the AVR are single
cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due
to the free and inexpensive development tools
available, including reasonably priced development
boards and free development software. The AVRs
are marketed under various names that share the
same basic core but with different peripheral and
memory combinations. Some models (notably, the
ATmega range) have additional instructions to make
arithmetic faster. Compatibility amongst chips is
fairly good. See external links for sites relating to
AVR development. [edit] Features Current AVRs
offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-
directional I/O Ports with Internal, Configurable Pull-
up Resistors Multiple Internal Oscillators Internal,
Self-Programmable Instruction Flash Memory up to
256K In-System Programmable using ICSP, JTAG,
or High Voltage methods Optional Boot Code
Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up
to 8K 8-Bit and 16-Bit Timers PWM Channels & dead
time generator Lighting (PWM Specific) Controller
models Dedicated I²C Compatible Two-Wire
Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,
RS-485, and more) Serial Peripheral Interface (SPI)
CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with
embedded AVR. Also freely available low-speed
(HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or
Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D
Converters, with multiplex of up to 16 channels
Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple
Power-Saving Sleep Modes picoPower Devices
Atmel AVR assembler programming language Atmel
AVR machine programming language Atmel AVR
From Wikipedia, the free encyclopedia (Redirected
from Avr) Jump to: navigation, search The AVRs are
a family of RISC microcontrollers from Atmel. Their
internal architecture was conceived by two
students: Alf-Egil Bogen and Vegard Wollan, at the
Norwegian Institute of Technology (NTH] and further
developed at Atmel Norway, a subsidiary founded
by the two architects. Atmel recently released the
Atmel AVR32 line of microcontrollers. These are 32-
bit RISC devices featuring SIMD and DSP
instructions, along with many additional features for
audio and video processing, intended to compete
with ARM based processors. Note that the use of
"AVR" in this article refers to the 8-bit RISC line of
Atmel AVR Microcontrollers. The acronym AVR has
been reported to stand for Advanced Virtual RISC.
It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when
questioned about it. Contents [hide] 1 Device
Overview 1.1 Program Memory 1.2 Data Memory and
Registers 1.3 EEPROM 1.4 Program Execution 1.5
Speed 2 Development 3 Features 4 Footnotes 5 See
also 6 External Links 6.1 Atmel Official Links 6.2
AVR Forums & Discussion Groups 6.3 Machine
Language Development 6.4 C Language
Development 6.5 BASIC & Other AVR Languages 6.6
AVR Butterfly Specific 6.7 Other AVR Links [edit]
Device Overview The AVR is a Harvard architecture
machine with programs and data stored and
addressed separately. Flash, EEPROM, and SRAM
are all integrated onto a single die, removing the
need for external memory (though still available on
some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either
16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the
device itself. For instance, the ATmega64x line has
64Kbytes of Flash. Almost all AVR devices are self-
programmable. [edit] Data Memory and Registers
The data address space consists of the register file,
I/O registers, and SRAM. The AVRs have thirty-two
single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the
first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16).
The actual usable RAM starts after both these
sections (address 006016). (Note that the I/O
register space may be larger on some more
extensive devices, in which case memory mapped I/
O registers will occupy a portion of the SRAM.)
Even though there are separate addressing
schemes and optimized opcodes for register file
and I/O register access, all can still be addressed
and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM.
This is most often used for long-term parameter
storage to be retrieved even after cycling the power
of the device. [edit] Program Execution Atmel's
AVRs have a single level pipeline design. The next
machine instruction is fetched as the current one is
executing. Most instructions take just one or two
clock cycles, making AVRs relatively fast among the
eight-bit microcontrollers. The AVR family of
processors were designed for the efficient
execution of compiled C code. The AVR instruction
set is more orthogonal than most eight-bit
microcontrollers, however, it is not completely
regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each
other. Register locations R0 to R15 have different
addressing capabilities than register locations R16
to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects
flags, while SER does not, even though they are
complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead
CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic
sugar for LDI R,$FF. Math operations such as EOR
modify flags while moves/loads/stores/branches
such as LDI do not.) [edit] Speed The AVR line can
normally support clock speeds from 0-16MHz, with
some devices reaching 20MHz. Lower powered
operation usually requires a reduced clock speed.
All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry.
Because many operations on the AVR are single
cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due
to the free and inexpensive development tools
available, including reasonably priced development
boards and free development software. The AVRs
are marketed under various names that share the
same basic core but with different peripheral and
memory combinations. Some models (notably, the
ATmega range) have additional instructions to make
arithmetic faster. Compatibility amongst chips is
fairly good. See external links for sites relating to
AVR development. [edit] Features Current AVRs
offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-
directional I/O Ports with Internal, Configurable Pull-
up Resistors Multiple Internal Oscillators Internal,
Self-Programmable Instruction Flash Memory up to
256K In-System Programmable using ICSP, JTAG,
or High Voltage methods Optional Boot Code
Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up
to 8K 8-Bit and 16-Bit Timers PWM Channels & dead
time generator Lighting (PWM Specific) Controller
models Dedicated I²C Compatible Two-Wire
Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,
RS-485, and more) Serial Peripheral Interface (SPI)
CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with
embedded AVR. Also freely available low-speed
(HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or
Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D
Converters, with multiplex of up to 16 channels
Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple
Power-Saving Sleep Modes picoPower Devices
Atmel AVR assembler programming language Atmel
AVR machine programming language
http://avr-asm.tripod.com/div3216.html (1 of 2)1/20/2009 8:40:41 PM
AVR MATH YX
tst R24
brne PREP_MD01 ;First number is floating point format
add R24,R16
rjmp PREP_MD02
PREP_MD01:
or R23,R17 ;restore msb bit
PREP_MD02:
tst R6
brne PREP_MD03 ;Second number is floating point format
add R6,R16
rjmp PREP_MD04
PREP_MD03:
or R5,R17 ;restore msb bit
PREP_MD04:
sub R24,R17
sub R6,R17 ;shift zero point by 0x80 (back
to 2's complement)
ret
; ------------------------------
; THE 'MULTIPLICATION' OPERATION
; ------------------------------
; (offset: $04 'multiply')
;
; m1: R6, R5:R2
; m2: R24, R23:R20
; -------------------
; Res: R6, R5:R2
;
; cycles + (RET) = Cycles
;
multiply:
rcall PREP_Mul_Div
mov R0,R2
or R0,R3
or R0,R4
or R0,R5
breq Res_Zero
mov R0,R20
or R0,R21
or R0,R22
or R0,R23
breq Res_Zero
rcall mult32
clr R7
rcall Normalize
sub R6,R16 ;shift exponent by
normalized value
brcs NumberTooBig
add R6,R24 ;2^x *2^y = 2^(x+y)
brvs NumberTooBig
ldi R16,0x80
sub R6,R16 ;set offset by 0x80
rcall Round
brcs NumberTooBig
ldi R17,0xFF
bld R17,7 ;get result sign bit
and R5,R17 ;set result sign bit
clc
ret
NumberTooBig:
sec
ret
Res_Zero:
clr R2
clr R3
movw R4,R2
clr R6
clc
ret
;***************************************************
;* Mutiply 32x32 -> 64 bit
;*
;* R23:R20 x R5:R2 -> R15:R8
;*
;* 86 cycles + 4 (RET) = 90 Cycles
;*
mult32:
clr R16
mul R20,R2
movw R8,R0
clr R10
clr R11
movw R12,R10
movw R14,R10
mul R21,R2
add R9,R0
adc R10,R1
mul R22,R2
add R10,R0
adc R11,R1
mul R23,R2
add R11,R0
adc R12,R1
mul R20,R3
add R9,R0
adc R10,R1
adc R11,R16
adc R12,R16
adc R13,R16
mul R21,R3
add R10,R0
adc R11,R1
adc R12,R16
adc R13,R16
mul R22,R3
add R11,R0
adc R12,R1
adc R13,R16
mul R23,R3
add R12,R0
adc R13,R1
mul R20,R4
add R10,R0
adc R11,R1
adc R12,R16
adc R13,R16
adc R14,R16
mul R21,R4
add R11,R0
adc R12,R1
adc R13,R16
adc R14,R16
mul R22,R4
add R12,R0
adc R13,R1
adc R14,R16
mul R23,R4
add R13,R0
adc R14,R1
mul R20,R5
add R11,R0
adc R12,R1
adc R13,R16
adc R14,R16
adc R15,R16
mul R21,R5
add R12,R0
adc R13,R1
adc R14,R16
adc R15,R16
mul R22,R5
add R13,R0
adc R14,R1
adc R15,R16
mul R23,R5
add R14,R0
adc R15,R1
ret
;**********************************************************
; R15:R8:R7 -> R15:R12
; R16 - 64-exponent
Normalize:
ldi R17,64 ;max 64 bitet kell vegigrotalni
Norm0: tst R15
brne Norm1
mov R15,R14
mov R14,R13
mov R13,R12
mov R12,R11
mov R11,R10
mov R10,R9
mov R9,R8
mov R8,R7
clr R7
subi R17,8
cpi R17,8
brne Norm0
Norm1:
;legnagyobb
helyiertek felrotalasa bit7-ig
sbrc R15,7
rjmp Norm2
lsl R7
rol R8
rol R9
rol R10
rol R11
rol R12
rol R13
rol R14
rol R15
dec R17
brne Norm1
Norm2:
ldi R16,64
sub R16,R17
;R16-ban az
exponens
ret
; -------------------------------
; THE 'PREPARE TO ADD' SUBROUTINE
; -------------------------------
; This routine is called twice by addition to prepare the two numbers.
; The sign bit is tested before being set to the implied state.
; Negative numbers are twos complemented.
;
; m1: R6, R5:R2 -> R6, R7:R5:R2
; m2: R24, R23:R20 -> R24, R25:R23:R20
; R25,R7 -> sign
;
PREP_ADD:
clr R25
clr R7
ldi R16,0x80
tst R24
brne Prep_Add1
mov R24,R16
rjmp M1Pos
Prep_Add1:
bst R23,7 ;test the sign bit
or R23,R16 ;set it to implied state
brtc M1Pos ;jump if positive number
NEG_M1:
clr R8
clr R9
movw R10,R8
movw R12,R8 ;clear result regs
tst R6
brne Prep_Add2
mov R6,R16
Prep_Add2:
bst R5,7 ;test the sign bit
or R5,R16 ;set it to implied state
brtc M2Pos ;jump if positive number
NEG_M2:
clr R8
clr R9
movw R10,R8
movw R12,R8 ;clear result regs
; -------------------------
; THE 'SHIFT FP Right' SUBROUTINE
; -------------------------
; In: mantissa R7:R5:R2
; Exponent : R6
; Shift right by R16
;
; Out: R17,R15,R14,R13,R12,R11,R10,R9,R8,R7
; s s s s s m m m m g
SHIFT_FP:
movw R12,R2
movw R14,R4
mov R17,R7
clr R7
clr R8
clr R9
movw R10,R8
tst R16
brne Shift_fp1
ret ;diff
== 0 no rota
Shift_fp1:
cpi R16,0x21 ;diff>33 bit
brcc ADDEND_0 ;we add 0 to 1st param
EIGHT_SHIFT:
cpi R16,8
brcs ONE_SHIFT
mov R7,R8
mov R8,R9
mov R9,R10
mov R10,R11
mov R11,R12
mov R12,R13
mov R13,R14
mov R14,R15
mov R15,R17
bst R17,7 ;negative
number?
clr R17
brtc SHIFT_FP2
ser R17
SHIFT_FP2: subi R16,8
rjmp EIGHT_SHIFT
; ---------------------------
; THE 'SUBTRACTION' OPERATION
; ---------------------------
; (offset: $03 'subtract')
subtract:
tst R24
brne Sub_NoZero
mov R0,R20
or R0,R21
or R0,R22
or R0,R23
brne addition
ret ;x - 0 = x
Sub_NoZero:
ori R23,0x80 ;make to negative
; ------------------------
; THE 'ADDITION' OPERATION
; ------------------------
; (offset: $0F 'addition')
;
; m1: R6, R5:R2
; m2: R24, R23:R20
; -------------------
; Res: R6, R5:R2
;
; cycles + (RET) = Cycles
;
addition:
rcall PREP_ADD
cp R24,R6 ;exp.
M1 < M2?
brcc SHIFT_LEN ;to SHIFT_LEN
movw R8,R4
movw R4,R22
movw R22,R8
movw R8,R6
movw R6,R24
movw R24,R8
SHIFT_LEN:
mov R16,R24
sub R16,
R6 ;length of shift
mov R6,R24
rcall SHIFT_FP
; R17,R15,R14,R13,R12,R11,R10,R9,R8,
R7
; s m m m m m m m m g
; + R25,R23,R22,R21,R20 0 0 0 0
0
;---------------------------------------
; R17,R15,R14,R13,R12,R11,R10,R9,R8,
R7
add R12,R20
adc R13,R21
adc R14,R22
adc R15,R23
adc R17,R25
brlt NoAdd_Overf1
inc R6
brne Add_Rota
rjmp Add_Rep_6
Add_Rota:
ldi R16,1
rcall ONE_SHIFT
NoAdd_Overf1:
mov R20,R17 ;store sign
bst R17,7 ;sign =
positive?
brtc Add_Pos
clr R0 ;negate
clr R1
movw R2,R0
sub R0,R7
mov R7,R0
movw R0,R2
sbc R0,R8
sbc R1,R9
movw R8,R0
movw R0,R2
sbc R0,R10
sbc R1,R11
movw R10,R0
movw R0,R2
sbc R0,R12
sbc R1,R13
movw R12,R0
movw R0,R2
sbc R0,R14
sbc R1,R15
movw R14,R0
mov R0,R2
sbc R0,R17
mov R17,R0
Add_Pos:
tst R17
breq Add_Norm
inc R6
brne Add_Rota1
rjmp Add_Rep_6
Add_Rota1:
ldi R16,1
rcall ONE_SHIFT
rjmp Add_Pos
Add_Norm:
rcall Normalize
bst R15,7
brts Add_Norm1 ;ha 7. =0 ,akkor nincs mit tenni
rjmp Res_Zero
Add_Norm1:
sub R6,R16
breq Add_Rep_6
brcs Add_Rep_6
rcall Round
brcs Add_Rep_6
bst R20,7
brts Add_NegResult
ldi R16,0x7F
and R5,R16 ;make pos sign
Add_NegResult:
clc
ret
Add_Rep_6:
sec ;
overflow error
ret
Round:
movw R4,R14
movw R2,R12
mov R0,R2
or R0,R3
or R0,R4
or R0,R5
brne Round1
clr R6
Round1:
clc
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
Atmel AVR From Wikipedia, the free encyclopedia (Redirected from Avr)
Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language Atmel AVR From Wikipedia,
the free encyclopedia (Redirected from Avr) Jump to: navigation, search
The AVRs are a family of RISC microcontrollers from Atmel. Their internal
architecture was conceived by two students: Alf-Egil Bogen and Vegard
Wollan, at the Norwegian Institute of Technology (NTH] and further
developed at Atmel Norway, a subsidiary founded by the two architects.
Atmel recently released the Atmel AVR32 line of microcontrollers. These
are 32-bit RISC devices featuring SIMD and DSP instructions, along with
many additional features for audio and video processing, intended to
compete with ARM based processors. Note that the use of "AVR" in this
article refers to the 8-bit RISC line of Atmel AVR Microcontrollers. The
acronym AVR has been reported to stand for Advanced Virtual RISC. It's
also rumoured to stand for the company's founders: Alf and Vegard, who
are evasive when questioned about it. Contents [hide] 1 Device Overview
1.1 Program Memory 1.2 Data Memory and Registers 1.3 EEPROM 1.4
Program Execution 1.5 Speed 2 Development 3 Features 4 Footnotes 5 See
also 6 External Links 6.1 Atmel Official Links 6.2 AVR Forums & Discussion
Groups 6.3 Machine Language Development 6.4 C Language Development
6.5 BASIC & Other AVR Languages 6.6 AVR Butterfly Specific 6.7 Other
AVR Links [edit] Device Overview The AVR is a Harvard architecture
machine with programs and data stored and addressed separately. Flash,
EEPROM, and SRAM are all integrated onto a single die, removing the need
for external memory (though still available on some devices). [edit]
Program Memory Program instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either 16 or 32 bits in length.
The Flash memory is addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the device itself. For
instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
http://avr-asm.tripod.com/float128.html (1 of 2)1/20/2009 8:41:21 PM
AVR MATH YX
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two
memory spaces (000016-001F16) followed by the 64 I/O registers (002016-
005F16). The actual usable RAM starts after both these sections (address
006016). (Note that the I/O register space may be larger on some more
extensive devices, in which case memory mapped I/O registers will occupy
a portion of the SRAM.) Even though there are separate addressing
schemes and optimized opcodes for register file and I/O register access, all
can still be addressed and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM. This is most often used
for long-term parameter storage to be retrieved even after cycling the
power of the device. [edit] Program Execution Atmel's AVRs have a single
level pipeline design. The next machine instruction is fetched as the
current one is executing. Most instructions take just one or two clock
cycles, making AVRs relatively fast among the eight-bit microcontrollers.
The AVR family of processors were designed for the efficient execution of
compiled C code. The AVR instruction set is more orthogonal than most
eight-bit microcontrollers, however, it is not completely regular: Pointer
registers X, Y, and Z have addressing capabilities that are different from
each other. Register locations R0 to R15 have different addressing
capabilities than register locations R16 to R31. I/O ports 0 to 31 have
different addressing capabilities than I/O ports 32 to 63. CLR affects flags,
while SER does not, even though they are complementary instructions.
CLR set all bits to zero and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead CLR is syntactic
sugar for [produces the same machine code as] EOR R,R while SER is
syntactic sugar for LDI R,$FF. Math operations such as EOR modify flags
while moves/loads/stores/branches such as LDI do not.) [edit] Speed The
AVR line can normally support clock speeds from 0-16MHz, with some
devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations
on the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due to the free and
inexpensive development tools available, including reasonably priced
development boards and free development software. The AVRs are
marketed under various names that share the same basic core but with
different peripheral and memory combinations. Some models (notably, the
ATmega range) have additional instructions to make arithmetic faster.
Compatibility amongst chips is fairly good. See external links for sites
relating to AVR development. [edit] Features Current AVRs offer a wide
range of features: RISC Core Running Many Single Cycle Instructions
Multifunction, Bi-directional I/O Ports with Internal, Configurable Pull-up
Resistors Multiple Internal Oscillators Internal, Self-Programmable
Instruction Flash Memory up to 256K In-System Programmable using ICSP,
JTAG, or High Voltage methods Optional Boot Code Section with
Independent Lock Bits for Protection Internal Data EEPROM up to 4KB
Internal SRAM up to 8K 8-Bit and 16-Bit Timers PWM Channels & dead time
generator Lighting (PWM Specific) Controller models Dedicated I²C
Compatible Two-Wire Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,RS-485, and more) Serial
Peripheral Interface (SPI) CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with embedded AVR. Also
freely available low-speed (HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or Three-Wire
Synchronous Data Transfer Analog Comparators LCD Controller Support
10-Bit A/D Converters, with multiplex of up to 16 channels Brownout
Detection Watchdog Timer (WDT) Low-voltage Devices Operating Down to
1.8v Multiple Power-Saving Sleep Modes picoPower Devices Atmel AVR
assembler programming language Atmel AVR machine programming
language Atmel AVR From Wikipedia, the free encyclopedia (Redirected
from Avr) Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language
bin2bcd8:
clr tBCDH ;clear result MSD
bBCD8_1:subi fbin,10 ;input = input - 10
brcs bBCD8_2 ;abort if carry set
inc tBCDH ;inc MSD
;---------------------------------------------------------------------------
; ;Replace the above line with this one
; ;for packed BCD output
; subi tBCDH,-$10 ;tBCDH = tBCDH + 10
;---------------------------------------------------------------------------
rjmp bBCD8_1 ;loop again
bBCD8_2:subi fbin,-10 ;compensate extra subtraction
;---------------------------------------------------------------------------
; ;Add this line for packed BCD output
; add fbin,tBCDH
;---------------------------------------------------------------------------
ret
;***************************************************************************
;*
;* "BCD2bin16" - BCD to 16-Bit Binary Conversion
;*
;* This subroutine converts a 5-digit packed BCD number represented by
;* 3 bytes (fBCD2:fBCD1:fBCD0) to a 16-bit number (tbinH:tbinL).
;* MSD of the 5-digit number must be placed in the lowermost nibble of
fBCD2.
;*
;* Let "abcde" denote the 5-digit number. The conversion is done by
;* computing the formula: 10(10(10(10a+b)+c)+d)+e.
;* The subroutine "mul10a"/"mul10b" does the multiply-and-add operation
;* which is repeated four times during the computation.
;*
;* Number of words :30
;* Number of cycles :108
;* Low registers used :4 (copyL,copyH,mp10L/tbinL,mp10H/tbinH)
;* High registers used :4 (fBCD0,fBCD1,fBCD2,adder)
;*
;***************************************************************************
;***** Code
;***** Code
BCD2bin16:
andi fBCD2,0x0f ;mask away upper nibble of fBCD2
clr mp10H
mov mp10L,fBCD2 ;mp10H:mp10L = a
mov adder,fBCD1
rcall mul10a ;mp10H:mp10L = 10a+b
mov adder,fBCD1
rcall mul10b ;mp10H:mp10L = 10(10a+b)+c
mov adder,fBCD0
rcall mul10a ;mp10H:mp10L = 10(10(10a+b)+c)+d
mov adder,fBCD0
rcall mul10b ;mp10H:mp10L = 10(10(10(10a+b)+c)+d)+e
ret
;***************************************************************************
;*
;* "BCD2bin8" - BCD to 8-bit binary conversion
;*
;* This subroutine converts a 2-digit BCD number (fBCDH:fBCDL) to an
;* 8-bit number (tbin).
;*
;* Number of words :4 + return
;* Number of cycles :3/48 (Min/Max) + return
;* Low registers used :None
;* High registers used :2 (tbin/fBCDL,fBCDH)
;*
;* Modifications to make the routine accept a packed BCD number is indicated
;* as comments in the code. If the modifications are used, fBCDH shall be
;* loaded with the BCD number to convert prior to calling the routine.
;*
;***************************************************************************
;***** Code
BCD2bin8:
;--------------------------------------------------------------------------
;| ;For packed BCD input, add these two lines
;| mov tbin,fBCDH ;copy input to result
;| andi tbin,$0f ;clear higher nibble of result
;--------------------------------------------------------------------------
;***************************************************************************
;*
;* "BCDadd" - 2-digit packed BCD addition
;*
;* This subroutine adds the two unsigned 2-digit BCD numbers
;* "BCD1" and "BCD2". The result is returned in "BCD1", and the overflow
;* carry in "BCD2".
;*
;* Number of words :19
;* Number of cycles :17/20 (Min/Max)
;* Low registers used :None
;* High registers used :3 (BCD1,BCD2,tmpadd)
;*
;***************************************************************************
;***** Code
BCDadd:
ldi tmpadd,6 ;value to be added later
add BCD1,BCD2 ;add the numbers binary
clr BCD2 ;clear BCD carry
brcc add_0 ;if carry not clear
ldi BCD2,1 ; set BCD carry
add_0: brhs add_1 ;if half carry not set
add BCD1,tmpadd ; add 6 to LSD
brhs add_2 ; if half carry not set (LSD <= 9)
subi BCD1,6 ; restore value
rjmp add_2 ;else
add_1: add BCD1,tmpadd ; add 6 to LSD
add_2: swap tmpadd
add BCD1,tmpadd ;add 6 to MSD
brcs add_4 ;if carry not set (MSD <= 9)
sbrs BCD2,0 ; if previous carry not set
subi BCD1,$60 ; restore value
add_3: ret ;else
add_4: ldi BCD2,1 ; set BCD carry
ret
;***************************************************************************
;*
;* "BCDsub" - 2-digit packed BCD subtraction
;*
;* This subroutine subtracts the two unsigned 2-digit BCD numbers
;* "BCDa" and "BCDb" (BCDa - BCDb). The result is returned in "BCDa", and
;* the underflow carry in "BCDb".
;*
;* Number of words :13
;* Number of cycles :12/17 (Min/Max)
;* Low registers used :None
;* High registers used :2 (BCDa,BCDb)
;*
;***************************************************************************
;***** Code
BCDsub:
sub BCDa,BCDb ;subtract the numbers binary
clr BCDb
brcc sub_0 ;if carry not clear
ldi BCDb,1 ; store carry in BCDB1, bit 0
sub_0: brhc sub_1 ;if half carry not clear
subi BCDa,$06 ; LSD = LSD - 6
sub_1: sbrs BCDb,0 ;if previous carry not set
ret ; return
subi BCDa,$60 ;subtract 6 from MSD
ldi BCDb,1 ;set underflow carry
brcc sub_2 ;if carry not clear
ldi BCDb,1 ; clear underflow carry
sub_2: ret
;
****************************************************************************
;*
;* Test Program
;*
;* This program calls all the subroutines as an example of usage and to
;* verify correct operation.
;*
;
****************************************************************************
;***** Code
RESET:
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,high(RAMEND)
out SPH,temp ;init Stack Pointer (remove for AT90Sxx0x)
ldi fbinL,low(54321)
ldi fbinH,high(54321)
rcall bin2BCD16 ;result: tBCD2:tBCD1:tBCD0 = $054321
ldi fbin,55
rcall bin2BCD8 ;result: tBCDH:tBCDL = 0505
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
Atmel AVR From Wikipedia, the free encyclopedia (Redirected from Avr)
Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language Atmel AVR From Wikipedia,
the free encyclopedia (Redirected from Avr) Jump to: navigation, search
The AVRs are a family of RISC microcontrollers from Atmel. Their internal
architecture was conceived by two students: Alf-Egil Bogen and Vegard
Wollan, at the Norwegian Institute of Technology (NTH] and further
developed at Atmel Norway, a subsidiary founded by the two architects.
Atmel recently released the Atmel AVR32 line of microcontrollers. These
are 32-bit RISC devices featuring SIMD and DSP instructions, along with
many additional features for audio and video processing, intended to
compete with ARM based processors. Note that the use of "AVR" in this
article refers to the 8-bit RISC line of Atmel AVR Microcontrollers. The
acronym AVR has been reported to stand for Advanced Virtual RISC. It's
also rumoured to stand for the company's founders: Alf and Vegard, who
are evasive when questioned about it. Contents [hide] 1 Device Overview
1.1 Program Memory 1.2 Data Memory and Registers 1.3 EEPROM 1.4
Program Execution 1.5 Speed 2 Development 3 Features 4 Footnotes 5 See
also 6 External Links 6.1 Atmel Official Links 6.2 AVR Forums & Discussion
Groups 6.3 Machine Language Development 6.4 C Language Development
6.5 BASIC & Other AVR Languages 6.6 AVR Butterfly Specific 6.7 Other
AVR Links [edit] Device Overview The AVR is a Harvard architecture
machine with programs and data stored and addressed separately. Flash,
EEPROM, and SRAM are all integrated onto a single die, removing the need
for external memory (though still available on some devices). [edit]
Program Memory Program instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either 16 or 32 bits in length.
The Flash memory is addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the device itself. For
instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two
memory spaces (000016-001F16) followed by the 64 I/O registers (002016-
005F16). The actual usable RAM starts after both these sections (address
006016). (Note that the I/O register space may be larger on some more
extensive devices, in which case memory mapped I/O registers will occupy
a portion of the SRAM.) Even though there are separate addressing
schemes and optimized opcodes for register file and I/O register access, all
can still be addressed and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM. This is most often used
for long-term parameter storage to be retrieved even after cycling the
power of the device. [edit] Program Execution Atmel's AVRs have a single
level pipeline design. The next machine instruction is fetched as the
current one is executing. Most instructions take just one or two clock
cycles, making AVRs relatively fast among the eight-bit microcontrollers.
The AVR family of processors were designed for the efficient execution of
compiled C code. The AVR instruction set is more orthogonal than most
eight-bit microcontrollers, however, it is not completely regular: Pointer
registers X, Y, and Z have addressing capabilities that are different from
each other. Register locations R0 to R15 have different addressing
capabilities than register locations R16 to R31. I/O ports 0 to 31 have
different addressing capabilities than I/O ports 32 to 63. CLR affects flags,
while SER does not, even though they are complementary instructions.
CLR set all bits to zero and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead CLR is syntactic
sugar for [produces the same machine code as] EOR R,R while SER is
syntactic sugar for LDI R,$FF. Math operations such as EOR modify flags
while moves/loads/stores/branches such as LDI do not.) [edit] Speed The
AVR line can normally support clock speeds from 0-16MHz, with some
devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations
on the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due to the free and
inexpensive development tools available, including reasonably priced
development boards and free development software. The AVRs are
marketed under various names that share the same basic core but with
different peripheral and memory combinations. Some models (notably, the
ATmega range) have additional instructions to make arithmetic faster.
Compatibility amongst chips is fairly good. See external links for sites
relating to AVR development. [edit] Features Current AVRs offer a wide
range of features: RISC Core Running Many Single Cycle Instructions
Multifunction, Bi-directional I/O Ports with Internal, Configurable Pull-up
Resistors Multiple Internal Oscillators Internal, Self-Programmable
Instruction Flash Memory up to 256K In-System Programmable using ICSP,
JTAG, or High Voltage methods Optional Boot Code Section with
Independent Lock Bits for Protection Internal Data EEPROM up to 4KB
Internal SRAM up to 8K 8-Bit and 16-Bit Timers PWM Channels & dead time
generator Lighting (PWM Specific) Controller models Dedicated I²C
Compatible Two-Wire Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,RS-485, and more) Serial
Peripheral Interface (SPI) CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with embedded AVR. Also
freely available low-speed (HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or Three-Wire
Synchronous Data Transfer Analog Comparators LCD Controller Support
10-Bit A/D Converters, with multiplex of up to 16 channels Brownout
Detection Watchdog Timer (WDT) Low-voltage Devices Operating Down to
1.8v Multiple Power-Saving Sleep Modes picoPower Devices Atmel AVR
assembler programming language Atmel AVR machine programming
language Atmel AVR From Wikipedia, the free encyclopedia (Redirected
from Avr) Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
http://avr-asm.tripod.com/avr204.html (1 of 2)1/20/2009 8:42:33 PM
16 BIT MATH (AVR 202)
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language
bin2bcd8:
clr tBCDH ;clear result MSD
bBCD8_1:subi fbin,10 ;input = input - 10
brcs bBCD8_2 ;abort if carry set
inc tBCDH ;inc MSD
;---------------------------------------------------------------------------
; ;Replace the above line with this one
; ;for packed BCD output
; subi tBCDH,-$10 ;tBCDH = tBCDH + 10
;---------------------------------------------------------------------------
rjmp bBCD8_1 ;loop again
bBCD8_2:subi fbin,-10 ;compensate extra subtraction
;---------------------------------------------------------------------------
; ;Add this line for packed BCD output
; add fbin,tBCDH
;---------------------------------------------------------------------------
ret
;***************************************************************************
;*
;* "BCD2bin16" - BCD to 16-Bit Binary Conversion
;*
;* This subroutine converts a 5-digit packed BCD number represented by
;* 3 bytes (fBCD2:fBCD1:fBCD0) to a 16-bit number (tbinH:tbinL).
;* MSD of the 5-digit number must be placed in the lowermost nibble of
fBCD2.
;*
;* Let "abcde" denote the 5-digit number. The conversion is done by
;* computing the formula: 10(10(10(10a+b)+c)+d)+e.
;* The subroutine "mul10a"/"mul10b" does the multiply-and-add operation
;* which is repeated four times during the computation.
;*
;* Number of words :30
;* Number of cycles :108
;* Low registers used :4 (copyL,copyH,mp10L/tbinL,mp10H/tbinH)
;* High registers used :4 (fBCD0,fBCD1,fBCD2,adder)
;*
;***************************************************************************
;***** Code
;***** Code
BCD2bin16:
andi fBCD2,0x0f ;mask away upper nibble of fBCD2
clr mp10H
mov mp10L,fBCD2 ;mp10H:mp10L = a
mov adder,fBCD1
rcall mul10a ;mp10H:mp10L = 10a+b
mov adder,fBCD1
rcall mul10b ;mp10H:mp10L = 10(10a+b)+c
mov adder,fBCD0
rcall mul10a ;mp10H:mp10L = 10(10(10a+b)+c)+d
mov adder,fBCD0
rcall mul10b ;mp10H:mp10L = 10(10(10(10a+b)+c)+d)+e
ret
;***************************************************************************
;*
;* "BCD2bin8" - BCD to 8-bit binary conversion
;*
;* This subroutine converts a 2-digit BCD number (fBCDH:fBCDL) to an
;* 8-bit number (tbin).
;*
;* Number of words :4 + return
;* Number of cycles :3/48 (Min/Max) + return
;* Low registers used :None
;* High registers used :2 (tbin/fBCDL,fBCDH)
;*
;* Modifications to make the routine accept a packed BCD number is indicated
;* as comments in the code. If the modifications are used, fBCDH shall be
;* loaded with the BCD number to convert prior to calling the routine.
;*
;***************************************************************************
;***** Code
BCD2bin8:
;--------------------------------------------------------------------------
;| ;For packed BCD input, add these two lines
;| mov tbin,fBCDH ;copy input to result
;| andi tbin,$0f ;clear higher nibble of result
;--------------------------------------------------------------------------
;***************************************************************************
;*
;* "BCDadd" - 2-digit packed BCD addition
;*
;* This subroutine adds the two unsigned 2-digit BCD numbers
;* "BCD1" and "BCD2". The result is returned in "BCD1", and the overflow
;* carry in "BCD2".
;*
;* Number of words :19
;* Number of cycles :17/20 (Min/Max)
;* Low registers used :None
;* High registers used :3 (BCD1,BCD2,tmpadd)
;*
;***************************************************************************
;***** Code
BCDadd:
ldi tmpadd,6 ;value to be added later
add BCD1,BCD2 ;add the numbers binary
clr BCD2 ;clear BCD carry
brcc add_0 ;if carry not clear
ldi BCD2,1 ; set BCD carry
add_0: brhs add_1 ;if half carry not set
add BCD1,tmpadd ; add 6 to LSD
brhs add_2 ; if half carry not set (LSD <= 9)
subi BCD1,6 ; restore value
rjmp add_2 ;else
add_1: add BCD1,tmpadd ; add 6 to LSD
add_2: swap tmpadd
add BCD1,tmpadd ;add 6 to MSD
brcs add_4 ;if carry not set (MSD <= 9)
sbrs BCD2,0 ; if previous carry not set
subi BCD1,$60 ; restore value
add_3: ret ;else
add_4: ldi BCD2,1 ; set BCD carry
ret
;***************************************************************************
;*
;* "BCDsub" - 2-digit packed BCD subtraction
;*
;* This subroutine subtracts the two unsigned 2-digit BCD numbers
;* "BCDa" and "BCDb" (BCDa - BCDb). The result is returned in "BCDa", and
;* the underflow carry in "BCDb".
;*
;* Number of words :13
;* Number of cycles :12/17 (Min/Max)
;* Low registers used :None
;* High registers used :2 (BCDa,BCDb)
;*
;***************************************************************************
;***** Code
BCDsub:
sub BCDa,BCDb ;subtract the numbers binary
clr BCDb
brcc sub_0 ;if carry not clear
ldi BCDb,1 ; store carry in BCDB1, bit 0
sub_0: brhc sub_1 ;if half carry not clear
subi BCDa,$06 ; LSD = LSD - 6
sub_1: sbrs BCDb,0 ;if previous carry not set
ret ; return
subi BCDa,$60 ;subtract 6 from MSD
ldi BCDb,1 ;set underflow carry
brcc sub_2 ;if carry not clear
ldi BCDb,1 ; clear underflow carry
sub_2: ret
;
****************************************************************************
;*
;* Test Program
;*
;* This program calls all the subroutines as an example of usage and to
;* verify correct operation.
;*
;
****************************************************************************
;***** Code
RESET:
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,high(RAMEND)
out SPH,temp ;init Stack Pointer (remove for AT90Sxx0x)
ldi fbinL,low(54321)
ldi fbinH,high(54321)
rcall bin2BCD16 ;result: tBCD2:tBCD1:tBCD0 = $054321
ldi fbin,55
rcall bin2BCD8 ;result: tBCDH:tBCDL = 0505
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
Atmel AVR From Wikipedia, the free encyclopedia (Redirected from Avr)
Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language Atmel AVR From Wikipedia,
the free encyclopedia (Redirected from Avr) Jump to: navigation, search
The AVRs are a family of RISC microcontrollers from Atmel. Their internal
architecture was conceived by two students: Alf-Egil Bogen and Vegard
Wollan, at the Norwegian Institute of Technology (NTH] and further
developed at Atmel Norway, a subsidiary founded by the two architects.
Atmel recently released the Atmel AVR32 line of microcontrollers. These
are 32-bit RISC devices featuring SIMD and DSP instructions, along with
many additional features for audio and video processing, intended to
compete with ARM based processors. Note that the use of "AVR" in this
article refers to the 8-bit RISC line of Atmel AVR Microcontrollers. The
acronym AVR has been reported to stand for Advanced Virtual RISC. It's
also rumoured to stand for the company's founders: Alf and Vegard, who
are evasive when questioned about it. Contents [hide] 1 Device Overview
1.1 Program Memory 1.2 Data Memory and Registers 1.3 EEPROM 1.4
Program Execution 1.5 Speed 2 Development 3 Features 4 Footnotes 5 See
also 6 External Links 6.1 Atmel Official Links 6.2 AVR Forums & Discussion
Groups 6.3 Machine Language Development 6.4 C Language Development
6.5 BASIC & Other AVR Languages 6.6 AVR Butterfly Specific 6.7 Other
AVR Links [edit] Device Overview The AVR is a Harvard architecture
machine with programs and data stored and addressed separately. Flash,
EEPROM, and SRAM are all integrated onto a single die, removing the need
for external memory (though still available on some devices). [edit]
Program Memory Program instructions are stored in semi-permanent Flash
memory. Each instruction for the AVR line is either 16 or 32 bits in length.
The Flash memory is addressed using 16 bit word sizes. The size of the
program memory is indicated in the naming of the device itself. For
instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two
memory spaces (000016-001F16) followed by the 64 I/O registers (002016-
005F16). The actual usable RAM starts after both these sections (address
006016). (Note that the I/O register space may be larger on some more
extensive devices, in which case memory mapped I/O registers will occupy
a portion of the SRAM.) Even though there are separate addressing
schemes and optimized opcodes for register file and I/O register access, all
can still be addressed and manipulated as if they were in SRAM. [edit]
EEPROM Almost all devices have on-die EEPROM. This is most often used
for long-term parameter storage to be retrieved even after cycling the
power of the device. [edit] Program Execution Atmel's AVRs have a single
level pipeline design. The next machine instruction is fetched as the
current one is executing. Most instructions take just one or two clock
cycles, making AVRs relatively fast among the eight-bit microcontrollers.
The AVR family of processors were designed for the efficient execution of
compiled C code. The AVR instruction set is more orthogonal than most
eight-bit microcontrollers, however, it is not completely regular: Pointer
registers X, Y, and Z have addressing capabilities that are different from
each other. Register locations R0 to R15 have different addressing
capabilities than register locations R16 to R31. I/O ports 0 to 31 have
different addressing capabilities than I/O ports 32 to 63. CLR affects flags,
while SER does not, even though they are complementary instructions.
CLR set all bits to zero and SER sets them to one. (Note though, that
neither CLR nor SER are native instructions. Instead CLR is syntactic
sugar for [produces the same machine code as] EOR R,R while SER is
syntactic sugar for LDI R,$FF. Math operations such as EOR modify flags
while moves/loads/stores/branches such as LDI do not.) [edit] Speed The
AVR line can normally support clock speeds from 0-16MHz, with some
devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations
on the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz.
[edit] Development AVRs have a large following due to the free and
inexpensive development tools available, including reasonably priced
development boards and free development software. The AVRs are
marketed under various names that share the same basic core but with
different peripheral and memory combinations. Some models (notably, the
ATmega range) have additional instructions to make arithmetic faster.
Compatibility amongst chips is fairly good. See external links for sites
relating to AVR development. [edit] Features Current AVRs offer a wide
range of features: RISC Core Running Many Single Cycle Instructions
Multifunction, Bi-directional I/O Ports with Internal, Configurable Pull-up
Resistors Multiple Internal Oscillators Internal, Self-Programmable
Instruction Flash Memory up to 256K In-System Programmable using ICSP,
JTAG, or High Voltage methods Optional Boot Code Section with
Independent Lock Bits for Protection Internal Data EEPROM up to 4KB
Internal SRAM up to 8K 8-Bit and 16-Bit Timers PWM Channels & dead time
generator Lighting (PWM Specific) Controller models Dedicated I²C
Compatible Two-Wire Interface (TWI) Synchronous/Asynchronous Serial
Peripherals (UART/USART) (As used with RS-232,RS-485, and more) Serial
Peripheral Interface (SPI) CAN Controller Support USB Controller Support
Proper High-speed hardware & Hub controller with embedded AVR. Also
freely available low-speed (HID) software emulation Ethernet Controller
Support Universal Serial Interface (USI) for Two or Three-Wire
Synchronous Data Transfer Analog Comparators LCD Controller Support
10-Bit A/D Converters, with multiplex of up to 16 channels Brownout
Detection Watchdog Timer (WDT) Low-voltage Devices Operating Down to
1.8v Multiple Power-Saving Sleep Modes picoPower Devices Atmel AVR
assembler programming language Atmel AVR machine programming
language Atmel AVR From Wikipedia, the free encyclopedia (Redirected
from Avr) Jump to: navigation, search The AVRs are a family of RISC
microcontrollers from Atmel. Their internal architecture was conceived by
two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian Institute
of Technology (NTH] and further developed at Atmel Norway, a subsidiary
founded by the two architects. Atmel recently released the Atmel AVR32
line of microcontrollers. These are 32-bit RISC devices featuring SIMD and
DSP instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that
the use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2
Development 3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel
Official Links 6.2 AVR Forums & Discussion Groups 6.3 Machine Language
Development 6.4 C Language Development 6.5 BASIC & Other AVR
Languages 6.6 AVR Butterfly Specific 6.7 Other AVR Links [edit] Device
Overview The AVR is a Harvard architecture machine with programs and
data stored and addressed separately. Flash, EEPROM, and SRAM are all
integrated onto a single die, removing the need for external memory
(though still available on some devices). [edit] Program Memory Program
instructions are stored in semi-permanent Flash memory. Each instruction
for the AVR line is either 16 or 32 bits in length. The Flash memory is
addressed using 16 bit word sizes. The size of the program memory is
indicated in the naming of the device itself. For instance, the ATmega64x
line has 64Kbytes of Flash. Almost all AVR devices are self-programmable.
[edit] Data Memory and Registers The data address space consists of the
register file, I/O registers, and SRAM. The AVRs have thirty-two single-byte
registers and are classified as 8-bit RISC devices. The working registers
are mapped in as the first thirty-two memory spaces (000016-001F16)
followed by the 64 I/O registers (002016-005F16). The actual usable RAM
starts after both these sections (address 006016). (Note that the I/O register
space may be larger on some more extensive devices, in which case
memory mapped I/O registers will occupy a portion of the SRAM.) Even
though there are separate addressing schemes and optimized opcodes for
register file and I/O register access, all can still be addressed and
manipulated as if they were in SRAM. [edit] EEPROM Almost all devices
have on-die EEPROM. This is most often used for long-term parameter
storage to be retrieved even after cycling the power of the device. [edit]
Program Execution Atmel's AVRs have a single level pipeline design. The
next machine instruction is fetched as the current one is executing. Most
instructions take just one or two clock cycles, making AVRs relatively fast
among the eight-bit microcontrollers. The AVR family of processors were
designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register
locations R0 to R15 have different addressing capabilities than register
locations R16 to R31. I/O ports 0 to 31 have different addressing
capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not,
even though they are complementary instructions. CLR set all bits to zero
and SER sets them to one. (Note though, that neither CLR nor SER are
native instructions. Instead CLR is syntactic sugar for [produces the same
machine code as] EOR R,R while SER is syntactic sugar for LDI R,$FF.
Math operations such as EOR modify flags while moves/loads/stores/
branches such as LDI do not.) [edit] Speed The AVR line can normally
support clock speeds from 0-16MHz, with some devices reaching 20MHz.
Lower powered operation usually requires a reduced clock speed. All AVRs
feature an on-chip oscillator, removing the need for external clocks or
resonator circuitry. Because many operations on the AVR are single cycle,
the AVR can achieve up to 1MIPS per MHz. [edit] Development AVRs have a
large following due to the free and inexpensive development tools
available, including reasonably priced development boards and free
development software. The AVRs are marketed under various names that
http://avr-asm.tripod.com/id77.html (1 of 2)1/20/2009 8:43:13 PM
16 BIT MATH (AVR 202)
share the same basic core but with different peripheral and memory
combinations. Some models (notably, the ATmega range) have additional
instructions to make arithmetic faster. Compatibility amongst chips is fairly
good. See external links for sites relating to AVR development. [edit]
Features Current AVRs offer a wide range of features: RISC Core Running
Many Single Cycle Instructions Multifunction, Bi-directional I/O Ports with
Internal, Configurable Pull-up Resistors Multiple Internal Oscillators
Internal, Self-Programmable Instruction Flash Memory up to 256K In-
System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog
Comparators LCD Controller Support 10-Bit A/D Converters, with multiplex
of up to 16 channels Brownout Detection Watchdog Timer (WDT) Low-
voltage Devices Operating Down to 1.8v Multiple Power-Saving Sleep
Modes picoPower Devices Atmel AVR assembler programming language
Atmel AVR machine programming language
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
Atmel AVR From Wikipedia, the free encyclopedia (Redirected from Avr)
Jump to: navigation, search The AVRs are a family of RISC microcontrollers
from Atmel. Their internal architecture was conceived by two students: Alf-
Egil Bogen and Vegard Wollan, at the Norwegian Institute of Technology
(NTH] and further developed at Atmel Norway, a subsidiary founded by the
two architects. Atmel recently released the Atmel AVR32 line of
microcontrollers. These are 32-bit RISC devices featuring SIMD and DSP
instructions, along with many additional features for audio and video
processing, intended to compete with ARM based processors. Note that the
use of "AVR" in this article refers to the 8-bit RISC line of Atmel AVR
Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2 Development
3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel Official Links
6.2 AVR Forums & Discussion Groups 6.3 Machine Language Development
6.4 C Language Development 6.5 BASIC & Other AVR Languages 6.6 AVR
Butterfly Specific 6.7 Other AVR Links [edit] Device Overview The AVR is a
Harvard architecture machine with programs and data stored and addressed
separately. Flash, EEPROM, and SRAM are all integrated onto a single die,
removing the need for external memory (though still available on some
devices). [edit] Program Memory Program instructions are stored in semi-
permanent Flash memory. Each instruction for the AVR line is either 16 or 32
bits in length. The Flash memory is addressed using 16 bit word sizes. The
size of the program memory is indicated in the naming of the device itself.
For instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two memory
spaces (000016-001F16) followed by the 64 I/O registers (002016-005F16).
The actual usable RAM starts after both these sections (address 006016).
(Note that the I/O register space may be larger on some more extensive
devices, in which case memory mapped I/O registers will occupy a portion of
the SRAM.) Even though there are separate addressing schemes and
optimized opcodes for register file and I/O register access, all can still be
addressed and manipulated as if they were in SRAM. [edit] EEPROM Almost
all devices have on-die EEPROM. This is most often used for long-term
parameter storage to be retrieved even after cycling the power of the device.
[edit] Program Execution Atmel's AVRs have a single level pipeline design.
The next machine instruction is fetched as the current one is executing.
Most instructions take just one or two clock cycles, making AVRs relatively
fast among the eight-bit microcontrollers. The AVR family of processors
were designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register locations
R0 to R15 have different addressing capabilities than register locations R16
to R31. I/O ports 0 to 31 have different addressing capabilities than I/O ports
32 to 63. CLR affects flags, while SER does not, even though they are
complementary instructions. CLR set all bits to zero and SER sets them to
one. (Note though, that neither CLR nor SER are native instructions. Instead
CLR is syntactic sugar for [produces the same machine code as] EOR R,R
while SER is syntactic sugar for LDI R,$FF. Math operations such as EOR
modify flags while moves/loads/stores/branches such as LDI do not.) [edit]
Speed The AVR line can normally support clock speeds from 0-16MHz, with
some devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations on
the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz. [edit]
Development AVRs have a large following due to the free and inexpensive
development tools available, including reasonably priced development
boards and free development software. The AVRs are marketed under
various names that share the same basic core but with different peripheral
and memory combinations. Some models (notably, the ATmega range) have
additional instructions to make arithmetic faster. Compatibility amongst
chips is fairly good. See external links for sites relating to AVR development.
[edit] Features Current AVRs offer a wide range of features: RISC Core
Running Many Single Cycle Instructions Multifunction, Bi-directional I/O
Ports with Internal, Configurable Pull-up Resistors Multiple Internal
Oscillators Internal, Self-Programmable Instruction Flash Memory up to
256K In-System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog Comparators
LCD Controller Support 10-Bit A/D Converters, with multiplex of up to 16
channels Brownout Detection Watchdog Timer (WDT) Low-voltage Devices
Operating Down to 1.8v Multiple Power-Saving Sleep Modes picoPower
Devices Atmel AVR assembler programming language Atmel AVR machine
programming language Atmel AVR From Wikipedia, the free encyclopedia
(Redirected from Avr) Jump to: navigation, search The AVRs are a family of
RISC microcontrollers from Atmel. Their internal architecture was conceived
by two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian
Institute of Technology (NTH] and further developed at Atmel Norway, a
subsidiary founded by the two architects. Atmel recently released the Atmel
AVR32 line of microcontrollers. These are 32-bit RISC devices featuring
SIMD and DSP instructions, along with many additional features for audio
and video processing, intended to compete with ARM based processors.
Note that the use of "AVR" in this article refers to the 8-bit RISC line of Atmel
AVR Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2 Development
3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel Official Links
6.2 AVR Forums & Discussion Groups 6.3 Machine Language Development
6.4 C Language Development 6.5 BASIC & Other AVR Languages 6.6 AVR
Butterfly Specific 6.7 Other AVR Links [edit] Device Overview The AVR is a
Harvard architecture machine with programs and data stored and addressed
separately. Flash, EEPROM, and SRAM are all integrated onto a single die,
removing the need for external memory (though still available on some
devices). [edit] Program Memory Program instructions are stored in semi-
permanent Flash memory. Each instruction for the AVR line is either 16 or 32
bits in length. The Flash memory is addressed using 16 bit word sizes. The
size of the program memory is indicated in the naming of the device itself.
For instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two memory
spaces (000016-001F16) followed by the 64 I/O registers (002016-005F16).
The actual usable RAM starts after both these sections (address 006016).
(Note that the I/O register space may be larger on some more extensive
devices, in which case memory mapped I/O registers will occupy a portion of
the SRAM.) Even though there are separate addressing schemes and
optimized opcodes for register file and I/O register access, all can still be
addressed and manipulated as if they were in SRAM. [edit] EEPROM Almost
all devices have on-die EEPROM. This is most often used for long-term
parameter storage to be retrieved even after cycling the power of the device.
[edit] Program Execution Atmel's AVRs have a single level pipeline design.
The next machine instruction is fetched as the current one is executing.
Most instructions take just one or two clock cycles, making AVRs relatively
fast among the eight-bit microcontrollers. The AVR family of processors
were designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register locations
R0 to R15 have different addressing capabilities than register locations R16
to R31. I/O ports 0 to 31 have different addressing capabilities than I/O ports
32 to 63. CLR affects flags, while SER does not, even though they are
complementary instructions. CLR set all bits to zero and SER sets them to
one. (Note though, that neither CLR nor SER are native instructions. Instead
CLR is syntactic sugar for [produces the same machine code as] EOR R,R
while SER is syntactic sugar for LDI R,$FF. Math operations such as EOR
modify flags while moves/loads/stores/branches such as LDI do not.) [edit]
Speed The AVR line can normally support clock speeds from 0-16MHz, with
some devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations on
the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz. [edit]
Development AVRs have a large following due to the free and inexpensive
development tools available, including reasonably priced development
boards and free development software. The AVRs are marketed under
various names that share the same basic core but with different peripheral
and memory combinations. Some models (notably, the ATmega range) have
additional instructions to make arithmetic faster. Compatibility amongst
chips is fairly good. See external links for sites relating to AVR development.
[edit] Features Current AVRs offer a wide range of features: RISC Core
Running Many Single Cycle Instructions Multifunction, Bi-directional I/O
Ports with Internal, Configurable Pull-up Resistors Multiple Internal
Oscillators Internal, Self-Programmable Instruction Flash Memory up to
256K In-System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog Comparators
LCD Controller Support 10-Bit A/D Converters, with multiplex of up to 16
channels Brownout Detection Watchdog Timer (WDT) Low-voltage Devices
Operating Down to 1.8v Multiple Power-Saving Sleep Modes picoPower
Devices Atmel AVR assembler programming language Atmel AVR machine
programming language Atmel AVR From Wikipedia, the free encyclopedia
(Redirected from Avr) Jump to: navigation, search The AVRs are a family of
RISC microcontrollers from Atmel. Their internal architecture was conceived
by two students: Alf-Egil Bogen and Vegard Wollan, at the Norwegian
Institute of Technology (NTH] and further developed at Atmel Norway, a
subsidiary founded by the two architects. Atmel recently released the Atmel
AVR32 line of microcontrollers. These are 32-bit RISC devices featuring
SIMD and DSP instructions, along with many additional features for audio
and video processing, intended to compete with ARM based processors.
Note that the use of "AVR" in this article refers to the 8-bit RISC line of Atmel
AVR Microcontrollers. The acronym AVR has been reported to stand for
Advanced Virtual RISC. It's also rumoured to stand for the company's
founders: Alf and Vegard, who are evasive when questioned about it.
Contents [hide] 1 Device Overview 1.1 Program Memory 1.2 Data Memory
and Registers 1.3 EEPROM 1.4 Program Execution 1.5 Speed 2 Development
3 Features 4 Footnotes 5 See also 6 External Links 6.1 Atmel Official Links
6.2 AVR Forums & Discussion Groups 6.3 Machine Language Development
6.4 C Language Development 6.5 BASIC & Other AVR Languages 6.6 AVR
Butterfly Specific 6.7 Other AVR Links [edit] Device Overview The AVR is a
Harvard architecture machine with programs and data stored and addressed
separately. Flash, EEPROM, and SRAM are all integrated onto a single die,
removing the need for external memory (though still available on some
devices). [edit] Program Memory Program instructions are stored in semi-
permanent Flash memory. Each instruction for the AVR line is either 16 or 32
bits in length. The Flash memory is addressed using 16 bit word sizes. The
size of the program memory is indicated in the naming of the device itself.
For instance, the ATmega64x line has 64Kbytes of Flash. Almost all AVR
devices are self-programmable. [edit] Data Memory and Registers The data
address space consists of the register file, I/O registers, and SRAM. The
AVRs have thirty-two single-byte registers and are classified as 8-bit RISC
devices. The working registers are mapped in as the first thirty-two memory
spaces (000016-001F16) followed by the 64 I/O registers (002016-005F16).
The actual usable RAM starts after both these sections (address 006016).
(Note that the I/O register space may be larger on some more extensive
devices, in which case memory mapped I/O registers will occupy a portion of
the SRAM.) Even though there are separate addressing schemes and
optimized opcodes for register file and I/O register access, all can still be
addressed and manipulated as if they were in SRAM. [edit] EEPROM Almost
all devices have on-die EEPROM. This is most often used for long-term
parameter storage to be retrieved even after cycling the power of the device.
[edit] Program Execution Atmel's AVRs have a single level pipeline design.
The next machine instruction is fetched as the current one is executing.
Most instructions take just one or two clock cycles, making AVRs relatively
fast among the eight-bit microcontrollers. The AVR family of processors
were designed for the efficient execution of compiled C code. The AVR
instruction set is more orthogonal than most eight-bit microcontrollers,
however, it is not completely regular: Pointer registers X, Y, and Z have
addressing capabilities that are different from each other. Register locations
R0 to R15 have different addressing capabilities than register locations R16
to R31. I/O ports 0 to 31 have different addressing capabilities than I/O ports
32 to 63. CLR affects flags, while SER does not, even though they are
complementary instructions. CLR set all bits to zero and SER sets them to
one. (Note though, that neither CLR nor SER are native instructions. Instead
CLR is syntactic sugar for [produces the same machine code as] EOR R,R
while SER is syntactic sugar for LDI R,$FF. Math operations such as EOR
modify flags while moves/loads/stores/branches such as LDI do not.) [edit]
Speed The AVR line can normally support clock speeds from 0-16MHz, with
some devices reaching 20MHz. Lower powered operation usually requires a
reduced clock speed. All AVRs feature an on-chip oscillator, removing the
need for external clocks or resonator circuitry. Because many operations on
the AVR are single cycle, the AVR can achieve up to 1MIPS per MHz. [edit]
Development AVRs have a large following due to the free and inexpensive
development tools available, including reasonably priced development
boards and free development software. The AVRs are marketed under
various names that share the same basic core but with different peripheral
and memory combinations. Some models (notably, the ATmega range) have
additional instructions to make arithmetic faster. Compatibility amongst
chips is fairly good. See external links for sites relating to AVR development.
[edit] Features Current AVRs offer a wide range of features: RISC Core
Running Many Single Cycle Instructions Multifunction, Bi-directional I/O
Ports with Internal, Configurable Pull-up Resistors Multiple Internal
Oscillators Internal, Self-Programmable Instruction Flash Memory up to
256K In-System Programmable using ICSP, JTAG, or High Voltage methods
Optional Boot Code Section with Independent Lock Bits for Protection
Internal Data EEPROM up to 4KB Internal SRAM up to 8K 8-Bit and 16-Bit
Timers PWM Channels & dead time generator Lighting (PWM Specific)
Controller models Dedicated I²C Compatible Two-Wire Interface (TWI)
Synchronous/Asynchronous Serial Peripherals (UART/USART) (As used
with RS-232,RS-485, and more) Serial Peripheral Interface (SPI) CAN
Controller Support USB Controller Support Proper High-speed hardware &
Hub controller with embedded AVR. Also freely available low-speed (HID)
software emulation Ethernet Controller Support Universal Serial Interface
(USI) for Two or Three-Wire Synchronous Data Transfer Analog Comparators
LCD Controller Support 10-Bit A/D Converters, with multiplex of up to 16
channels Brownout Detection Watchdog Timer (WDT) Low-voltage Devices
Operating Down to 1.8v Multiple Power-Saving Sleep Modes picoPower
Devices Atmel AVR assembler programming language Atmel AVR machine
programming language
http://avr-asm.tripod.com/intascii.html (1 of 2)1/20/2009 8:44:37 PM
16 BIT MATH (AVR 202)
MATH 202
MATH 202 ;
**********************************************************************************************
DEC ASCII
;E. Seah
INT ASCII ;03/24/01
;HEX-TO-ASCII conversion subroutine
HX2ASC
;"high" registers : 4 (3 if "value" can be "low"
AVG8 222 register)
FFT7 ;"low" registers : 0 (1 if "value" can be "low" register)
;program words : 22+1 (including return)
COPY 102 ;
LPM 108 ;description : convert 0x00<="value"<=0xff to 3 digits of
ASCII in "hundreds","tens" and "ones"
EPROM 100 ;
SER EPROM _h2a: ldi hundreds,200 ;init hundreds for hundreds cp
loop
DFLASH AT45
ldi ones,2 ;init ones for hundreds cp loop
FLASH CARD
a100: cp value,hundreds
VFX SMIL
brlo sub100 ;if value=hundreds
VFX MEM sub value,hundreds ;remove 100s from value
SORT 220 subi ones,-0x30 ;?00<=x<=?99, 1st digit is '?'
mov hundreds,ones
CRC 236 ldi tens,90 ;init tens for tens cp loop
XMODEM REC ldi ones,9 ;init ones for tens cp loop
a10: cp value,tens
UART 304 brlo sub10 ;if value=tens
UART 305 sub value,tens ;remove 10s from value
subi ones,-0x30 ;?0<=x<=?9, 2nd digit is '?'
UART 128
mov tens,ones
UART BUFF
mov ones,value ;3rd digit is the remainder
USB 232
subi ones,-0x30 ;'ones' in ASCII
AVR ISP
ISP 2313 ret
RESET:
;***** Code
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,high(RAMEND)
out SPH,temp ;init Stack Pointer
clr ZH
ldi ZL,tableend*2+1 ;Z-pointer <- ROM table end
+ 1
ldi YL,low(256*TABLE_H+TABLE_L+SIZE)
ldi YH,high(256*TABLE_H+TABLE_L+SIZE)
;Y pointer <- SRAM table
end + 1
loop: lpm ;get ROM constant
st -Y,r0 ;store in SRAM and
decrement Y-pointer
sbiw ZL,1 ;decrement Z-pointer
cpi YL,TABLE_L ;if not done
brne loop ; loop more
cpi YH,TABLE_H
brne loop
ldi ZL,TABLE_L
ldi ZH,TABLE_H
ldi T_size,SIZE
rcall mav8
forever:rjmp forever
table:
.db 120,196
.db 78,216
.db 78,100
.db 43,39
.db 241,43
.db 62,172
.db 109,69
.db 48,184
.db 215,231
.db 63,133
.db 216,8
.db 121,126
.db 188,98
.db 168,205
.db 157,172
.db 108,233
.db 80,255
.db 252,102
.db 198,0
.db 171,239
.db 107,114
.db 172,170
.db 17,45
.db 42,55
.db 34,174
.db 229,250
.db 12,179
.db 187,243
.db 44,231
tableend:
.db 76,48
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
while_schleife_body:
mov istep,mmax
lsl istep ;istep:=2*mmax
clr ii ;ii:=0
for_schleife_ii_start: ;for ii=1 to (mmax div 2)
inc ii
mov m,ii
lsl m ;m:=2*ii
dec m ;m:=2*ii-1
ldi temp,nn2 ;nn2=64
sub temp,m ;nn2-m
mov dd8u,temp
mov dv8u,istep
rcall div8u ;Divisionsroutine
;.def drem8u =r15 ;remainder
;.def dres8u =r24 ;result
;.def dd8u =r24 ;dividend
;.def dv8u =r25 ;divisor
mov jjende,dres8u ;jjende:=nn2-m div istep
clr jj ;jj:=0 Initialisierung für
Schleife
;Nun holen wir die Cosinuswerte
ldi ZH,high(2*cosinetab)
ldi ZL, low(2*cosinetab)
ldi zaehler,nn2
mov temp,mmax
lsr temp
pp: lsr zaehler
lsr temp
brne pp
mov temp,ii
dec temp
mul temp,zaehler
add ZL,r0
adc ZH,r1
add ZL,r0 ;addition des pointers doppelt wegen
adc ZH,r1 ;2Byte pro Tabelleneintrag
lpm wrL,Z+ ;jetzt haben wir wrL(ow)
lpm wrH,Z ;jetzt haben wir wrH(igh)
;Nun holen wir die Sinuswerte
ldi ZH,high(2*sinetab)
ldi ZL, low(2*sinetab)
ldi zaehler,nn2
mov temp,mmax
lsr temp
pq: lsr zaehler
lsr temp
brne pq
mov temp,ii
dec temp
mul temp,zaehler
add ZL,r0
adc ZH,r1
add ZL,r0 ;Addition des Pointer-Werts doppelt
wegen
adc ZH,r1 ;2Byte pro Tabelleneintrag
lpm wiL,Z+ ;jetzt haben wir wiL(ow)
lpm wiH,Z ;jetzt haben wir wiH(igh)
for_schleife_jj_start:
rcall Schleife_jj_body ;damit die Schleife mit
einer branch-instruktion
;abgeschlossen werden kann,
wird die eigentliche
;Abarbeitungsroutine mit rcall
aufgerufen.
;(Problem ist die
Sprungreichweite von brsh)
inc jj
cp jjende,jj
brsh for_schleife_jj_start
;ende der jj-Schleife
mov temp,mmax
lsr temp ;iiende:=mmax div 2
cp ii,temp
brlo for_schleife_ii_start
;hier ist das ende der for_schleife_ii
mov mmax,istep
rjmp while_schleife_start
While_schleife_ende:
; Die FFTransformation ist geschafft! Jetzt muß nur
noch richtig
; sortiert werden, da Inputdaten reelle Werte waren.
ldi i,1 ;Initialisierung von i
for_schleife_i_anfang:
inc i ;for i:=2 to ((nn2 div 4)+1)
;Berechnung der Indizes i1..i4
mov i1,i
lsl i1
dec i1 ; i1:=i+i-1
mov i2,i1
inc i2 ; i2:= i1+1
ldi temp,nn2
sub temp,i2
subi temp,-3
mov i3,temp ; i3:=nn2-i2+3
mov i4,i3
inc i4 ; i4:=i3+1
;Nun holen wir die wr
ldi ZH,high(2*cosinetab)
ldi ZL, low(2*cosinetab)
mov temp,i
dec temp
lsl temp
add ZL,temp
adc ZH,nullwert
lpm wrL,Z+ ;jetzt haben wir wrL(ow)
lpm wrH,Z ;jetzt haben wir wrH(igh)
;Nun holen wir die wi
ldi ZH,high(2*sinetab)
ldi ZL, low(2*sinetab)
mov temp,i
dec temp
lsl temp
add ZL,temp
adc ZH,nullwert
lpm wiL,Z+ ;jetzt haben wir wiL(ow)
lpm wiH,Z ;jetzt haben wir wiH(igh)
rcall for_schleife_calculus ;auch hier
Unterprogramm, damit die
;Schleife mit brlo enden
kann.
;test ob FOR_Schleife schon fertig
ldi temp,nn2
lsr temp
lsr temp
inc temp
cp i,temp
brlo for_schleife_i_anfang
for_schleife_i_exit: ;Umsortieren ist
geschafft.
nop
;here comes compensation for DC-Value.
; if DC is not important, then just skip the following
routine
rcall DC_compensation
;
***********************************************************
;now the fft is done.
;data contains real-part and imaginary-part as 16bit
values
;arranged in pairs first real, then imaginary
;
***********************************************************
ende: ;Das Werk ist vollbracht!
rjmp ende ;SCHLUSS! ENDE! AUS!
for_schleife_calculus:
;***** Berechnung von h1r und h2i
;hole Data[i1] in reg. data2:data1
ldi XH,0
ldi XL,sramstart
add XL,i1
adc XH,nullwert
add XL,i1
adc XH,nullwert
ld data1,X+ ;lower-Byte zuerst
ld data2,X ;Highbyte
;hole Data[i3] in register-pair data4:data3
ldi XH,0
ldi XL,sramstart
add XL,i3
adc XH,nullwert
add XL,i3
adc XH,nullwert
ld data3,X+ ;lower-Byte zuerst
ld data4,X ;Highbyte
asr data2
ror data1 ;data[i1]:=data[i1]/2
asr data4
ror data3 ;data[i3]:=data[i3]/2
movw tmp_hi:tmp_lo,data2:data1
add tmp_lo,data3
adc tmp_hi,data4 ;h1r:=data[i1]+data[i3]
sts h1r_lo,tmp_lo
sts h1r_hi,tmp_hi ;save h1r to sram-location
movw tmp_hi:tmp_lo,data2:data1
sub tmp_lo,data3
sbc tmp_hi,data4 ;h1r:=-1*(data[i1]-data[i3])
com tmp_lo
com tmp_hi
ldi temp,1
add tmp_lo,temp
adc tmp_hi,nullwert
sts h2i_lo,tmp_lo
sts h2i_hi,tmp_hi ;save h1r to sram-location
;***** Berechnung von h1i und h2r
;hole Data[i2] in reg. data2:data1
ldi XH,0
ldi XL,sramstart
add XL,i2
adc XH,nullwert
add XL,i2
adc XH,nullwert
ld data1,X+ ;lower-Byte zuerst
ld data2,X ;Highbyte
;hole Data[i4] in register-pair data4:data3
ldi XH,0
ldi XL,sramstart
add XL,i4
adc XH,nullwert
add XL,i4
adc XH,nullwert
ld data3,X+ ;lower-Byte zuerst
ld data4,X ;Highbyte
asr data2
ror data1 ;data[i2]:=data[i2]/2
asr data4
ror data3 ;data[i4]:=data[i4]/2
movw tmp_hi:tmp_lo,data2:data1
sub tmp_lo,data3
sbc tmp_hi,data4
sts h1i_lo,tmp_lo
sts h1i_hi,tmp_hi ;save h1i to sram-location
add data1,data3
adc data2,data4
sts h2r_lo,data1
sts h2r_hi,data2 ;save h2r to sram-location
push r23
push r22
push r21
push r20
push r19
push r18
push r17
push r16
; **** Data[i1]:=h1r+wr*h2r-wi*h2i
movw R21:R20,wrh:wrl
lds r23,h2r_hi
lds r22,h2r_lo
rcall muls16x16_32
mov data2,r18
mov data1,r17
movw R21:R20,wih:wil
lds r23,h2i_hi
lds r22,h2i_lo
rcall muls16x16_32
sub data1,r17
sbc data2,r18
lds r18,h1r_hi
lds r17,h1r_lo
add data1,r17
adc data2,r18
ldi XH,0
ldi XL,sramstart
add XL,i1
adc XH,nullwert
add XL,i1
adc XH,nullwert
st X+,data1
st X ,data2
; **** Data[i2]:=h1i+wr*h2i+wi*h2r
movw R21:R20,wrh:wrl
lds r23,h2i_hi
lds r22,h2i_lo
rcall muls16x16_32
mov data2,r18
mov data1,r17
movw R21:R20,wih:wil
lds r23,h2r_hi
lds r22,h2r_lo
rcall muls16x16_32
add data1,r17
adc data2,r18
lds r18,h1i_hi
lds r17,h1i_lo
add data1,r17
adc data2,r18
ldi XH,0
ldi XL,sramstart
add XL,i2
adc XH,nullwert
add XL,i2
adc XH,nullwert
st X+,data1
st X ,data2
; **** Data[i3]:=h1r-wr*h2r+wi*h2i
movw R21:R20,wih:wil
lds r23,h2i_hi
lds r22,h2i_lo
rcall muls16x16_32
mov data2,r18
mov data1,r17
movw R21:R20,wrh:wrl
lds r23,h2r_hi
lds r22,h2r_lo
rcall muls16x16_32
sub data1,r17
sbc data2,r18
lds r18,h1r_hi
lds r17,h1r_lo
add data1,r17
adc data2,r18
ldi XH,0
ldi XL,sramstart
add XL,i3
adc XH,nullwert
add XL,i3
adc XH,nullwert
st X+,data1
st X ,data2
; **** Data[i4]:=-h1i+wr*h2i+wi*h2r
movw R21:R20,wrh:wrl
lds r23,h2i_hi
lds r22,h2i_lo
rcall muls16x16_32
mov data2,r18
mov data1,r17
movw R21:R20,wih:wil
lds r23,h2r_hi
lds r22,h2r_lo
rcall muls16x16_32
add data1,r17
adc data2,r18
lds r18,h1i_hi
lds r17,h1i_lo
sub data1,r17
sbc data2,r18
ldi XH,0
ldi XL,sramstart
add XL,i4
adc XH,nullwert
add XL,i4
adc XH,nullwert
st X+,data1
st X ,data2
pop r16
pop r17
pop r18
pop r19
pop r20
pop r21
pop r22
pop r23
ret ;ende der umfangreichen Berechnungen in
For_schleife_i
DC_compensation:
lds data1,sramstart+2
lds data2,sramstart+3
lds data3,sramstart+4
lds data4,sramstart+5
movw tmp_hi:tmp_lo,data2:data1
add data1,data3
adc data2,data4
sub tmp_lo,data3
sbc tmp_hi,data4
sts sramstart+2,data1
sts sramstart+3,data2
sts sramstart+4,tmp_lo
sts sramstart+5,tmp_hi
ret
;ende DC-kompensation
speicherorte_128_werte:
.db 1,2
.db 65,66
.db 33,34
.db 97,98
.db 17,18
.db 81,82
.db 49,50
.db 113,114
.db 9,10
.db 73,74
.db 41,42
.db 105,106
.db 25,26
.db 89,90
.db 57,58
.db 121,122
.db 5,6
.db 69,70
.db 37,38
.db 101,102
.db 21,22
.db 85,86
.db 53,54
.db 117,118
.db 13,14
.db 77,78
.db 45,46
.db 109,110
.db 29,30
.db 93,94
.db 61,62
.db 125,126
.db 3,4
.db 67,68
.db 35,36
.db 99,100
.db 19,20
.db 83,84
.db 51,52
.db 115,116
.db 11,12
.db 75,76
.db 43,44
.db 107,108
.db 27,28
.db 91,92
.db 59,60
.db 123,124
.db 7,8
.db 71,72
.db 39,40
.db 103,104
.db 23,24
.db 87,88
.db 55,56
.db 119,120
.db 15,16
.db 79,80
.db 47,48
.db 111,112
.db 31,32
.db 95,96
.db 63,64
.db 127,128
;
******************************************************************************
;*
;* FUNCTION
;* muls16x16_32
;* DECRIPTION
;* Signed multiply of two 16bits numbers with 32bits
result.
;* USAGE
;* r19:r18:r17:r16 = r23:r22 * r21:r20
;* STATISTICS
;* Cycles : 19 + ret
;* Words : 15 + ret
;* Register usage: r0:r1 and r6 and r16 to r23 (11
registers)
;* NOTE
;* The routine is non-destructive to the operands.
;*
;
******************************************************************************
muls16x16_32:
; clr r6
muls r23, r21 ; (signed)ah * (signed)bh
movw r19:r18, r1:r0
mul r22, r20 ; al * bl
movw r17:r16, r1:r0
mulsu r23, r20 ; (signed)ah * bl
sbc r19, r6
add r17, r0
adc r18, r1
adc r19, r6
mulsu r21, r22 ; (signed)bh * al
sbc r19, r6
add r17, r0
adc r18, r1
adc r19, r6
ret
;
***************************************************************************
;*
;* "div8u" - 8/8 Bit Unsigned Division
;*
;* This subroutine divides the two register variables
"dd8u" (dividend) and
;* "dv8u" (divisor). The result is placed in "dres8u"
and the remainder in
;* "drem8u".
;*
;* Number of words :66 + return
;* Number of cycles :50/58/66 (Min/Avg/Max) + return
;* Low registers used :1 (drem8u)
;* High registers used :2 (dres8u/dd8u,dv8u)
;*
;
***************************************************************************
;***** Code
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search