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
;***** Code
RESET:
ldi temp,low(RAMEND)
out SPL,temp ;init Stack
Pointer
ldi temp,high(RAMEND)
out SPH,temp
ldi ZH,high(F_TABLE*2)
ldi ZL,low(F_TABLE*2);init Z-pointer
ldi YH,high(BLOCK1)
ldi YL,low(BLOCK1) ;init Y-pointer
ldi flashsize,20
rcall flash2ram ;copy 20 bytes
ldi ZH,high(BLOCK1)
ldi ZL,low(BLOCK1) ;init Z-pointer
ldi YH,high(BLOCK2) ;(not necessary in this
specific case)
ldi YL,low(BLOCK2) ;init Y-pointer
ldi ramsize,20
rcall ram2ram ;copy 20 bytes
F_TABLE:
.db 0,1 ;start of table (20 bytes)
.db 2,3
.db 4,5
.db 6,7
.db 8,9
.db 10,11
.db 12,13
.db 14,15
.db 16,17
.db 18,19
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
FLOAT 128
SQRT16 .include "8515def.inc"
;***** Code
EERead:
sbic EECR,EEWE ;if EEWE not clear
rjmp EERead ; wait more
; out EEAR,EEard ;output address for 1200,
commented out !
;
***************************************************************************
;*
;* EEWrite_seq
;*
;* This subroutine increments the EEPROM address by one
and waits until the
;* EEPROM is ready for programming. It then programs
the EEPROM with
;* register variable "EEdwr_s".
;***** Code
EEWrite_seq:
sbic EECR,EEWE ;if EEWE not clear
rjmp EEWrite_seq ; wait more
;
***************************************************************************
;*
;* EERead_seq
;*
;* This subroutine increments the address stored in
EEAR and reads the
;* EEPROM into the register variable "EEdrd_s".
;***** Code
EERead_seq:
sbic EECR,EEWE ;if EEWE not clear
rjmp EERead_seq ; wait more
; The above sequence for EEWE = 0 can be skipped if no
write is initiated.
;
****************************************************************************
;*
;* Test/Example Program
;*
;
****************************************************************************
;***** Code
RESET:
;***** Initialize stack pointer
;* Initialize stack pointer to highest address in
internal SRAM
;* Comment out for devices without SRAM
ldi EEdwr,$aa
ldi EEawrh,$00
ldi EEawr,$10
rcall EEWrite ;store $aa in EEPROM
location $0010
ldi EEardh,$00
ldi EEard,$10
rcall EERead ;read address $10
out PORTB,EEdrd ;output value to Port B
clr temp
out EEARH,temp ;EEARH <- $00
ldi temp,$00
out EEARL,temp ;EEAR <- $00 (start address
- 1)
clr ZH
ldi ZL,1 ;Z-pointer points to r1
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
MATH 202
MATH 202
DEC ASCII
INT ASCII
HX2ASC
AVG8 222
FFT7
COPY 102
LPM 108
EPROM 100 Programming the AVR Microcontrollers in Machine Language
SER EPROM
DFLASH AT45 AVR
FLASH CARD << Prev | Ring Hub | Join | Rate| Next
VFX SMIL >>
© WebRing Inc. Search
VFX MEM
SORT 220
CRC 236
Atmel AVR From Wikipedia, the free encyclopedia
XMODEM REC
UART 304
(Redirected from Avr) Jump to: navigation, search The
UART 305 AVRs are a family of RISC microcontrollers from Atmel.
UART 128
Their internal architecture was conceived by two
UART BUFF
USB 232
students: Alf-Egil Bogen and Vegard Wollan, at the
AVR ISP Norwegian Institute of Technology (NTH] and further
ISP 2313
developed at Atmel Norway, a subsidiary founded by the
ISP 1200
AVR SPI
two architects. Atmel recently released the Atmel AVR32
I2C 300 line of microcontrollers. These are 32-bit RISC devices
I2C 302
featuring SIMD and DSP instructions, along with many
I2C TWI26
I2C/TWI 128
additional features for audio and video processing,
I2C/TWI AT8 intended to compete with ARM based processors. Note
DALLAS-1W that the use of "AVR" in this article refers to the 8-bit
DALLAS CRC
ETHNET 8019
RISC line of Atmel AVR Microcontrollers. The acronym
TEA AVR has been reported to stand for Advanced Virtual
ADC 128 RISC. It's also rumoured to stand for the company's
ADC 10B
ADC 400
founders: Alf and Vegard, who are evasive when
ADC 401 questioned about it. Contents [hide] 1 Device Overview
THERM 232 1.1 Program Memory 1.2 Data Memory and Registers 1.3
IRD 410
LCD HD44
EEPROM 1.4 Program Execution 1.5 Speed 2
LCD 2313 Development 3 Features 4 Footnotes 5 See also 6
LCD44 2313 External Links 6.1 Atmel Official Links 6.2 AVR Forums &
KBD 240
MUX 242
Discussion Groups 6.3 Machine Language Development
KBD PS2 6.4 C Language Development 6.5 BASIC & Other AVR
KBD PC/128 Languages 6.6 AVR Butterfly Specific 6.7 Other AVR
PS2 EMU
BOOT MG8
Links [edit] Device Overview The AVR is a Harvard
BOOT DR8 architecture machine with programs and data stored and
ALM CLK addressed separately. Flash, EEPROM, and SRAM are all
CLOCK 8564
90 DAYS
integrated onto a single die, removing the need for
DELAYS external memory (though still available on some devices).
CALL ID [edit] Program Memory Program instructions are stored
DTMF 314
PWM 6CH
in semi-permanent Flash memory. Each instruction for
PWM 10K the AVR line is either 16 or 32 bits in length. The Flash
ENCODE memory is addressed using 16 bit word sizes. The size of
STH-11
ATMEL CORP
the program memory is indicated in the naming of the
AVR device itself. For instance, the ATmega64x line has
BUTTERFLY
64Kbytes of Flash. Almost all AVR devices are self-
AVR BOOK
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/sereprom.html (1 of 2)1/20/2009 8:48:42 PM
16 BIT MATH (AVR 202)
;
**************************************************************************
;* Hardware Def.
;
; RDY/BUSY - Ready/Busy
.equ DFRDY_PORT = PORTD
.equ DFRDY_DIR = DDRD
.equ DFRDY_PIN = PIND
.equ DFRDY = 7
;
***************************************************************************
;**** VARIABLES
.DSEG
DFSize: .byte 1
DFPageSize: .byte 1
DFPageBits: .byte 1
;
***************************************************************************
.ESEG
;
***************************************************************************
;**** CODE SEG
;
***************************************************************************
.CSEG
;p,x,y,z,0
;page bits = p
;page number = x * 256
;page size = y * 256 (264)
;type = z
;
AT45DBxxx: .db 9, 2,1,0b00001100 ;AT45DB011 1Mbit
.db 9, 4,1,0b00010100 ;AT45DB021 2Mbit
.db 9, 8,1,0b00011100 ;AT45DB041 4Mbit
.db 9,16,1,0b00100100 ;AT45DB081 8Mbit
.db 10,16,2,0b00101100 ;AT45DB161 16Mbit
.db 10,32,2,0b00110100 ;AT45DB321 32Mbit
.db 11,32,4,0b00111000 ;AT45DB642 64Mbit
.db 11,64,4,0b00010000 ;AT45DB1282
128Mbit
.dw 0,0
;
****************************************************************************
;*** S P I R U T I N S
;***
;
****************************************************************************
;* SPI_init
;*
;* Initialize our port pins for use as SPI master.
;*
;
***************************************************************************
;
SPI_init:
sbi DFCS_PORT,DFCS ;DFlash CE
pin is output for ATmega
sbi DFCS_DIR,DFCS ;CS=1
sbi DFRES_PORT,DFRES
sbi DFRES_DIR,DFRES ;DFlash
Reset = H
cbi DFRDY_DIR,DFRDY
sbi DFRDY_PORT,DFRDY ;DFlash R/B
pullup input
in R16,PORTB
andi R16,0b11000011
ori R16,0b00101100
out PORTB,R16 ;SS, MOSI,
SCK output; MISO input
in R16,DDRB
andi R16,0b11000011
ori R16,0b00101100
out DDRB,R16
ldi R16,0b01011100
out SPCR,R16 ;[7] - SPIE: SPI
Interrupt Enable
;[6] - SPE: SPI
Enable
;[5] - DORD: Data
Order
;[4] - MSTR: Master/
Slave Select
;[3] - CPOL: Clock
Polarity
;[2] - CPHA: Clock
Phase
;[1:0] - SPR1,SPR0:
SPI Clock Rate Select
; SPI2X SPR1 SPR0
SCK Frequency
; 0 0
0 fosc/4
; 0 0
1 fosc/16
; 0 1
0 fosc/64
; 0 1
1 fosc/128
; 1 0
0 fosc/2
; 1 0
1 fosc/8
; 1 1
0 fosc/32
; 1 1
1 fosc/64
ldi R16,0b00000001
out SPSR,R16 ;[7] - SPIF: SPI
Interrupt Flag
;[6] - WCOL: Write
COLlision flag
;[5:1] - Res:
Reserved Bits
;[0] - SPI2X:
Double SPI Speed Bit
in R16,SPSR
in R16,SPDR ;Clear SPIF & WCOL
bits
rcall DF_ReadStatus
cbr R16,0b11000011
ldi ZL,low(AT45DBxxx*2) ;ATmega128 -
> set PAMPZ!!
ldi ZH,high(AT45DBxxx*2)
SearchDF: lpm R17,Z+
sts DFPageBits,R17
lpm R18,Z+
sts DFSize,R18
lpm R18,Z+
sts DFPageSize,R18
lpm R2,Z+
cp R16,R2
breq DFHit
tst R17
brne SearchDF
DFHit:
ret
;
*****************************************************************************
;*DF_SPI_RW
;*
;* Read and writes one byte from/to SPI master
;*
;* In: R16 - Byte to be written to SPI data register
;*
;* Out: R16 - Byte read from SPI data register
;*
;
******************************************************************************
;
DF_SPI_RW:
out SPDR,R16
DF_SPI_RW0:
sbis SPSR,spif
rjmp DF_SPI_RW0 ;wait for transfer
complete, poll SPIF-flag
in R16,SPDR
ret
;
*****************************************************************************
;*Read_DF_status
;*
;* Status info concerning the Dataflash is busy or not.
;* Status info concerning compare between buffer and
flash page
;* Status info concerning size of actual device
;*
;* In: -
;*
;* Out: R16 - status byte. Consult Dataflash datasheet
for further decoding info
;*
;
******************************************************************************
;
DF_ReadStatus:
sbi DFCS_PORT,DFCS ;DF CS
inactive
nop
nop
cbi DFCS_PORT,DFCS ;DF CS
Active!
;to reset
dataflash command decoder
ldi R16,StatusRegMode3
rcall DF_SPI_RW ;send
status register read op-code
clr R16
rcall DF_SPI_RW ;dummy
write to get result
ret
;
*****************************************************************************
;* WaitToDF
;*
;* Wait for DataFlash to Ready
;*
;* In: -
;*
;* Out: -
;*
;
******************************************************************************
;
WaitToDF:
rcall DF_ReadStatus
cbr R16,0x7F ;
Csak a Busy Flag marad meg
breq WaitToDF ;
monitor the status register, wait until busy-flag is high
sbi DFCS_PORT,DFCS ;DF CS
inactive
nop
cbi DFCS_PORT,DFCS ;DF CS
Active! , reset dataflash command decoder
ret
;
*****************************************************************************
;Page_To_Buffer
;
; Transfers a page from flash to dataflash SRAM buffer
;
; In: R0 = BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 = PageAdr -> Address of page to be
transferred to buffer
;
; Out: -
;
*****************************************************************************
;
DF_PageToBuffer:
rcall WaitToDF
ldi R16,FlashToBuf1Transfer ;transfer
to buffer 1 op-code
tst R0
breq DF_PageToBuff01
ldi R16,FlashToBuf2Transfer ;transfer
to buffer 2 op-code
DF_PageToBuff01:
rcall DF_SPI_RW ;send op-
code
lds R16,DFPageBits
subi R16,8
DF_PageToBuff02:
lsl R18
rol R19
dec R16
brne DF_PageToBuff02
mov R16,R19
rcall DF_SPI_RW ;upper part of page
address
mov R16,R18
rcall DF_SPI_RW ;lower part of page
address
clr R16
rcall DF_SPI_RW
;
*****************************************************************************
;DF_BufferReadByte
;
; Reads one byte from one of the dataflash internal
SRAM buffers
;
; In: R0 = BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 = IntPageAdr -> Internal page address
;
; Out: R16 - One read byte (any value)
;
;
*****************************************************************************
;
DF_BufferReadByte:
rcall WaitToDF
ldi R16,Buf1Read ;read byte
from buffer 1
tst R0
breq BufferReadByte01
ldi R16,Buf2Read ;read byte
from buffer 2
BufferReadByte01:
rcall DF_SPI_RW ;send op-
code
clr R16
rcall DF_SPI_RW ;don't cares
mov R16,R19
rcall DF_SPI_RW ;upper part
of page address
mov R16,R18
rcall DF_SPI_RW ;lower part
of page address
clr R16
rcall DF_SPI_RW ;additional
don't cares
clr R16
rcall DF_SPI_RW ;read byte
sbi DFCS_PORT,DFCS ;DF CS
inactive
ret
;
*****************************************************************************
;DF_BufferReadStr
;
; Reads one or more bytes from one of the dataflash
internal SRAM buffers,
; and puts read bytes into buffer pointed to by X
; In: R0: BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 -> Internal page address
; R21:R20 -> Number of bytes to be read
; X -> address of buffer to be
used for read bytes
;
; Out: -
;
;
*****************************************************************************
;
DF_BufferReadStr:
rcall WaitToDF
ldi R16,Buf1Read ;read byte
from buffer 1
tst R0
breq DF_BufferReadStr01
ldi R16,Buf2Read ;read byte
from buffer 2
DF_BufferReadStr01:
rcall DF_SPI_RW ;send op-
code
clr R16
rcall DF_SPI_RW ;don't cares
mov R16,R19
rcall DF_SPI_RW ;upper part
of page address
mov R16,R18
rcall DF_SPI_RW ;lower part
of page address
clr R16
rcall DF_SPI_RW ;additional
don't cares
push YL
push YH
movw YL,R20 ;Internal
page address + Number of bytes to be read <= Page Size!!!
DF_BufferReadStr02:
clr R16
rcall DF_SPI_RW
st X+,R16 ;Store DF
data byte
sbiw YL,1
brne DF_BufferReadStr02
pop YH
pop YL
sbi DFCS_PORT,DFCS ;DF CS
inactive
ret
;
*****************************************************************************
; DF_BufferWriteEnable
;
; Enables continous write functionality to one of the
dataflash buffers
; NOTE : User must ensure that CS goes high to
terminate this mode
; before accessing other dataflash functionalities
;
; In: R0: BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 -> Internal page address to
start writing from
;
; Out: None
;
;
*****************************************************************************
;
DF_BufferWriteEnable:
rcall WaitToDF
ldi R16,Buf1Write ;buffer 1
write op-code
tst R0
breq DF_BufferWriteEnable01
ldi R16,Buf2Write ;buffer 2
write op-code
DF_BufferWriteEnable01:
rcall DF_SPI_RW ;send op-
code
clr R16
rcall DF_SPI_RW ;don't cares
mov R16,R19
rcall DF_SPI_RW ;upper part
of page address
mov R16,R18
rcall DF_SPI_RW ;lower part
of page address
ret
;
*****************************************************************************
; DF_BufferWriteByte:
;
; Writes one byte to one of the dataflash internal SRAM
buffers
;
; In: R0: BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 -> Internal page address to
write byte to
; R16 -> Data byte to be written
;
; Out: None
;
;
*****************************************************************************
;
DF_BufferWriteByte:
push R16
rcall WaitToDF
ldi R16,Buf1Write ;buffer 1
write op-code
tst R0
breq DF_BufferWriteByte01
ldi R16,Buf2Write ;buffer 2
write op-code
DF_BufferWriteByte01:
rcall DF_SPI_RW ;send op-
code
clr R16
rcall DF_SPI_RW ;don't cares
mov R16,R19
rcall DF_SPI_RW ;upper part
of page address
mov R16,R18
rcall DF_SPI_RW ;lower part
of page address
pop R16
rcall DF_SPI_RW ;write data
byte
DF_EndWrite:
sbi DFCS_PORT,DFCS ;DF CS
inactive
ret
;
*****************************************************************************
; DF_BufferWriteStr
;
; Copies one or more bytes to one of the dataflash
internal SRAM buffers
; from AVR SRAM buffer pointed to by X
;
; In: R0: BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 -> Internal page address
; R21:R20 -> Number of bytes to be read
; X -> address of buffer to be
used for write bytes
;
; Out: None
;
;
*****************************************************************************
;
DF_BufferWriteStr:
rcall WaitToDF
ldi R16,Buf1Write ;write byte
to buffer 1
tst R0
breq DF_BufferWriteStr01
ldi R16,Buf2Write ;write byte
to buffer 2
DF_BufferWriteStr01:
rcall DF_SPI_RW ;send op-
code
clr R16
rcall DF_SPI_RW ;don't cares
mov R16,R19
rcall DF_SPI_RW ;upper part
of page address
mov R16,R18
rcall DF_SPI_RW ;lower part
of page address
push YL
push YH
movw YL,R20 ;Internal
page address + Number of bytes to be read <= Page Size!!!
DF_BufferWriteStr02:
ld R16,X+ ;Store DF
data byte
rcall DF_SPI_RW
sbiw YL,1
brne DF_BufferWriteStr02
pop YH
pop YL
ret
;
*****************************************************************************
; DF_BufferToPage
; DF_BufferToPageWErase
;
; Transfers a page from dataflash SRAM buffer to flash
;
; In: R0 = BufferNo -> R0 = 0 usage Buffer 1
; = non zero usage Buffer 2
; R19:R18 = PageAdr -> Address of flash page to be
programmed
;
; Out: None
;
;
*****************************************************************************
;
DF_BufferToPage:
rcall WaitToDF
ldi R16,Buffer1toMem ;buffer 1
to flash without erase
tst R0
breq DF_BufferToPage01
ldi R16,Buffer1toMem
rjmp DF_BufferToPage01
DF_BufferToPageWErase:
rcall WaitToDF
ldi R16,Buf1ToFlashWE ;buffer 1
to flash with erase op-code
tst R0
breq DF_BufferToPage01
ldi R16,Buf2ToFlashWE ;buffer 2
to flash with erase op-code
DF_BufferToPage01:
rcall DF_SPI_RW ;send op-
code
lds R16,DFPageBits
subi R16,8
DF_BufferToPage02:
lsl R18
rol R19
dec R16
brne DF_BufferToPage02
mov R16,R19
rcall DF_SPI_RW ;upper part of page
address
mov R16,R18
rcall DF_SPI_RW ;lower part of page
address
clr R16
rcall DF_SPI_RW
nop
sbi DFCS_PORT,DFCS ;DF CS
inactive
ret
;
*****************************************************************************
; DF_PageErase
;
; Erase Flash Page
;
; In: R19:R18 = PageAdr -> Address of flash
page to be erased
;
; Out: None
;
;
*****************************************************************************
;
DF_PageErase:
rcall WaitToDF
ldi R16,DFPageErase
rcall DF_SPI_RW ;send op-
code
lds R16,DFPageBits
subi R16,8
DF_PageErase01:
lsl R18
rol R19
dec R16
brne DF_PageErase01
mov R16,R19
rcall DF_SPI_RW ;upper part
of page address
mov R16,R18
rcall DF_SPI_RW ;lower part
of page address
clr R16
rcall DF_SPI_RW ;dumpy part
of address!!!
nop
sbi DFCS_PORT,DFCS ;DF CS
inactive
ret
;
*****************************************************************************
; DF_CheckErasedPage
;
; Test Erased Flash Page
;
; In: R19:R18 = PageAdr -> Address of flash
page to be tested
; R0 = used buffer 0 = buffer0 other = buffer1
;
; Out: c=0 no error
; c=1 Bad Page! Dont use!!
;
;
*****************************************************************************
;
DF_CheckErasedPage:
rcall WaitToDF
push R0
rcall DF_PageToBuffer
clr XL
ldi R16,8
lds XH,DFPageSize
mul R16,XH
add XL,R0
adc XH,R1 ;X full
lenght of page in byte
pop R0
DF_Check00:
push R0
push XL
push XH
sbiw XL,1
movw R18,XL
rcall DF_BufferReadByte
pop XH
pop XL
pop R0
cpi R16,0xFF
brne DF_BadPage
sbiw XL,1
brne DF_Check00
clc
ret ;ok page
cleared well
DF_BadPage:
sec
ret ;Bad Page!
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
***************************************************************************************
;*** Definition of the status register bits
;***
;***
Bit7
Bit0
;*** BSY DRDY DWF DSC
DRQ CORR IDX ERR
;
***************************************************************************************
.equ CFC_STATUS_BSY = 0x80 ;Busy flag
.equ CFC_STATUS_DRDY = 0x40 ;Drive ready
.equ CFC_STATUS_DWF = 0x20 ;Drive write fault
.equ CFC_STATUS_DSC = 0x10 ;Drive seek complete
.equ CFC_STATUS_DRQ = 0x08 ;Data request
.equ CFC_STATUS_CORR = 0x04 ;Corrected data
.equ CFC_STATUS_IDX = 0x02 ;Index
.equ CFC_STATUS_ERR = 0x01 ;Error
;
;***************************************************************************
;**** VARIABLES
.DSEG
;***************************************************************************
.ESEG
;***************************************************************************
;**** CODE SEG
;***************************************************************************
.CSEG
;********************************************************
;CFRdy
;
; Wait until CF not busy
;
; Out: c= 0 no error
; 1 error
;
; Alt: R16,R17
;
CFHWRdy:
lds R16,ADR_CFST
bst R16,CFVS1 ;CF inserted?
brtc CFHWRdy0
rjmp CFDrvError
CFHWRdy0:
lds R16,ADR_CFST
bst R16,CFRDY ;CF ready?
brtc CFHWRdy
clc
ret
;********************************************************
;CFWaitDRQ
;
; Wait until Data will available
;
; Out: c= 0 no error
; 1 error
;
; Alt: R16,R17
;
CFWaitDRQ:
rcall CFHWRdy
brcc CFWaitDRQ00
ret
CFWaitDRQ00:
lds R16,CF_STACOM
bst R16,0
brtc CFWaitDRQ0
CFWaitErr:
ldi R16,low(0xFFF0) ;Error in last command
ldi R17,high(0xFFF0) ;ide keresunk egy error kodot!!!
sec
ret
CFWaitDRQ0:
andi R16,0xF8
cpi R16,0x58
brne CFWaitDRQ
clc
ret
;********************************************************
;CFWaitReady
;
; Wait until CF will ready
;
; Out: c= 0 no error
; 1 error
;
; Alt: R16,R17
;
CFWaitReady:
rcall CFHWRdy
brcc CFWaitRdy0
ret
CFWaitRdy0:
lds R16,CF_STACOM
bst R16,0
brts CFWaitErr
CFWaitReady01:
andi R16,0xF0
cpi R16,0x50
brne CFWaitReady
clc
ret
;********************************************************
;CFReadSector
;
; In: R13:R12:R11:R10 - LBA sector number
; Page: Y - Pointer to Data Buffer [512 byte]
; Z - Phis. Drive Descriptor
;
; Out: c= 0 no error
; 1 error
;
CFReadSector:
ldd R0,Z+MaxSector+0
ldd R1,Z+MaxSector+1
ldd R2,Z+MaxSector+2
ldd R3,Z+MaxSector+3
cp R10,R0
cpc R11,R1
cpc R12,R2
cpc R13,R3
brcs CFReadSec00
rcall CFWaitReady
brcc CFReadSec01
ret ;Error in last command
CFReadSec01:
ldi R16,1
sts CF_SECCOUNT,R16
nop
sts CF_LBA0,R10 ;D7..D0
nop
sts CF_LBA1,R11 ;D15..D8
nop
sts CF_LBA2,R12 ;D23..D16
ldi R16,0x0F
and R16,R13
ori R16,0xE0 ;set LBA mode
sts CF_LBA3,R16 ;D27..D24 + LBA mode + Drive0
ldi R16,CF_CMD_READ_SEC
sts CF_STACOM,R16 ;Set Read Sector Command
ldi XL,0
ldi XH,1 ;if X==0 -> X=256 word;
rcall CFWaitDrq
brcc CFReadSec02
ret ;Drive error
CFReadSec02:
lds R16,ADR_CFST
bst R16,CFVS1 ;CF inserted?
brts CFDrvError
bst R16,CFRDY ;CF ready?
brtc CFReadSec02
lds R16,CF_EvenData
st Y+,R16
lds R16,CF_OddData
st Y+,R16
sbiw XL,1
brne CFReadSec02
CFDrvError:
ldi R16,low(ERROR_BAD_UNIT)
ldi R17,high(ERROR_BAD_UNIT) ;Drive not present
sec
ret
;********************************************************
;CFWriteSector
;
; In: R13:R12:R11:R10 - LBA sector number
; Page: Y - Pointer to Data Buffer [512 byte]
; Z - Phis. Drive Descriptor
;
; Out: c= 0 no error
; 1 error
;
CFWriteSector:
ldd R0,Z+MaxSector+0
ldd R1,Z+MaxSector+1
ldd R2,Z+MaxSector+2
ldd R3,Z+MaxSector+3
cp R10,R0
cpc R11,R1
cpc R12,R2
cpc R13,R3
brcs CFWriteSec00
ldi XL,0
ldi XH,1 ;if X==0 -> X=256 word;
movw R0,YL
rcall CFWaitDrq
brcc CFWriteSec02
ret ;Drive error
CFWriteSec02:
lds R16,ADR_CFST
bst R16,CFVS1 ;CF inserted?
brts CFDrvError
bst R16,CFRDY ;CF ready?
brtc CFWriteSec02
ld R16,Y+
sts CF_EvenData,R16
ld R16,Y+
sts CF_OddData,R16
sbiw XL,1
brne CFWriteSec02
movw YL,R0
clc
ret
;********************************************************
;CFResetDevice
;
; In: -
;
; Out: c= 0 no error
; 1 error R17:R16 error code
;
CFResetDevice:
ldi R16,0b00000100 ;Force SW reset
sts ADR_CFC+0x0E,R16 ;Device Control Register
ldi R16,64
CFRes0: dec R17
brne CFRes0
dec R16
brne CFRes0
clr R16
sts ADR_CFC+0x0E,R16 ;Device Control Register
rcall CFWaitReady
ret
;********************************************************
;CFIdentify
;
; In: Z - Phis. Drive Descriptor
; Page: Y - Pointer to temporary Data Buffer [512 byte]
;
; Out: c= 0 no error
; 1 error
;
CFIdentify:
rcall CFWaitReady
brcc CFIdent01
ret ;Error code in R17:R16
CFIdent01:
ldi R16,1
sts CF_SECCOUNT,R16
clr R16
sts CF_LBA0,R16
nop
sts CF_LBA1,R16
nop
sts CF_LBA2,R16
ldi R16,0xE0
sts CF_LBA3,R16
ldi R16,CF_CMD_IDENTIFY
sts CF_STACOM,R16
call CFWaitDRQ
brcc CFIdent02
ret ;Drive error
CFIdent02:
lds R16,CF_EvenData
st Y+,R16
nop
lds R16,CF_OddData
st Y+,R16
sbiw XL,1
brne CFIdent02
movw YL,R0
clr R0
ldd R16,Y+0 ;CF IDs: 848Ah
cpi R16,0x8A
brne CFIDs0
ldd R16,Y+1
cpi R16,0x84
brne CFIDs0
inc R0
CFIDs0:
std Z+MediaFlag,R0 ;Store CF ID
ldi R16,RemovableMedia
std Z+MediaType,R16
ldi R16,0x80
std Z+DiskNumber,R16 ;First HDD => HDD0
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 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
http://avr-asm.tripod.com/flashcard.html (1 of 2)1/20/2009 8:49:58 PM
16 BIT MATH (AVR 202)
;
--------------------------------------------------------------------------------------
; Sector Data Structure
; [1 Sector = 1 Page]
; 0-255 Data Area-1
; 256-511 Data Area-2
;
; Spare Area Information (4 ~ 128 MB)
; 512-515 Reserved Area
; 516 Data/User Status Flag/Area
; 517 Block Status Flag/Area
; 518-519 Block Address Area-1
; 520-522 ECC Area-2
; 523-524 Block Address Area-2
; 525-527 ECC Area-1
;
;
--------------------------------------------------------------------------------------
; Block Address Area Information
; [Block Address Configuration]
;D7 D6 D5 D4 D3 D2 D1 D0 1,2 MB
SM 4,8,16 MB and above SM
;
;0 0 0 1 0 BA9 BA8 BA7 262 bytes(even)
518, 523 bytes
; 259 bytes(odd)
;
;BA6 BA5 BA4 BA3 BA2 BA1 BA0 P 263 bytes(even)
519, 524 bytes
; 260 bytes(odd)
;
;BA9 ~ BA0 : Block Address (values=0 through n,where n
= maximum logical block count - 1)
;P : Even Parity bit
;
;
--------------------------------------------------------------------------------------
; Block_a Parameter Definition
; - Used Valid Block is block_a[ Physical block number]
= bl_addr(Block Address value)
; - Invalid Block is block_a[Physical block number] =
0xffee(Invalid Mark is defined as ‘ 0xffee’ )
; - CIS Block is block_a[Physical block number] = 0
(Actual Block Addess Value is ‘ 0x0000’ .)
; - Unused Valid Block[Physical block number] = 0xffff
;
;
--------------------------------------------------------------------------------------
;
; Support Devices
; K9S2808V0M-SSB0 16M x 8 bit SmartMedia Card - tested
; [32768 rows(pages), 528 columns]
;
;
; Command Latch Enable(CLE)
; The CLE input controls the path activation for
commands sent to the
; command register. When active high, commands are
latched into the
; command register through the I/O ports on the
rising edge of the
; WE signal.
;
; Address Latch Enable(ALE)
; The ALE input controls the activating path for
address to the internal
; address registers. Addresses are latched on the
rising edge of WE with
; ALE high.
;
; Chip Enable(CE)
; The CE input is the device selection control. When
CE goes high during
; a read operation the device is returned to standby
mode.
; However, when the device is in the busy state
during program or erase,
; CE high is ignored, and does not return the device
to standby mode.
;
; Write Enable(WE)
; The WE input controls writes to the I/O port.
Commands, address and data
; are latched on the rising edge of the WE pulse.
;
; Read Enable(RE)
; The RE input is the serial data-out control, and
when active drives the
; data onto the I/O bus. Data is valid tREA after the
falling edge of RE
; which also increments the internal column address
counter by one.
;
; I/O Port : I/O 0 ~ I/O 7
; The I/O pins are used to input command, address and
data, and to output
; data during read operations. The I/O pins float to
high-z when the chip
; is deselected or when the outputs are disabled.
;
; Write Protect(WP)
; The WP pin provides inadvertent write/erase
protection during power
; transitions. The internal high voltage generator is
reset when the
; WP pin is active low.
;
; Ready/Busy(R/B)
; The R/B output indicates the status of the device
operation. When low,
; it indicates that a program, erase or random read
operation is
; in process and returns to high state upon
completion. It is an open
; drain output and does not float to high-z condition
when the chip
; is deselected or when outputs are disabled.
;
;
;
***************************************************************************
; M O D I F I C A T I O N H I S T O R Y
;
;
; rev. date who why
; ---- ---------- ---
------------------------------------
; 0.01 2002.07.19 VFX Creation
; 1.10 2003.02.02 VFX Redesign all
functions
; 1.11 2003.05.05 VFX Remove IO pin and
change to XMEM mode
;
;
***************************************************************************
;Hardware
;
***************************************************************************
;*
;* SYSCLK: f=16.000 MHz (T= 62.5 ns)
;*
;
***************************************************************************
;
;
;
***************************************************************************
;* Const Def
;SmartMedia Commands
.EQU SM_ReadLowHalf =
0x00h ;Page read A
.EQU SM_ReadHiHalf = 0x01h
.EQU SM_ReadEnd =
0x50h ;Page read C
.EQU SM_ReadID =
0x90h ;Read ID
.EQU SM_ReadUnique =
0x91h ;Read Unique 128 bit
.EQU SM_Reset =
0xFFh ;Device reset
.EQU SM_PageProgram =
0x80h ;Ready to write, Serial Data Input
.EQU SM_PageProgramTrue =
0x10h ;Start to write page, auto program (Toshiba)
.EQU SM_PageProgramDumy =
0x11h ;
.EQU SM_PageProgramMultiBlk =
0x15h ;
.EQU SM_BlockErase =
0x60h ;Erase block (block#)
.EQU SM_BlockErase2nd =
0xD0h ;Erase block (start)
.EQU SM_ReadStatus =
0x70h ;Read status
.EQU SM_ReadMultiPlaneStatus =
0x71h ;
;SMIL Commands
;SM Manufacturer ID
.equ MakerSamsung = 0xEC
.equ MakerToshiba = 0x98
.equ SM_Protected =
7 ;bit = 1, media write protect
.equ SM_Busy =
6 ;bit = 1, media ready
.equ SM_Fail =
0 ;bit = 1, Fail
;SmFlags
.EQU SM_UniqueID = 7
.EQU SM_MultiplaneSupport = 6
.EQU SM_DeviceTooSmall =
5 ;Device < 16 MB
.EQU SM_DeviceUnkown =
4 ;Device Unknown
;
**************************************************************************
;* Hardware Def.
;
;
***************************************************************************
;**** VARIABLES
.DSEG
;end struct
;
***************************************************************************
.ESEG
;
***************************************************************************
;**** CODE SEG
;
***************************************************************************
.CSEG
Init_SMedia:
ldi R16, SMIL_Standby
sts ADR_SMMODE,R16 ;SmartMedia
Controller is StandBy
clr R16
sts SmManufacturerID,R16 ;No valid
Card in socket
sts SmDeviceCode,R16
sts SmFlags,R16
PrintSMType:
rcall SM_GetType ;Get
SmartMedia Type
lds R18,SmFlags
andi R18,(1<
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
srt1: st Z+,R21
sbiw XL,1
brne srt1 ;fill bank
inc R20
dec R18
brne SRT0
ldi R20,SRAMBASE
ldi R18,8
ldi R21,0x5A ;test byte
SRT2: sts ADR_EXHH,R20
ldi ZL,0
ldi ZH,192 ;Z point to
upper memory
ldi XL,low(16384)
ldi XH,high(16384) ;Count of
test byte
srt3: ld R3,Z+
cp R21,R3
brne SRAMERR
sbiw XL,1
brne srt3 ;check bank
inc R20
dec R18
brne srt2
clc
ret
SRAMERR: sec
ret
;******************************************************
; Convert Phisycal address to Logical Address
; In: R18:R17:R16 Phisycal address
; Out R18 - page,
; R17:R16 - offset address (must add MMAP1,2,3)
;
MmTranslatePhysicalAddress:
push R17
rol R17
rol R18
rol R17
rol R18
pop R17
andi R17,0b00111111
ret
;******************************************************
; Set Page at R18:R16
; In: R18:R17:R16 Phisycal address
; Out R18 - page+1,
; R17:R16 - offset address on MMAP2
; Z - mapped address on MMAP2
;
MmSetPage:
rcall MmTranslatePhysicalAddress
MmSetPageMap:
ori R17,high(MMAP2)
sts ADR_EXHL,R18
inc R18
sts ADR_EXHH,R18 ;2 page ->
no page border fault
movw ZL,R16 ;Z - offset
at first page
RET
;******************************************************
; Initialize Memory & setup MCBs
;
Mem_Init:
ldi R16,S1D_DISPLAY_HEIGHT
ldi R17,S1D_DISPLAY_SCANLINE_BYTES
mul R16,R17
inc R1 ;skip Video
RAM + 256 byte
clr R2
sts LargeMCB+0,R0
sts LargeMCB+1,R1
sts LargeMCB+2,R2 ;First MCB
movw R16,R0
mov R18,R2
rcall MmSetPage
movw R12,R16
mov R14,R18 ;delta
movw R8,R0
mov R10,R2 ;best pointer
rjmp MMVanMeg
MMTeljesenJo:
movw R8,R0
mov R10,R2 ;pointer
clr R12
clr R13
clr R14 ;delta=0
rjmp MMLastInChain
MMVanMeg:
ldd R16,Z+MCB_Type
sbrc R16,MCBLast
rjmp MMLastInChain
ldd R18,Z+MCB_LenH
ldd R17,Z+MCB_LenL+1
ldd R16,Z+MCB_LenL+0
add R16,R21
adc R17,R15
adc R18,R15
add R0,R16
adc R1,R17
adc R2,R18
rjmp MmNextMCB01
MMLastInChain:
mov R0,R8
or R0,R9
or R0,R10
brne mmMoreM00
rjmp mmNoMoreMemory
mmMoreM00:
;Memory block
Allocation/sharing
;Alloc = delta < 40
byte (32+8)
;share = delta =>
40 byte
ldi R16,40
clr R17
cp R12,R16
cpc R13,R17
cpc R14,R17
brsh MMShare
mmAllocAll:
movw R0,R8
mov R2,R10
movw R16,R8
mov R18,R10
rcall MmSetPage
mmMakeFree:
ldd R16,Z+MCB_Type
cbr R16,(1<
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
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
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
CRC 236 ;
XMODEM REC **************************************************************************
;*
UART 304 ;* PROGRAM START - EXECUTION STARTS HERE
UART 305 ;*
;
UART 128
**************************************************************************
UART BUFF
; .cseg
USB 232
AVR ISP .org $0000
ISP 2313 rjmp RESET ;Reset handle
ISP 1200
AVR SPI ;
***************************************************************************
I2C 300 ;*
I2C 302 ;* "crc_gen" - Generation and checking of CRC checksum
;*
I2C TWI26
;* This subroutine generates the checksum for the
I2C/TWI 128 program code.
I2C/TWI AT8 ;* 32 bits are loaded into 4 register, the upper 16
bits are XORed
DALLAS-1W ;* with the divisor value each time a 1 is shifted into
DALLAS CRC the carry flag
;* from the MSB.
ETHNET 8019 ;*
TEA ;* If the status byte is 0x00,the routine will generate
new checksum:
ADC 128 ;* After the computing the code 16 zeros are
ADC 10B ;* appended to the code and the checksum is calculated.
;*
ADC 400
;* If the status byte is different from 0X00, the
ADC 401 routine will check if the current checksum is valid.
THERM 232 ;* After the computing the code the original checksum
are
IRD 410 ;* appended to the code and calculated. The result is
LCD HD44 zero if no errors occurs
;* The result is placed in registers byte_2 and byte_3
LCD 2313 ;*
LCD44 2313 ;* Number of words :44 + return
;* Number of cycles :program memory size(word) * 175
KBD 240 (depending on memory contens)
MUX 242 ;* Low registers used :6 (byte_0,byte_1,byte_2,
byte_3)
KBD PS2
;* High registers used :7 (sizel,sizeh,crdivl,crdivh,
KBD PC/128 count,status,zl,zh)
PS2 EMU ;*
;
BOOT MG8 ***************************************************************************
BOOT DR8
;***** Subroutine Register Variables
ALM CLK
CLOCK 8564 .def byte_0 = r0 ; Lower byte of
lower word
90 DAYS
.def byte_1 = r1 ; Upper byte of
DELAYS lower word
.def byte_2 = r2 ; Lower byte of
CALL ID
upper word
DTMF 314 .def byte_3 = r3 ; Upper byte of
PWM 6CH upper word
.def crc = r4 ; CRC
PWM 10K checksum low byte
ENCODE .def crch = r5 ; CRC
checksum high byte
STH-11 .def sizel = r17 ; Program code size register
ATMEL CORP .def sizeh = r18
.def crdivl = r19 ; CRC divisor register
AVR
.def crdivh = r20
BUTTERFLY .def count = r21 ; Bit counter
AVR BOOK .def status = r22 ; Status byte: generate(0)
or check(1)
crc_gen:
ldi sizel,low(LAST_PROG_ADDR) ;Load last
program memory address
ldi sizeh,high(LAST_PROG_ADDR)
clr zl ;Clear Z pointer
clr zh
ldi crdivh,high(CR);Load divisor value
ldi crdivl,low(CR)
lpm ;Load first memory
location
mov byte_3,byte_0 ;Move to highest byte
adiw zl,0x01 ;Increment Z pointer
lpm ;Load second memory
location
mov byte_2,byte_0
next_byte:
cp zl,sizel ;Loop starts here
cpc zh,sizeh ;Check for end of
code
brge end ;Jump if end of code
adiw zl,0x01
lpm ;Load high byte
mov byte_1,byte_0 ;Move to upper byte
adiw zl,0x01 ;Increment Z pointer
lpm ;Load program
memory location
rcall rot_word ;Call the rotate routine
rjmp next_byte
end:
;ret ;uncomment this line if checksum is stored
in last flash memory address.
ldi count,0x11
cpi status,0x00
brne check
clr byte_0 ;Append 16 bits(0x0000) to
clr byte_1 ;the end of the code for
CRC generation
rjmp gen
check:
mov byte_0,crc ;Append the
original checksum to
mov byte_1,crch ;the end of the code for
CRC checking
gen:
rcall rot_word ;Call the rotate routine
mov crc,byte_2
mov crch,byte_3
ret ;Return to main prog
rot_word:
ldi count,0x11
rot_loop:
dec count ;Decrement bit counter
breq stop ;Break if bit
counter = 0
lsl byte_0 ;Shift zero into lowest bit
rol byte_1 ;Shift in carry from
previous byte
rol byte_2 ;Preceede shift
rol byte_3
brcc rot_loop ;Loop if MSB =
0
eor byte_2,crdivl
eor byte_3,crdivh ;XOR high word if MSB = 1
rjmp rot_loop
stop:
ret
;
***************************************************************************
;*
;* EERead_seq
;*
;* This routine reads the
;* EEPROM into the global register variable "temp".
;*
;* Number of words :4+ return
;* Number of cycles :8 + return
;* High Registers used :4 (temp,eeadr,eeadrh,
eedata)
;*
;
***************************************************************************
;***** Code
eeread:
out EEARH,eeadrh ;output address high byte
out EEARL,eeadr ;output address low byte
sbi EECR,EERE ;set EEPROM Read
strobe
in eedata,EEDR ;get data
ret
;
***************************************************************************
;*
;* EEWrite
;*
;* This subroutine waits until the EEPROM is ready to
be programmed, then
;* programs the EEPROM with register variable "EEdwr"
at address "EEawr"
;*
;* Number of words :7 + return
;* Number of cycles :13 + return (if EEPROM is ready)
;* Low Registers used :None
;* High Registers used: ;4 (temp,eeadr,eeadr,eedata)
;*
;
***************************************************************************
eewrite:
sbic EECR,EEWE ;If EEWE not clear
rjmp EEWrite ; Wait more
out EEARH,eeadrh ;Output address high byte
out EEARL,eeadr ;Output address low byte
out EEDR,eedata ;Output data
sbi EECR,EEMWE
sbi EECR,EEWE ;Set EEPROM Write
strobe
ret
;
************************************************************************
;*
;* Start Of Main Program
;*
.cseg
.def crc = r4 ;Low byte
of checksum to be returned
.def crch = r5 ;High byte
of checksum to be returned
.def temp = r16
.def status = r22 ;Status byte: generate(0)
or check(1)
.def eeadr = r23
.def eeadrh = r24
.def eedata = r25
RESET:
ldi r16,high(RAMEND) ;Initialize stack
pointer
out SPH,r16 ;High byte only
required if
ldi r16,low(RAMEND) ;RAM is bigger than 256
Bytes
out SPL,r16
ldi temp,0xff
out DDRB,temp ;Set PORTB as output
out PORTB,temp ;Write 0xFF to PORTB
clr status ;Clear status register,
prepare for CRC generation
rcall crc_gen
mainloop:
sbic EECR,EEWE ;If EEWE not clear
rjmp mainloop ; Wait more
loop:
out PORTB,crc ;Output CRC low value to
PORTB
rjmp loop
.exit
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
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
BOOT MG8 ;
BOOT DR8 ***************************************************************************
.ESEG
ALM CLK
CLOCK 8564
;
90 DAYS
***************************************************************************
DELAYS .CSEG
CALL ID
DTMF 314 ;
PWM 6CH ***************************************************************************
;** Init Xmodem File Receive
PWM 10K ;**
ENCODE
Init_Xmodem: ldi R16,128
STH-11 sts LastPocketSize,R16
ATMEL CORP clr R0
sts FileLength+0,R0
AVR
sts FileLength+1,R0
BUTTERFLY sts FileLength+2,R0
AVR BOOK sts FileLength+3,R0
sts Xm_ErrorCNT,R0
sts XmodemFlag,R0
sts Xm_BlkCounter,R0
Init_XmNextBl: clr R0
sts CRC+0,R0
sts CRC+1,R0
sts XmodemPTR,R0
STS SCNT2+0,R0
STS SCNT2+1,R0
ret
;
***************************************************************************
;** Calc & Update XMODEM CRC
;*
;* In: R0 - data byte
eor R17,R15
andi R17,0xF0
andi R16,0x0F
eor R15,R16
mov R14,R17
lsl R14
rol R16
lds R14,CRC+0
eor R15,R0
eor R17,R14
sts CRC+0,R15
sts CRC+1,R17
ret
;
***************************************************************************
;** XMODEM Receive File & Block
;*
;*
Xmodem_Rec: lds R16,XmodemFlag
cpi R16,Xmodem_Sync
breq Xm_Sync
cpi R16,Xmodem_Fill
brne Xmodem_Rec1
rjmp Xm_Fill
cpi R16,Xmodem_Err
breq Xm_Sync
rjmp Xmodem_Cancel
;mivel meg
mindig nem jott semmi kuldunk egy
;CRC -
karaktert 3 masodpercenkent
;End of
Trans == Canacel
Xmodem_EndOfT:
ldi R16,ACK
call SendChrW ;Pozitiv
nyugta
ldi R16,Low(Xm_ByteStr)
ldi R17,High(Xm_ByteStr)
call SendStrW
lds R17,XmodemMode
cpi R17,1
brne Xm_CancelEnd
;itt lesz
vege a FALSH update-nak
Xmodem_StartOfH:
ldi R16,Xmodem_Fill
sts XmodemFlag,R16
rcall Init_XmNextBl
ldi ZL,Low(SyncTiming) ;Timer=3sec
@100Hz
sts SCNT2+0,ZL ;he nem jon
ujjab byte, akkor baj van!!
ldi ZL,High(SyncTiming)
sts SCNT2+1,ZL
rjmp Xmodem_Rec
ldi R16,Xmodem_Err
sts XmodemFlag,R16 ;Time Out,
Ismetles kell
Xm_vanido: ret
Xm_data:
ldi ZL,Low(SyncTiming) ;Timer=3sec
@100Hz
sts SCNT2+0,ZL ;he nem jon
ujjab byte, akkor baj van!!
ldi ZL,High(SyncTiming)
sts SCNT2+1,ZL
ldi ZL,Low(XmodemBuf)
ldi ZH,High(XmodemBuf)
clr R1
lds R16,XmodemPTR
add ZL,R16
adc ZH,R1 ;ZL:ZH ->
Xmodem Actualis Pos.
st Z,R0 ;Char
eltarolasa
inc R16
sts XmodemPTR,R16
cpi R16,3 ;3
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
**************************************************************************
;*
;* PROGRAM START - EXECUTION STARTS HERE
;*
;
**************************************************************************
.cseg
.org $0000
rjmp start ;Reset handler
.org INT0addr
rjmp ext_int0 ;External interrupt
handler
.org OVF0addr
rjmp tim0_ovf ;Timer0 overflow
handler
.org ACIaddr
reti ;Analog comparator
handler (Not Used)
;
**************************************************************************
;*
;* EXT_INT0 - External Interrupt Routine 0
;*
;*
;* DESCRIPTION
;* This routine is executed when a negative edge on the
incoming serial
;* signal is detected. It disables further external
interrupts and enables
;* timer interrupts (bit-timer) because the UART must
now receive the
;* incoming data.
;*
;* This routine sets bits in the GIMSK, TIFR and TIMSK
registers. In this
;* code when the bits are set, it overwrites all other
bits. This is done
;* because of the lack of available cycles when it
operates at low clock
;* rate and high baudrates.
;*
;*
;* Total number of words : 12
;* Total number of cycles : 15 (incl. reti)
;* Low register usage : 1 (u_sr)
;* High register usage : 4 (u_bit_cnt,
u_tmp,u_status,u_reload)
;*
;
**************************************************************************
ext_int0:
in u_sr,SREG ;Store Status
Register
tim0_stopb:
sbi PORTD,PD4 ;Generate stop-bit
tim0_complete:
ldi u_tmp,1<' is sent back. The character is
also
;* presented on port B.
;*
;
**************************************************************************
;
**************************************************************************
;*
;* Test/Example program data.
;*
;* This is the data that will be sent back when a
character is recieved.
;*
;
**************************************************************************
.eseg
example_data:
.db 89 ;'Y'
.db 111 ;'o'
.db 117 ;'u'
.db 32 ;' '
.db 116 ;'t'
.db 121 ;'y'
.db 112 ;'p'
.db 101 ;'e'
.db 100 ;'d'
.db 32 ;' '
.db 13 ;
.db 10 ;
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
CRC 236 ;
XMODEM REC ***************************************************************************
;*
UART 304 ;* "putchar"
UART 305 ;*
;* This subroutine transmits the byte stored in the
UART 128
"Txbyte" register
UART BUFF ;* The number of stop bits used is set with the sb
constant
USB 232
;*
AVR ISP ;* Number of words :14 including return
ISP 2313 ;* Number of cycles :Depens on bit rate
;* Low registers used :None
ISP 1200 ;* High registers used :2 (bitcnt,Txbyte)
AVR SPI ;* Pointers used :None
;*
I2C 300 ;
I2C 302 ***************************************************************************
.equ sb =1 ;Number of
I2C TWI26
stop bits (1, 2, ...)
I2C/TWI 128
I2C/TWI AT8 putchar: ldi bitcnt,9+sb ;1+8+sb (sb is # of
stop bits)
DALLAS-1W com Txbyte ;Inverte everything
DALLAS CRC sec ;Start bit
getchar3: ret
;
***************************************************************************
;*
;* "UART_delay"
;*
;* This delay subroutine generates the required delay
between the bits when
;* transmitting and receiving bytes. The total
execution time is set by the
;* constant "b":
;*
;* 3·b + 7 cycles (including rcall and ret)
;*
;* Number of words :4 including return
;* Low registers used :None
;* High registers used :1 (temp)
;* Pointers used :None
;*
;
***************************************************************************
; Some b values: (See also table in Appnote
documentation)
;
; 1 MHz crystal:
; 9600 bps - b=14
; 19200 bps - b=5
; 28800 bps - b=2
;
; 2 MHz crystal:
; 19200 bps - b=14
; 28800 bps - b=8
; 57600 bps - b=2
; 4 MHz crystal:
; 19200 bps - b=31
; 28800 bps - b=19
; 57600 bps - b=8
; 115200 bps - b=2
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
BOOT MG8
BOOT DR8 ;
********************************************************************
ALM CLK ;
CLOCK 8564 ;ASCII Equivalents
;
90 DAYS
.equ NUL=0x00 ;Null
DELAYS .equ SOH=0x01 ;Start of Header
.equ STX=0x02 ;Start of Text
CALL ID
.equ ETX=0x03 ;End of Text
DTMF 314 .equ EOT=0x04 ;End of Transmission
PWM 6CH .equ ENQ=0x05 ;Enquiry
.equ ACK=0x06 ;Acknowlege
PWM 10K .equ BEL=0x07 ;Bell
ENCODE .equ BS=0x08 ;Backspace
.equ HT=0x09 ;Horizontal Tab
STH-11 .equ LF=0x0A ;Line Feed
ATMEL CORP .equ VT=0x0B ;Vertical Tab
.equ FF=0x0C ;Form Feed
AVR
.equ CR=0x0D ;Carriage Return
BUTTERFLY .equ SO=0x0E ;
AVR BOOK .equ SI=0x0F ;
.equ Rx_Buffer_Length = 24
.equ Tx_Buffer_Length = 32
;
***************************************************************************
.DSEG
Rx_Buffer:
Rx_Head: .byte 1
Rx_Tail: .byte 1
Rx_Data: .byte Rx_Buffer_Length
Tx_Buffer:
Tx_Head: .byte 1
Tx_Tail: .byte 1
Tx_Data: .byte Tx_Buffer_Length
;
*************************************************************************
;* Text Const
;*
.CSEG
;
************************************************************************
;** Init_UART1
;** Set up the inital states for the buffers, and make
sure the handshake
;** is turned on (Not the Shaddap state), so we can
talk.
;**
;**
;
************************************************************************
Init_UART1: ldi R16,0
sts Tx_Tail,R16
sts Tx_Head,R16
sts Rx_Tail,R16
sts Rx_Head,R16
sts UARTFlg,R16
sts CMD_Len,R16
sts CMD_Pos,R16
;Set up
Hardware HS I/O bits
sbi SER_HSO_DIR,SER_HSO ;Set as
output
HS_Enabled
ldi R16,High(SYSCLK/(16*BaudSpeed1)-1)
sts UBRR1H,R16
ldi R16,Low(SYSCLK/(16*BaudSpeed1)-1)
sts UBRR1L,R16 ;BaudRate
Gen.
;***********************************************
;* Megnezi, hogy kell-e ujrainditani a Tx muveletet
;
***************************************************************************
;
***************************************************************************
;
***************************************************************************
;** UART TX Functions
;
***************************************************************************
; kod Bufferbe
Osszesen
; 0x02 - send ROM TXT -> 0xE0, 0x02, low addr, hi
addr ; 4 byte
; 0xE0 - send 0xE0 -> 0xE0,
0xE0 ; 2 byte
;
************************************************************************
;** Calc Tx Buffer Free Space
; In: -
; Out: R18 - Tx_Tail
; R19 - Tx_Head
; R20 - Free Space in Tx Buffer
; Alt: R21
;
; Tail < Head -> Free= LEN+Tail-Head-1
; Tail = Head -> Free= LEN
; Tail > Head -> Free= Tail-Head-1
;
FreeInTxBuff: lds R19,Tx_Head
lds R18,Tx_Tail
ldi R20,Tx_Buffer_Length
mov R21,R18
sub R21,R19
breq FreeInTx1 ;T=H, Free=
Tx_Buffer_Length
brcs FreeInTx2
clr R20
FreeInTx2: add R20,R21
dec R20
FreeInTx1: ret
;************************************************
;* The RS232 Tx FIFO manager ROM TEXT *
;* In: (R16, R17) address word of text (L,
H) *
;* Out: c=1 hiba *
;************************************************
SendStr: rcall FreeInTxBuff ;R18,R19-t
is beallitja
cpi R20,4
brcs ExitwError ;ha <4
nincs eleg hely! Hiba!
cli
rcall StoreChar
ldi R16,SendROMTXT ;Buf
[Tx_head]=SendROMTXT indicate Send ROM TXT
rcall StoreChar
pop R16
rcall StoreChar ;Buf
[Tx_head]=RomTXT low address
sei
rcall TxRunning
;************************************************
;* The RS232 Tx FIFO manager Send CHAR *
;* in: R16 char *
;* out c=1 hiba *
;************************************************
SendChr: rcall FreeInTxBuff ;R18,R19-t
is beallitja
cpi R20,2
brcs ExitwError ;ha <1
nincs elg hely! Hiba!
cpi R16,0xE0 ;
Alternative kod?
brne only1char ;ha igen
akkor ketszer kell atkuldeni!!
rcall StoreChar
only1char: rcall StoreChar
sts Tx_Head,R19
rcall TxRunning
SendChrW: push ZL
push ZH
rcall SendChr
pop ZH
pop ZL
brcs SendChrW
ret
;***********************************************
; Subrutin for SendROMTXT & SendChar
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
exit_get_txfifo:
rjmp U_Tx4 ; (remove this for multi-
byte transmits)
;rjmp U_Tx1 ; (loop until all bytes
are sent -
; remove this for a one
byte transmit)
U_Tx3:
cbi UCSRB,UDRIE ; disable UDRE int to
avoid ADC lock-up if
; HW handshake is active
U_Tx4:
pop Tmp2
pop Tmp1
pop Flags_tmp
out SREG,Flags_tmp ; restore the status
register
pop Flags_tmp
U_Tx5:
reti
;
***************************************************************************
;*
;* "USART_Rx" interrupt handler
;*
;* Stores received bytes to fifo ring buffer
("Add_txfifo")
;* Checks for errors, skips byte if error
;*
;* All regs saved
;*
;
***************************************************************************
USART_RXC:
push Flags_tmp
in Flags_tmp,SREG ; flags may be changed
by arithmetics,
push Flags_tmp ; so save the
status register
push Tmp1
push Tmp3
U_R1:
in Tmp1,UCSRA ; get status
ldi Tmp3,0b00011100
and Tmp1,Tmp3 ; isolate bits 4-2
tst Tmp1 ; if not zero, we have
an error
breq U_R_cont ; no error
U_R_cont:
in Tmp1,UDR ; get data from UDR ...
add_rxfifo_HWoff:
cpi Tmp3,rxfifo_length ; check if
buffer full
breq full_rxfifo_n ; if so, deal
with that
add_rxfifo_cont:
sts save_Y,YL ; save Y reg
pair
sts save_Y + 1,YH
lds YL,rxfifo_in ; setup FIFO_in
lds YH,rxfifo_in + 1
st Y+,Tmp1 ; ** store data
from Tmp1 **
end_add_rxfifo:
sts rxfifo_in,YL ; store FIFO_in
sts rxfifo_in + 1,YH
lds YL,save_Y ; restore Y reg
pair
lds YH,save_Y + 1
exit_add_rxfifo:
rjmp U_R2 ; return (Exit
Add_rxfifo routine)
U_R2:
sbic UCSRA,RXC ; another byte pending
in fifo?
rjmp U_R1 ; yes, loop
U_R_exit:
pop Tmp3
pop Tmp1
pop Flags_tmp
out SREG,Flags_tmp ; restore the status
register
pop Flags_tmp
reti
;
***************************************************************************
;*
;* UART ring buffer functions
;*
;* ("Add_rxfifo": store a byte from IO_Source (UDR) to
buffer, -> ISR)
;* "Get_rxfifo": return 1 byte from rx ring buffer in
Tmp2
;*
;* "Add_txfifo": store a byte to transmit buffer
;* ("Get_txfifo": transmits the bytes stored in
transmit buffer -> ISR)
;*
;* "Init_rx/txbuf": initialize/clear fifo ring buffers
(RX / TX)
;*
;
***************************************************************************
;
**************************************************************************
get_rxfifo_cont:
tst Tmp1
breq exit_get_rxfifo
sts save_Y,YL
sts save_Y + 1,YH
lds YL,rxfifo_out
lds YH,rxfifo_out + 1
ld Tmp2,Y+ ; ** data_out to
Tmp2 **
dec Tmp1
sts rxfifo_n,Tmp1
brne rx_notclr
cbr B_Flags4,0x02 ; rx buffer
empty: clear "data pending" bit
rx_notclr:
ldi Tmp3,high(rxfifo_base + rxfifo_length)
cpi YL,low(rxfifo_base + rxfifo_length)
cpc YH,Tmp3
brne end_get_rxfifo
ldi YL,low(rxfifo_base)
ldi YH,high(rxfifo_base)
end_get_rxfifo:
sts rxfifo_out,YL
sts rxfifo_out + 1,YH
lds YL,save_Y
lds YH,save_Y + 1
exit_get_rxfifo:
pop Tmp3
pop Tmp1
ret ; EXIT function
;
**************************************************************************
;
**************************************************************************
add_txfifo_cont:
sbr B_Flags3,0x40 ; set TX data
pending flag
;sbi UCSRB,UDRIE ; (enable UDRE
int to start transmit!)
sts save_Y,YL ; save Y reg
pair
sts save_Y + 1,YH
lds YL,txfifo_in ; setup FIFO_in
lds YH,txfifo_in + 1
st Y+,Tmp2 ; ** store data
from Tmp2 **
inc Tmp3 ; inc FIFO_n
sts txfifo_n,Tmp3
end_add_txfifo:
sts txfifo_in,YL ; store FIFO_in
sts txfifo_in + 1,YH
lds YL,save_Y ; restore Y reg
pair
lds YH,save_Y + 1
exit_add_txfifo:
pop Tmp3
pop Tmp1
ret ; return
;
**************************************************************************
;
**************************************************************************
Init_rxbuf:
push YH
push YL
push Tmp1
; init rx buffer
clr YL
sts rxfifo_n,YL
ldi YL,low(rxfifo_base)
ldi YH,high(rxfifo_base)
sts rxfifo_in,YL
sts rxfifo_in + 1,YH
sts rxfifo_out,YL
sts rxfifo_out + 1,YH
pop Tmp1
pop YL
pop YH
ret
Init_txbuf:
push YH
push YL
push Tmp1
; init tx buffer
clr YL
sts txfifo_n,YL
ldi YL,low(txfifo_base)
ldi YH,high(txfifo_base)
sts txfifo_in,YL
sts txfifo_in + 1,YH
sts txfifo_out,YL
sts txfifo_out + 1,YH
pop Tmp1
pop YL
pop YH
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
AVR ISP ;.equ LEDPortLSB =PORTD ;pripojenie LED diod LSB ;ENG;
ISP 2313 connecting LED diode LSB
;.equ LEDPinLSB =PIND ;pripojenie LED diod LSB
ISP 1200 (vstup) ;ENG;connecting LED diode LSB (input)
AVR SPI ;.equ LEDdirectionLSB =DDRD ;vstup/vystup LED LSB ;ENG;input/
output LED LSB
I2C 300 ;.equ LEDPortMSB =PORTB ;pripojenie LED diod MSB ;ENG;
I2C 302 connecting LED diode MSB
;.equ LEDPinMSB =PINB ;pripojenie LED diod MSB
I2C TWI26
(vstup) ;ENG;connecting LED diode MSB (input)
I2C/TWI 128 ;.equ LEDdirectionMSB =DDRB ;vstup/vystup LED MSB ;ENG;input/
I2C/TWI AT8 output LED MSB
;.equ LEDlsb0 =3 ;LED0 na pin PD3 ;ENG;LED0 on
DALLAS-1W pin PD3
DALLAS CRC ;.equ LEDlsb1 =5 ;LED1 na pin PD5 ;ENG;LED1 on
pin PD5
ETHNET 8019 ;.equ LEDlsb2 =6 ;LED2 na pin PD6 ;ENG;LED2 on
TEA pin PD6
;.equ LEDmsb3 =3 ;LED3 na pin PB3 ;ENG;LED3 on
ADC 128 pin PB3
ADC 10B ;.equ LEDmsb4 =4 ;LED4 na pin PB4 ;ENG;LED4 on
pin PB4
ADC 400
;.equ LEDmsb5 =5 ;LED5 na pin PB5 ;ENG;LED5 on
ADC 401 pin PB5
THERM 232 ;.equ LEDmsb6 =6 ;LED6 na pin PB6 ;ENG;LED6 on
pin PB6
IRD 410 ;.equ LEDmsb7 =7 ;LED7 na pin PB7 ;ENG;LED7 on
LCD HD44 pin PB7
;databits ;ENG;databits
.equ DataBits5 =0
.equ DataBits6 =1
.equ DataBits7 =2
.equ DataBits8 =3
;parity ;ENG;parity
.equ ParityNone =0
.equ ParityOdd =1
.equ ParityEven =2
.equ ParityMark =3
.equ ParitySpace =4
;stopbits ;ENG;stopbits
.equ StopBit1 =0
.equ StopBit2 =1
;------------------------------------------------------------------------------------------
;********************************************************************
;* Interrupt table ;ENG;* Interrupt table
;********************************************************************
.cseg
;------------------------------------------------------------------------------------------
.org 0 ;po resete ;ENG;after reset
rjmp reset
;------------------------------------------------------------------------------------------
.org INT0addr ;externe prerusenie INT0 ;ENG;
external interrupt INT0
rjmp INT0handler
;------------------------------------------------------------------------------------------
.org URXCaddr ;prijem zo seriovej linky ;ENG;
receiving from serial line
push temp0
cbi UCR,RXCIE ;zakazat interrupt od prijimania
UART ;ENG;disable interrupt from UART receiving
sei ;povol interrupty na obsluhu
USB ;ENG;enable interrupts to service USB
in temp0,UDR ;nacitaj do temp0 prijate data z UART-
u ;ENG;put to temp0 received data from UART
in backupSREGTimer,SREG ;zaloha SREG ;ENG;backup SREG
push temp2
push temp3
lds temp2,RS232LengthPosPtr
lds temp3,RS232LengthPosPtr+1 ;zisti dlzku buffera RS232
kodu ;ENG;determine length of RS232 code buffer
cpi temp3,HIGH(RS232BufferEnd-RS232FIFOBegin-1) ;ci by mal pretiect
buffer ;ENG;if the buffer would overflow
brlo FIFOBufferNoOverflow ;ak nepretecie, tak zapis do
FIFO ;ENG;if not overflow then write to FIFO
brne NoIncRS232BufferFull ;ak by mal pretiect, tak
zabran prepisaniu ;ENG;if buffer would overflow, then prevent of overwriting
;inak (pri rovnosti) este
porovnaj Lo byty ;ENG;otherwise (if equall) still compare Lo bytes
cpi temp2,LOW(RS232BufferEnd-RS232FIFOBegin-1) ;ak by mal pretiect
buffer (Lo byte) ;ENG;if buffer would overflow (Lo byte)
brcc NoIncRS232BufferFull ;tak zabran prepisaniu ;ENG;
then prevent of overwriting
FIFOBufferNoOverflow:
push RS232BufptrX
push RS232BufptrXH
lds RS232BufptrX,RS232WritePosPtr ;nastavenie sa na zaciatok
buffera zapisu RS232 kodu ;ENG;set position to begin of buffer
write RS232 code
lds RS232BufptrXH,RS232WritePosPtr+1 ;nastavenie sa na zaciatok
buffera zapisu RS232 kodu ;ENG;set position to begin of
buffer write RS232 code
clr temp0 ;
out UBRRH,temp0 ;nastavit vysielaciu rychlost UART-u
High ;ENG;set UART speed High
out EEARH,temp0 ;znulovat EEPROM ukazovatel ;ENG;zero
EEPROM index
;********************************************************************
;* Main program ;ENG;* Main program
;********************************************************************
sei ;povolit interrupty globalne ;ENG;
enable interrupts globally
Main:
sbis inputport,DATAminus ;cakanie az sa zmeni D- na 0 ;ENG;waiting
till change D- to 0
rjmp CheckUSBReset ;a skontroluj, ci to nie je USB reset ;ENG;
and check, if isn't USB reset
cpi ActionFlag,DoReceiveSetupData
breq ProcReceiveSetupData
cpi ActionFlag,DoPrepareOutContinuousBuffer
breq ProcPrepareOutContinuousBuffer
rjmp Main
CheckUSBReset:
ldi temp0,255 ;pocitadlo trvania reset-u (podla normy je to
cca 10ms - tu je to cca 100us) ;ENG;counter duration of reset
(according to specification is that cca 10ms - here is cca 100us)
WaitForUSBReset:
sbic inputport,DATAminus ;cakanie az sa zmeni D+ na 0 ;ENG;waiting
till change D+ to 0
rjmp Main
dec temp0
brne WaitForUSBReset
rcall USBReset
rjmp Main
ProcPrepareOutContinuousBuffer:
rcall PrepareOutContinuousBuffer ;priprav pokracovanie odpovede do
buffera ;ENG;prepare next sequence of answer to buffer
ldi ActionFlag,DoReadySendAnswer
rjmp Main
ProcReceiveSetupData:
ldi USBBufptrY,InputBufferBegin ;pointer na zaciatok prijimacieho
buffera ;ENG;pointer to begin of receiving buffer
mov ByteCount,InputBufferLength ;dlzka vstupneho buffera ;ENG;
length of input buffer
rcall DecodeNRZI ;prevod kodovania NRZI na bity ;ENG;transfer
NRZI coding to bits
rcall MirrorInBufferBytes ;prehodit poradie bitov v bajtoch ;ENG;
invert bits order in bytes
rcall BitStuff ;odstranenie bit stuffing ;ENG;removal
of bitstuffing
;rcall CheckCRCIn ;kontrola CRC ;ENG;rcall
CheckCRCIn ;check CRC
rcall PrepareUSBOutAnswer ;pripravenie odpovede do vysielacieho
buffera ;ENG;prepare answers to transmitting buffer
ldi ActionFlag,DoReadySendAnswer
rjmp Main
;********************************************************************
;* Main program END ;ENG;* Main program END
;********************************************************************
;------------------------------------------------------------------------------------------
;********************************************************************
;* Interrupt0 interrupt handler ;ENG;* Interrupt0 interrupt handler
;********************************************************************
INT0Handler: ;prerusenie INT0 ;ENG;interrupt
INT0
in backupSREG,SREG
push temp0
push temp1
USBBeginPacket:
mov backupbitcount,bitcount ;zaloha bitcount registra ;ENG;backup
bitcount register
in shiftbuf,inputport ;ak ano nacitaj ho ako nulty bit priamo do
shift registra ;ENG;if yes load it as zero bit directly
to shift register
USBloopBegin:
push ByteCount ;dalsia zaloha registrov (setrenie
casu) ;ENG;additional backup of registers (save of time)
push USBBufptrY
ldi bitcount,6 ;inicializacia pocitadla bitov v bajte ;ENG;
initialization of bits counter in byte
ldi ByteCount,MAXUSBBYTES ;inicializacia max poctu prijatych bajtov v
pakete ;ENG;initialization of max number of received
bytes in packet
ldi USBBufptrY,InputShiftBufferBegin ;nastav vstupny buffera ;ENG;
set the input buffer
USBloop1_6:
in inputbuf,inputport
cbr inputbuf,USBpinmask ;odmaskovat spodne 2 bity ;ENG;unmask
low 2 bits
breq USBloopEnd ;ak su nulove - koniec USB packetu ;ENG;
if they are zeros - end of USB packet
ror inputbuf ;presun Data+ do shift registra ;ENG;transfer
Data+ to shift register
rol shiftbuf
dec bitcount ;zmensi pocitadlo bitov ;ENG;decrement bits
counter
brne USBloop1_6 ;ak nie je nulove - opakuj naplnanie shift
registra ;ENG;if it isn't zero - repeat filling of shift register
nop ;inak bude nutne skopirovat shift register bo
buffera ;ENG;otherwise is necessary copy shift register to buffer
USBloop7:
in inputbuf,inputport
cbr inputbuf,USBpinmask ;odmaskovat spodne 2 bity ;ENG;unmask
low 2 bits
breq USBloopEnd ;ak su nulove - koniec USB packetu ;ENG;
if they are zeros - end of USB packet
ror inputbuf ;presun Data+ do shift registra ;ENG;transfer
Data+ to shift register
rol shiftbuf
ldi bitcount,7 ;inicializacia pocitadla bitov v bajte ;ENG;
initialization of bits counter in byte
st Y+,shiftbuf ;skopiruj shift register bo buffera a zvys
pointer do buffera ;ENG;copy shift register into buffer and increment
pointer to buffer
USBloop0: ;a zacni prijimat dalsi bajt ;ENG;and start
receiving next byte
in shiftbuf,inputport ;nulty bit priamo do shift registra ;ENG;
zero bit directly to shift register
cbr shiftbuf,USBpinmask ;odmaskovat spodne 2 bity ;ENG;unmask
low 2 bits
breq USBloopEnd ;ak su nulove - koniec USB packetu ;ENG;
if they are zeros - end of USB packet
dec bitcount ;zmensi pocitadlo bitov ;ENG;decrement bits
counter
nop ;
dec ByteCount ;ak sa nedosiahol maximum buffera ;ENG;
if not reached maximum buffer
brne USBloop1_6 ;tak prijimaj dalej ;ENG;then receive next
USBloopEnd:
cpi USBBufptrY,InputShiftBufferBegin+3 ;ak sa neprijali aspon 3
byte ;ENG;if at least 3 byte not received
brcs EndInt0HandlerPOP ;tak skonci ;ENG;then finish
lds temp0,InputShiftBufferBegin+0 ;identifikator paketu do temp0 ;ENG;
identifier of packet to temp0
lds temp1,InputShiftBufferBegin+1 ;adresa do temp1 ;ENG;address
to temp1
brne TestDataPacket ;ak je dlzka ina ako 3 - tak to moze byt iba
DataPaket ;ENG;if is length different from 3 - then this
can be only DataPaket
TestIOPacket:
cp temp1,MyAddress ;ak to nie je urcene (adresa) pre mna ;ENG;
if this isn't assigned (address) for me
brne TestDataPacket ;tak to moze byt este Data Packet ;ENG;
then this can be still DataPacket
TestSetupPacket:;test na SETUP paket ;ENG;test to SETUP packet
cpi temp0,nNRZISETUPPID
brne TestOutPacket ;ak nie je Setup PID - dekoduj iny
paket ;ENG;if this isn't Setup PID - decode other packet
ldi State,SetupState
rjmp EndInt0HandlerPOP ;ak je Setup PID - prijimaj nasledny Data
paket ;ENG;if this is Setup PID - receive consecutive Data
packet
TestOutPacket: ;test na OUT paket ;ENG;test for OUT packet
cpi temp0,nNRZIOUTPID
brne TestInPacket ;ak nie je Out PID - dekoduj iny paket ;ENG;
if this isn't Out PID - decode other packet
ldi State,OutState
rjmp EndInt0HandlerPOP ;ak je Out PID - prijimaj nasledny Data
paket ;ENG;if this is Out PID - receive consecutive Data
packet
TestInPacket: ;test na IN paket ;ENG;test on IN packet
cpi temp0,nNRZIINPID
brne TestDataPacket ;ak nie je In PID - dekoduj iny paket ;ENG;
if this isn't In PID - decode other packet
rjmp AnswerToInRequest
TestDataPacket: ;test na DATA0 a DATA1 paket ;ENG;test for DATA0 and DATA1 packet
cpi temp0,nNRZIDATA0PID
breq Data0Packet ;ak nie je Data0 PID - dekoduj iny
paket ;ENG;if this isn't Data0 PID - decode other packet
cpi temp0,nNRZIDATA1PID
brne NoMyPacked ;ak nie je Data1 PID - dekoduj iny
paket ;ENG;if this isn't Data1 PID - decode other packet
Data0Packet:
cpi State,SetupState ;ak bol stav Setup ;ENG;if was state Setup
breq ReceiveSetupData ;prijmi ho ;ENG;receive it
cpi State,OutState ;ak bol stav Out ;ENG;if was state Out
breq ReceiveOutData ;prijmi ho ;ENG;receive it
NoMyPacked:
ldi State,BaseState ;znuluj stav ;ENG;zero state
rjmp EndInt0HandlerPOP ;a prijimaj nasledny Data paket ;ENG;and
receive consecutive Data packet
AnswerToInRequest:
push temp2 ;zazalohuj dalsie registre a pokracuj ;ENG;
backup next registers and continue
push temp3
push RS232BufptrX
push ACC
cpi ActionFlag,DoReadySendAnswer ;ak nie je pripravena odpoved ;ENG;
if isn't prepared answer
brne NoReadySend ;tak posli NAK ;ENG;then send NAK
rcall SendPreparedUSBAnswer ;poslanie odpovede naspat ;ENG;
transmitting answer back
and MyUpdatedAddress,MyUpdatedAddress ;ak je MyUpdatedAddress
nenulova ;ENG;if is MyUpdatedAddress nonzero
brne SetMyNewUSBAddress ;tak treba zmenit USB adresu ;ENG;then is
necessary to change USB address
ldi State,InState
ldi ActionFlag,DoPrepareOutContinuousBuffer
rjmp EndInt0Handler ;a opakuj - cakaj na dalsiu odozvu z
USB ;ENG;and repeat - wait for next response from USB
ReceiveSetupData:
push temp2 ;zazalohuj dalsie registre a pokracuj ;ENG;
backup next registers and continue
push temp3
push RS232BufptrX
push ACC
rcall SendACK ;akceptovanie Setup Data paketu ;ENG;accept
Setup Data packet
rcall FinishReceiving ;ukonci prijem ;ENG;finish receiving
ldi ActionFlag,DoReceiveSetupData
rjmp EndInt0Handler
ReceiveOutData:
push temp2 ;zazalohuj dalsie registre a pokracuj ;ENG;
backup next registers and continue
push temp3
push RS232BufptrX
push ACC
cpi ActionFlag,DoReceiveSetupData ;ak sa prave spracovava prikaz
Setup ;ENG;if is currently in process command Setup
breq NoReadySend ;tak posli NAK ;ENG;then send NAK
rcall SendACK ;akceptovanie Out paketu ;ENG;accept
Out packet
clr ActionFlag
rjmp EndInt0Handler
NoReadySend:
rcall SendNAK ;este nie som pripraveny s odpovedou ;ENG;
still I am not ready to answer
rjmp EndInt0Handler ;a opakuj - cakaj na dalsiu odozvu z
USB ;ENG;and repeat - wait for next response from USB
;------------------------------------------------------------------------------------------
SetMyNewUSBAddress: ;nastavi novu USB adresu v NRZI kodovani ;ENG;set new
USB address in NRZI coded
clr MyAddress ;vychodzi stav odpovede - mojej nNRZI USB
adresy ;ENG;original answer state - of my nNRZI USB address
ldi temp2,0b00000001 ;maska na xorovanie ;ENG;mask for xoring
ldi temp3,8 ;pocitadlo bitov ;ENG;bits counter
SetMyNewUSBAddressLoop:
mov temp0,MyAddress ;zapamatat si koncovu odpoved ;ENG;remember
final answer
ror MyUpdatedAddress ;do carry vysielany bit LSB (v smere naskor
LSB a potom MSB) ;ENG;to carry transmitting bit LSB (in
direction firstly LSB then MSB)
brcs NoXORBit ;ak je jedna - nemen stav ;ENG;if one -
don't change state
eor temp0,temp2 ;inak sa bude stav menit podla posledneho bitu
odpovede ;ENG;otherwise state will be changed according
to last bit of answer
NoXORBit:
ror temp0 ;posledny bit zmenenej odpovede do
carry ;ENG;last bit of changed answer to carry
rol MyAddress ;a z carry do koncovej odpovede na miesto LSB
(a sucasne prehodenie LSB a MSB poradia) ;ENG;and from carry
to final answer to the LSB place (and reverse LSB and MSB order)
dec temp3 ;zmensi pocitadlo bitov ;ENG;decrement bits
counter
brne SetMyNewUSBAddressLoop ;ak pocitadlo bitov nie je nulove opakuj
vysielanie s dalsim bitom ;ENG;if bits counter isn't
zero repeat transmitting with next bit
clr MyUpdatedAddress ;znulovanie adresy ako priznak jej buduceho
nemenenia ;ENG;zero addresses as flag of its next unchanging
rjmp EndInt0Handler
;------------------------------------------------------------------------------------------
FinishReceiving: ;korekcne akcie na ukoncenie prijmu ;ENG;corrective
actions for receive termination
cpi bitcount,7 ;prenes do buffera aj posledny necely
byte ;ENG;transfer to buffer also last not completed byte
breq NoRemainingBits ;ak boli vsetky byty prenesene, tak neprenasaj
nic ;ENG;if were all bytes transfered, then nothing
transfer
inc bitcount
ShiftRemainingBits:
rol shiftbuf ;posun ostavajuce necele bity na spravnu
poziciu ;ENG;shift remaining not completed bits on right position
dec bitcount
brne ShiftRemainingBits
st Y+,shiftbuf ;a skopiruj shift register bo buffera - necely
byte ;ENG;and copy shift register bo buffer - not completed
byte
NoRemainingBits:
mov ByteCount,USBBufptrY
subi ByteCount,InputShiftBufferBegin-1 ;v ByteCount je pocet
prijatych byte (vratane necelych byte) ;ENG;in ByteCount is
number of received bytes (including not completed bytes)
;********************************************************************
;* Other procedures ;ENG;* Other procedures
;********************************************************************
;------------------------------------------------------------------------------------------
USBReset: ;inicializacia USB stavoveho stroja ;ENG;initialization of USB
state engine
ldi temp0,nNRZIADDR0 ;inicializacia USB adresy ;ENG;
initialization of USB address
mov MyAddress,temp0
clr State ;inicializacia stavoveho stroja ;ENG;
initialization of state engine
clr BitStuffInOut
clr OutBitStuffNumber
clr ActionFlag
clr RAMread ;bude sa vycitavat z ROM-ky ;ENG;will be
reading from ROM
sts ConfigByte,RAMread ;nenakonfiguravany stav ;ENG;unconfigured state
ret
;------------------------------------------------------------------------------------------
SendPreparedUSBAnswer: ;poslanie kodovanim NRZI OUT buffera s dlzkou
OutputBufferLength do USB ;ENG;transmitting by NRZI coding
OUT buffer with length OutputBufferLength to USB
mov ByteCount,OutputBufferLength ;dlzka odpovede ;ENG;length of
answer
SendUSBAnswer: ;poslanie kodovanim NRZI OUT buffera do USB ;ENG;transmitting by
NRZI coding OUT buffer to USB
ldi USBBufptrY,OutputBufferBegin ;pointer na zaciatok
vysielacieho buffera ;ENG;pointer to begin of transmitting buffer
SendUSBBuffer: ;poslanie kodovanim NRZI dany buffer do USB ;ENG;transmitting by
NRZI coding given buffer to USB
ldi temp1,0 ;zvysovanie pointera (pomocna premenna) ;ENG;
incrementing pointer (temporary variable)
mov temp3,ByteCount ;pocitadlo bytov: temp3 = ByteCount ;ENG;
byte counter: temp3 = ByteCount
ldi temp2,0b00000011 ;maska na xorovanie ;ENG;mask for xoring
ld inputbuf,Y+ ;nacitanie prveho bytu do inputbuf a zvys
dec temp1 ;
mov lastBitstufNumber,temp1 ;zapamataj si poslednu poziciu
bitstuffingu ;ENG;remember last position of bitstuffing
cpi bitcount,1 ;aby sa ukazovalo na 7 bit (ktory sa ma
vymazat alebo kde sa ma vlozit nula) ;ENG;for pointing to 7-th bit
(which must be deleted or where to insert zero)
brne NoBitcountCorrect
ldi bitcount,9 ;
inc USBBufptrY ;zvys pointer do buffera ENG;increment
pointer to buffer
NoBitcountCorrect:
dec bitcount
bst BitStuffInOut,0
brts CorrectOutBuffer ;ak je Out buffer - zvys dlzku buffera ;ENG;
if this is Out buffer - increment buffer length
rcall ShiftDeleteBuffer ;posun In buffer ;ENG;shift In buffer
dec temp3 ;zniz pocitadlo vynechani ;ENG;decrement
counter of omission
rjmp CorrectBufferEnd
CorrectOutBuffer:
rcall ShiftInsertBuffer ;posun Out buffer ;ENG;shift Out buffer
inc temp3 ;zvys pocitadlo vynechani ;ENG;increment
counter of omission
CorrectBufferEnd:
pop ByteCount ;obnov dlzku buffera ;ENG;restore buffer
length
pop USBBufptrY ;obnov pointer do buffera ;ENG;restore
pointer to buffer
rjmp BitStuffRepeat ;a restartni od zaciatku ;ENG;and
restart from begin
NeposunBuffer:
dec temp1 ;ak uz boli vsetky bity ;ENG;if already were
all bits
breq EndBitStuff ;ukonci cyklus ;ENG;finish cycle
dec bitcount ;zniz pocitadlo bitov v byte ;ENG;decrement
bits counter in byte
brne BitStuffByteLoop ;ak este neboli vsetky bity v byte - chod na
dalsi bit ;ENG;if not yet been all bits in byte - go
to next bit
;inak nahraj dalsi byte ;ENG;otherwise load
next byte
inc USBBufptrY ;zvys pointer do buffera ;ENG;increment
pointer to buffer
rjmp BitStuffLoop ;a opakuj ;ENG;and repeat
EndBitStuff:
pop ByteCount ;obnov dlzku buffera ;ENG;restore buffer
length
pop USBBufptrY ;obnov pointer do buffera ;ENG;restore
pointer to buffer
bst BitStuffInOut,0
brts IncrementLength ;ak je Out buffer - zvys dlzku Out
buffera ;ENG;if this is Out buffer - increment length of Out buffer
DecrementLength: ;ak je In buffer - zniz dlzku In
buffera ;ENG;if this is In buffer - decrement length of In buffer
cpi temp3,0 ;bolo aspon jedno znizenie ;ENG;was at
least one decrement
breq NoChangeByteCount ;ak nie - nemen dlzku buffera ;ENG;if no -
don't change buffer length
dec ByteCount ;ak je In buffer - zniz dlzku buffera ;ENG;
if this is In buffer - decrement buffer length
subi temp3,256-8 ;ak nebolo viac ako 8 bitov naviac ;ENG;
if there wasn't above 8 bits over
brcc NoChangeByteCount ;tak skonci ;ENG;then finish
dec ByteCount ;inak este zniz dlzku buffera ;ENG;otherwise
next decrement buffer length
ret ;a skonci ;ENG;and finish
IncrementLength:
mov OutBitStuffNumber,temp3 ;zapamataj si pocet bitov naviac ;ENG;
remember number of bits over
subi temp3,8 ;ak nebolo viac ako 8 bitov naviac ;ENG;
if there wasn't above 8 bits over
brcs NoChangeByteCount ;tak skonci ;ENG;then finish
inc ByteCount ;inak zvys dlzku buffera ;ENG;otherwise
increment buffer length
mov OutBitStuffNumber,temp3 ;a zapamataj si pocet bitov naviac (znizene o
8) ;ENG;and remember number of bits over (decremented
by 8)
NoChangeByteCount:
ret ;skonci ;ENG;finish
;------------------------------------------------------------------------------------------
ShiftInsertBuffer: ;posuv buffer o jeden bit vpravo od konca az po poziciu: byte-
USBBufptrY a bit-bitcount ;ENG;shift buffer
by one bit to right from end till to position: byte-USBBufptrY and bit-bitcount
mov temp0,bitcount ;vypocet: bitcount= 9-bitcount ;ENG;
calculation: bitcount= 9-bitcount
ldi bitcount,9
sub bitcount,temp0 ;do bitcount poloha bitu, ktory treba
nulovat ;ENG;to bitcount bit position, which is necessary to clear
cpi temp1,1 ;
brne NoDoSetInfraBufferEmpty ;
rjmp DoSetInfraBufferEmpty ;restartne infra prijimanie (ak bolo
zastavene citanim z RAM-ky) ;ENG;restart infra receiving
(if it was stopped by reading from RAM)
NoDoSetInfraBufferEmpty:
cpi temp1,2 ;
brne NoDoGetInfraCode
rjmp DoGetInfraCode ;vysle prijaty infra kod (ak je v
bufferi) ;ENG;transmit received infra code (if it is in buffer)
NoDoGetInfraCode:
cpi temp1,3 ;
brne NoDoSetDataPortDirection
rjmp DoSetDataPortDirection ;nastavi smer toku datovych
bitov ;ENG;set flow direction of datal bits
NoDoSetDataPortDirection:
cpi temp1,4 ;
brne NoDoGetDataPortDirection
rjmp DoGetDataPortDirection ;zisti smer toku datovych bitov ;ENG;
detect of flow direction of data bits
NoDoGetDataPortDirection:
cpi temp1,5 ;
brne NoDoSetOutDataPort
rjmp DoSetOutDataPort ;nastavi datove bity (ak su vstupne,
tak ich pull-up) ;ENG;set data bits (if they are inputs, then
pull-ups)
NoDoSetOutDataPort:
cpi temp1,6 ;
brne NoDoGetOutDataPort
rjmp DoGetOutDataPort ;zisti nastavenie datovych out bitov
(ak su vstupne, tak ich pull-up) ;ENG;detect settings of data
out bits (if they are input, then pull-ups)
NoDoGetOutDataPort:
cpi temp1,7 ;
brne NoDoGetInDataPort
rjmp DoGetInDataPort ;vrati hodnotu datoveho vstupneho
portu ;ENG;return value of input data port
NoDoGetInDataPort:
cpi temp1,8 ;
brne NoDoEEPROMRead
rjmp DoEEPROMRead ;vrati obsah EEPROM od urcitej
adresy ;ENG;return contents of EEPROM from given address
NoDoEEPROMRead:
cpi temp1,9 ;
brne NoDoEEPROMWrite
rjmp DoEEPROMWrite ;zapise EEPROM na urcitu adresu urcite
data ;ENG;write to EEPROM to given address given data
NoDoEEPROMWrite:
cpi temp1,10 ;
brne NoDoRS232Send
rjmp DoRS232Send ;vysle byte na seriovy linku ;ENG;
transmit byte to serial line
NoDoRS232Send:
cpi temp1,11 ;
brne NoDoRS232Read
rjmp DoRS232Read ;vrati prijaty byte zo seriovej linky
(ak sa nejaky prijal) ;ENG;returns received byte from serial line
NoDoRS232Read:
cpi temp1,12 ;
brne NoDoSetRS232Baud
rjmp DoSetRS232Baud ;nastavi prenosovu rychlost seriovej
linky ;ENG;set line speed of of serial line
NoDoSetRS232Baud:
cpi temp1,13 ;
brne NoDoGetRS232Baud
rjmp DoGetRS232Baud ;vrati prenosovu rychlost seriovej
linky ;ENG;return line speed of serial line
NoDoGetRS232Baud:
cpi temp1,14 ;
brne NoDoGetRS232Buffer
rjmp DoGetRS232Buffer ;vrati prenosovu rychlost seriovej
linky ;ENG;return line speed of serial line
NoDoGetRS232Buffer:
cpi temp1,15 ;
brne NoDoSetRS232DataBits
rjmp DoSetRS232DataBits ;nastavi prenosovu rychlost seriovej
linky ;ENG;set line speed of serial line
NoDoSetRS232DataBits:
cpi temp1,16 ;
brne NoDoGetRS232DataBits
rjmp DoGetRS232DataBits ;vrati prenosovu rychlost seriovej
linky ;ENG;return line speed of serial line
NoDoGetRS232DataBits:
cpi temp1,17 ;
brne NoDoSetRS232Parity
rjmp DoSetRS232Parity ;nastavi prenosovu rychlost seriovej
linky ;ENG;set line speed of serial line
NoDoSetRS232Parity:
cpi temp1,18 ;
brne NoDoGetRS232Parity
rjmp DoGetRS232Parity ;vrati prenosovu rychlost seriovej
linky ;ENG;return line speed of serial line
NoDoGetRS232Parity:
cpi temp1,19 ;
brne NoDoSetRS232StopBits
rjmp DoSetRS232StopBits ;nastavi prenosovu rychlost seriovej
linky ;ENG;set line speed of serial line
NoDoSetRS232StopBits:
cpi temp1,20 ;
brne NoDoGetRS232StopBits
rjmp DoGetRS232StopBits ;vrati prenosovu rychlost seriovej
linky ;ENG;return line speed of serial line
NoDoGetRS232StopBits:
cpi temp1,USER_FNC_NUMBER+0 ;
brne NoDoUserFunction0
rjmp DoUserFunction0 ;vykona uzivatelsku rutinu0 ;ENG;
execute of user function0
NoDoUserFunction0:
cpi temp1,USER_FNC_NUMBER+1 ;
brne NoDoUserFunction1
rjmp DoUserFunction1 ;vykona uzivatelsku rutinu1 ;ENG;
execute of user function1
NoDoUserFunction1:
cpi temp1,USER_FNC_NUMBER+2 ;
brne NoDoUserFunction2
rjmp DoUserFunction2 ;vykona uzivatelsku rutinu2 ;ENG;
execute of user function1
NoDoUserFunction2:
DoUserFunctionX:
DoUserFunction0: ;send byte(s) of RAM starting at position given by first parameter in
function
lds temp0,InputBufferBegin+4 ;first parameter Lo into temp0
lds temp1,InputBufferBegin+5 ;first parameter Hi into temp1
;lds temp2,InputBufferBegin+6 ;second parameter Lo into temp2
;lds temp3,InputBufferBegin+7 ;second parameter Hi into temp3
;lds ACC,InputBufferBegin+8 ;number of requested bytes from USB
host (computer) into ACC
rcall GetUCSRCtotemp1
cbr temp1,~((1<<UPM0)|(1<<UPM1)) ;a nechaj nenulove iba paritne
bity ;ENG;and let nonzero only parity bits
cpi temp1,CLEAR_FEATURE ;
breq ComposeCLEAR_FEATURE ;
cpi temp1,SET_FEATURE ;
breq ComposeSET_FEATURE ;
cpi temp1,SET_DESCRIPTOR ;
breq ComposeSET_DESCRIPTOR ;
cpi temp1,GET_CONFIGURATION ;
breq ComposeGET_CONFIGURATION ;
cpi temp1,SET_CONFIGURATION ;
breq ComposeSET_CONFIGURATION ;
cpi temp1,GET_INTERFACE ;
breq ComposeGET_INTERFACE ;
cpi temp1,SET_INTERFACE ;
breq ComposeSET_INTERFACE ;
cpi temp1,SYNCH_FRAME ;
breq ComposeSYNCH_FRAME ;
;ak sa nenasla znama poziadavka ;ENG;
if not found known request
rjmp ZeroDATA1Answer ;ak to bolo nieco nezname, tak priprav
nulovu odpoved ;ENG;if that was something unknown, then prepare
zero answer
ComposeSET_ADDRESS:
lds MyUpdatedAddress,InputBufferBegin+4 ;nova adresa do
MyUpdatedAddress ;ENG;new address to MyUpdatedAddress
rjmp ZeroDATA1Answer ;posli nulovu odpoved ;ENG;send zero
answer
ComposeSET_CONFIGURATION:
lds temp0,InputBufferBegin+4 ;cislo konfiguracie do premennej
ConfigByte ;ENG;number of configuration to variable ConfigByte
sts ConfigByte,temp0 ;
ComposeCLEAR_FEATURE:
ComposeSET_FEATURE:
ComposeSET_INTERFACE:
ZeroStringAnswer:
rjmp ZeroDATA1Answer ;posli nulovu odpoved ;ENG;send zero
answer
ComposeGET_STATUS:
TwoZeroAnswer:
ldi temp0,2 ;pocet mojich bytovych odpovedi do
temp0 ;ENG;number of my bytes answers to temp0
ComposeGET_STATUS2:
ldi ZH, high(StatusAnswer<<1) ;ROMpointer na odpoved ;ENG;
ROMpointer to answer
ldi ZL, low(StatusAnswer<<1)
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
ComposeGET_CONFIGURATION:
lds temp0,ConfigByte
and temp0,temp0 ;ak som nenakonfigurovany ;ENG;
if I am unconfigured
breq OneZeroAnswer ;tak posli jednu nulu - inak posli
moju konfiguraciu ;ENG;then send single zero - otherwise send my
configuration
ldi temp0,1 ;pocet mojich bytovych odpovedi do
temp0 ;ENG;number of my bytes answers to temp0
ldi ZH, high(ConfigAnswerMinus1<<1) ;ROMpointer na odpoved ;ENG;
ROMpointer to answer
ldi ZL, low(ConfigAnswerMinus1<<1)+1
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
ComposeGET_INTERFACE:
ldi ZH, high(InterfaceAnswer<<1) ;ROMpointer na odpoved ;ENG;
ROMpointer to answer
ldi ZL, low(InterfaceAnswer<<1)
ldi temp0,1 ;pocet mojich bytovych odpovedi do
temp0 ;ENG;number of my bytes answers to temp0
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
ComposeSYNCH_FRAME:
ComposeSET_DESCRIPTOR:
rcall ComposeSTALL
ret
ComposeGET_DESCRIPTOR:
lds temp1,InputBufferBegin+5 ;DescriptorType do temp1 ;ENG;
DescriptorType to temp1
cpi temp1,DEVICE ;DeviceDescriptor ;ENG;
DeviceDescriptor
breq ComposeDeviceDescriptor ;
cpi temp1,CONFIGURATION ;ConfigurationDescriptor ;ENG;
ConfigurationDescriptor
breq ComposeConfigDescriptor ;
cpi temp1,STRING ;StringDeviceDescriptor ;ENG;
StringDeviceDescriptor
breq ComposeStringDescriptor ;
ret
ComposeDeviceDescriptor:
ldi ZH, high(DeviceDescriptor<<1) ;ROMpointer na descriptor ;ENG;
ROMpointer to descriptor
ldi ZL, low(DeviceDescriptor<<1)
ldi temp0,0x12 ;pocet mojich bytovych odpovedi do
temp0 ;ENG;number of my bytes answers to temp0
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
ComposeConfigDescriptor:
ldi ZH, high(ConfigDescriptor<<1) ;ROMpointer na descriptor ;ENG;
ROMpointer to descriptor
ldi ZL, low(ConfigDescriptor<<1)
ldi temp0,9+9+7 ;pocet mojich bytovych odpovedi do
temp0 ;ENG;number of my bytes answers to temp0
ComposeEndXXXDescriptor:
lds TotalBytesToSend,InputBufferBegin+8 ;pocet pozadovanych bytov do
TotalBytesToSend ;ENG;number of requested bytes to
TotalBytesToSend
cp TotalBytesToSend,temp0 ;ak sa neziada viac ako mozem
dodat ;ENG;if not requested more than I can send
brcs HostConfigLength ;vysli tolko kolko sa ziada ;ENG;
transmit the requested number
mov TotalBytesToSend,temp0 ;inak posli pocet mojich
odpovedi ;ENG;otherwise send number of my answers
HostConfigLength:
mov temp0,TotalBytesToSend ;
clr TransmitPart ;nuluj pocet 8 bytovych
odpovedi ;ENG;zero the number of 8 bytes answers
andi temp0,0b00000111 ;ak je dlzka delitelna 8-mimi ;ENG;
if is length divisible by 8
breq Length8Multiply ;tak nezapocitaj jednu necelu odpoved
(pod 8 bytov) ;ENG;then not count one answer (under 8 byte)
inc TransmitPart ;inak ju zapocitaj ;ENG;otherwise
count it
Length8Multiply:
mov temp0,TotalBytesToSend ;
lsr temp0 ;dlzka 8 bytovych odpovedi sa
dosiahne ;ENG;length of 8 bytes answers will reach
lsr temp0 ;delenie celociselne 8-mimi ;ENG;
integer division by 8
lsr temp0
add TransmitPart,temp0 ;a pripocitanim k poslednej necelej 8-
mici do premennej TransmitPart ;ENG;and by addition to last
non entire 8-bytes to variable TransmitPart
ldi temp0,DATA0PID ;DATA0 PID - v skutocnosti sa
stoggluje na DATA1PID v nahrati deskriptora ;ENG;DATA0 PID - in the next
will be toggled to DATA1PID in load descriptor
sts OutputBufferBegin+1,temp0 ;nahraj do vyst buffera ;ENG;store to
output buffer
rjmp ComposeNextAnswerPart
ComposeStringDescriptor:
ldi temp1,4+8 ;ak RAMread=4(vkladaj nuly z ROM-
koveho citania) + 8(za prvy byte nevkldadaj nulu) ;ENG;if RAMread=4(insert
zeros from ROM reading) + 8(behind first byte no load zero)
mov RAMread,temp1
lds temp1,InputBufferBegin+4 ;DescriptorIndex do temp1 ;ENG;
DescriptorIndex to temp1
cpi temp1,0 ;LANGID String ;ENG;LANGID String
breq ComposeLangIDString ;
cpi temp1,2 ;DevNameString ;ENG;DevNameString
breq ComposeDevNameString ;
brcc ZeroStringAnswer ;ak je DescriptorIndex vyssi nez 2 -
posli nulovu odpoved ;ENG;if is DescriptorIndex higher than
2 - send zero answer
;inak to bude VendorString ;ENG;
otherwise is VendorString
ComposeVendorString:
ldi ZH, high(VendorStringDescriptor<<1) ;ROMpointer na
descriptor ;ENG;ROMpointer to descriptor
ldi ZL, low(VendorStringDescriptor<<1)
ldi temp0,(VendorStringDescriptorEnd-VendorStringDescriptor)*4-2 ;pocet
mojich bytovych odpovedi do temp0 ;ENG;number of
my bytes answers to temp0
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
ComposeDevNameString:
ldi ZH, high(DevNameStringDescriptor<<1) ;ROMpointer na
descriptor ;ENG;ROMpointer to descriptor
ldi ZL, low(DevNameStringDescriptor<<1)
ldi temp0,(DevNameStringDescriptorEnd-DevNameStringDescriptor)*4-2 ;pocet
mojich bytovych odpovedi do temp0 ;ENG;number
of my bytes answers to temp0
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
ComposeLangIDString:
clr RAMread
ldi ZH, high(LangIDStringDescriptor<<1) ;ROMpointer na
descriptor ;ENG;ROMpointer to descriptor
ldi ZL, low(LangIDStringDescriptor<<1)
ldi temp0,(LangIDStringDescriptorEnd-LangIDStringDescriptor)*2;pocet
mojich bytovych odpovedi do temp0 ;ENG;number of my
bytes answers to temp0
rjmp ComposeEndXXXDescriptor ;a dokonci ;ENG;and complete
;------------------------------------------------------------------------------------------
ZeroDATA1Answer:
rcall ComposeZeroDATA1PIDAnswer
ret
;----------------------------- END positionARD USB REQUESTS
------------------------------------- END DATA ENCRYPTION USB
REQUESTS ------------------------------
PrepareOutContinuousBuffer:
rcall PrepareContinuousBuffer
rcall MakeOutBitStuff
ret
;------------------------------------------------------------------------------------------
PrepareContinuousBuffer:
mov temp0,TransmitPart
cpi temp0,1
brne NextAnswerInBuffer ;ak uz je buffer prazdny ;ENG;
if buffer empty
rcall ComposeZeroAnswer ;priprav nulovu odpoved ;ENG;prepare
zero answer
ret
NextAnswerInBuffer:
dec TransmitPart ;znizit celkovu dlzku odpovede ;ENG;
decrement general length of answer
ComposeNextAnswerPart:
mov temp1,TotalBytesToSend ;zniz pocet bytov na vyslanie ;ENG;decrement
number of bytes to transmit
subi temp1,8 ;ci je este treba poslat viac ako 8
bytov ;ENG;is is necessary to send more as 8 byte
ldi temp3,8 ;ak ano - posli iba 8 bytov ;ENG;if yes -
send only 8 byte
brcc Nad8Bytov
mov temp3,TotalBytesToSend ;inak posli iba dany pocet bytov ;ENG;
otherwise send only given number of bytes
clr TransmitPart
inc TransmitPart ;a bude to posledna odpoved ;ENG;and this
will be last answer
Nad8Bytov:
mov TotalBytesToSend,temp1 ;znizeny pocet bytov do
TotalBytesToSend ;ENG;decremented number of bytes to TotalBytesToSend
rcall LoadXXXDescriptor
ldi ByteCount,2 ;dlzka vystupneho buffera (iba SOP a
PID) ;ENG;length of output buffer (only SOP and PID)
add ByteCount,temp3 ;+ pocet bytov ;ENG;+ number of bytes
rcall AddCRCOut ;pridanie CRC do buffera ;ENG;addition
of CRC to buffer
inc ByteCount ;dlzka vystupneho buffera + CRC16 ;ENG;
length of output buffer + CRC16
inc ByteCount
ret ;skonci ;ENG;finish
;------------------------------------------------------------------------------------------
.equ USBversion =0x0100 ;pre aku verziu USB je to
(1.00) ;ENG;for what version USB is that (1.00)
.equ VendorUSBID =0x03EB ;identifikator dodavatela
(Atmel=0x03EB) ;ENG; vendor identifier (Atmel=0x03EB)
.equ DeviceUSBID =0x0004 ;identifikator vyrobku (USB to RS232
converter ATmega8=0x0004) ;ENG;product identifier (USB to
RS232 converter ATmega8=0x0004)
.equ DeviceVersion =0x0003 ;cislo verzie vyrobku
(verzia=0.03) ;ENG;version number of product (version=0.03)
;(0.01=AT90S2313 Infra buffer) ;ENG;
(0.01=AT90S2313 Infra buffer)
;(0.02=AT90S2313 RS232 buffer 32bytes) ;ENG;
(0.02=AT90S2313 RS232 buffer 32bytes)
;(0.03=ATmega8 RS232 buffer 800bytes) ;ENG;
(0.03=ATmega8 RS232 buffer 800bytes)
.equ MaxUSBCurrent =50 ;prudovy odber z USB (50mA) - rezerva
na MAX232 ;ENG;current consumption from USB (50mA) - together
with MAX232
;------------------------------------------------------------------------------------------
DeviceDescriptor:
.db 0x12,0x01 ;0 byte - velkost deskriptora v bytoch ;ENG;0
byte - size of descriptor in byte
;1 byte - typ deskriptora: Deskriptor
zariadenia ;ENG;1 byte - descriptor type: Device descriptor
.dw USBversion ;2,3 byte - verzia USB LSB (1.00) ;
ENG;2,3 byte - version USB LSB (1.00)
.db 0x00,0x00 ;4 byte - trieda zariadenia ;ENG;4 byte -
device class
;5 byte - podtrieda zariadenia ;ENG;5 byte -
subclass
.db 0x00,0x08 ;6 byte - kod protokolu ;ENG;6 byte - protocol
code
;7 byte - velkost FIFO v bytoch ;ENG;7 byte -
FIFO size in bytes
.dw VendorUSBID ;8,9 byte - identifikator dodavatela
(Cypress=0x04B4) ;ENG;8,9 byte - vendor identifier (Cypress=0x04B4)
.dw DeviceUSBID ;10,11 byte - identifikator vyrobku
(teplomer=0x0002) ;ENG;10,11 byte - product identifier (teplomer=0x0002)
.dw DeviceVersion ;12,13 byte - cislo verzie vyrobku
(verzia=0.01) ;ENG;12,13 byte - product version number (verzia=0.01)
.db 0x01,0x02 ;14 byte - index stringu "vyrobca" ;
ENG;14 byte - index of string "vendor"
;15 byte - index stringu "vyrobok" ;
ENG;15 byte - index of string "product"
.db 0x00,0x01 ;16 byte - index stringu "seriove
cislo" ;ENG;16 byte - index of string "serial number"
;17 byte - pocet moznych konfiguracii ;
ENG;17 byte - number of possible configurations
DeviceDescriptorEnd:
;------------------------------------------------------------------------------------------
ConfigDescriptor:
.db 0x9,0x02 ;dlzka,typ deskriptoru ;ENG;length,
descriptor type
ConfigDescriptorLength:
.dw 9+9+7 ;celkova dlzka vsetkych deskriptorov ;ENG;
entire length of all descriptors
ConfigAnswerMinus1: ;pre poslanie cisla congiguration number
(pozor je treba este pricitat 1) ;ENG;for sending the number
- congiguration number (attention - addition of 1 required)
.db 1,1 ;numInterfaces,congiguration number ;ENG;
numInterfaces, congiguration number
.db 0,0x80 ;popisny index stringu, atributy;bus
powered ;ENG;string index, attributes; bus powered
.db MaxUSBCurrent/2,0x09 ;prudovy odber, interface descriptor
length ;ENG;current consumption, interface descriptor length
.db 0x04,0 ;interface descriptor; cislo interface ;ENG;
interface descriptor; number of interface
InterfaceAnswer: ;pre poslanie cisla alternativneho
interface ;ENG;for sending number of alternatively interface
.db 0,1 ;alternativne nastavenie interface; pocet
koncovych bodov okrem EP0 ;ENG;alternatively interface; number of endpoints
except EP0
StatusAnswer: ;2 nulove odpovede (na usetrenie
miestom) ;ENG;2 zero answers (saving ROM place)
.db 0,0 ;trieda rozhrania; podtrieda rozhrania ;ENG;
interface class; interface subclass
.db 0,0 ;kod protokolu; index popisneho stringu ;ENG;
protocol code; string index
.db 0x07,0x5 ;dlzka,typ deskriptoru - endpoint ;ENG;
length, descriptor type - endpoint
.db 0x81,0 ;endpoint address; transfer type ;ENG;
endpoint address; transfer type
.dw 0x08 ;max packet size ;ENG;max packet size
.db 10,0 ;polling interval [ms]; dummy byte (pre
vyplnenie) ;ENG;polling interval [ms]; dummy byte (for filling)
ConfigDescriptorEnd:
;------------------------------------------------------------------------------------------
LangIDStringDescriptor:
.db (LangIDStringDescriptorEnd-LangIDStringDescriptor)*2,3 ;dlzka, typ:
string deskriptor ;ENG;length, type: string descriptor
.dw 0x0409 ;English ;ENG;English
LangIDStringDescriptorEnd:
;------------------------------------------------------------------------------------------
VendorStringDescriptor:
.db (VendorStringDescriptorEnd-VendorStringDescriptor)*4-2,3 ;
dlzka, typ: string deskriptor ;ENG;length, type: string descriptor
CopyRight:
.db "Ing. Igor Cesko, Copyright(c) 2003"
CopyRightEnd:
VendorStringDescriptorEnd:
;------------------------------------------------------------------------------------------
DevNameStringDescriptor:
.db (DevNameStringDescriptorEnd-DevNameStringDescriptor)*4-2,3;dlzka, typ:
string deskriptor ;ENG;length, type: string descriptor
.db "Igor Atmel-AVR device: Advanced USB to RS232 converter + I/O pins
control + EEPROM scratch pad"
DevNameStringDescriptorEnd:
;------------------------------------------------------------------------------------------
;********************************************************************
;* End of Program ;ENG;* End of program
;********************************************************************
;------------------------------------------------------------------------------------------
;********************************************************************
;* EEPROM contents ;ENG;* EEPROM contents
;********************************************************************
;------------------------------------------------------------------------------------------
.eseg ;data v EEPROM-ke (vo finalnej verzii zapoznamkovat) ;ENG;data in
EEPROM (at final version comment)
;.org 0x400 ;pre naplnenie EEPROM dat na spravne adresy - hned za kod programu (vo
finalnej verzii odpoznamkovat) ;ENG;.org 0x400 ;for
filling EEPROM give on right addresses - behind the program code (at final version
uncomment)
EEData:
.db "This device was developed by Ing. Igor Cesko: [email protected] "
.db "For more information see: http://www.cesko.host.sk. "
.db "S/N:00000001"
;------------------------------------------------------------------------------------------
;********************************************************************
;* End of file ;ENG;* End of file
;********************************************************************
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
.include "1200def.inc"
;
***************************************************************************
;*
;* CONSTANTS
;* device codes
;*
;* DESCRIPTION
;* The following device codes must be used by the host
computer. Note
;* that the device codes are arbitrary selected, they
do not have any
;* thing in common with the signature bytes stored in
the device.
;*
;* The following devices are supported (make a new
table for each
;* software release):
;*
;* SW_MAJOR=1, SW_MINOR=5
;* AT90S1200 rev. C (abbreviated S1200C)
;* AT90S1200 rev. D (abbreviated S1200D)
;* AT90S8515 rev. A (abbreviated S8515A)
;* AT89S8252 (abbreviated S8252)
;*
;* SW_MAJOR=1, SW_MINOR=6
;* AT90S1200 rev. C (abbreviated S1200C)
;* AT90S1200 rev. D (abbreviated S1200D)
;* AT90S8515 rev. A (abbreviated S8515A)
;* AT89S8252 (abbreviated S8252)
;* ATmega103 rev. A (abbreviated S01838A)
;*
;
***************************************************************************
;
***************************************************************************
;*
;* MACROS
;* Program Macros
;*
;* DESCRIPTION
;* Change the following four macros if the RESET pin
to the
;* target moves and/or if the SCK/MISO/MOSO moves.
;*
;
***************************************************************************
.macro set_reset
sbi portb,4
.endm
.macro clr_reset
cbi portb,4
.endm
.macro ddrd_init
nop
; sbi ddrd,3
.endm
.macro ddrb_init
ldi temp1,0xdf
out ddrb,temp1 ; PB5 is input, the rest is
output
.endm
.macro ddrb_release
ldi temp1,(1<= 0x20) && (device <= 0x7F) )
brlo s2
tst device
brmi s2
s0b: ; {
ldi count,32 ; count = 32;
s1: ; do {
rcall rdser ; if (rdser
== 0x53) // SPI read (byte 3)
cpi s_data,0x53
breq s3 ;
break;
ldi s_data,0x00 ; wrser
(0x00); // SPI write (byte 4)
rcall wrser
pulse_sck ; pulse SCK
ldi s_data,0xac ; wrser
(0xac); // SPI write (byte 1)
rcall wrser
ldi s_data,0x53 ; wrser
(0x53); // SPI write (byte 2)
rcall wrser
dec count ; } while(--count);
brne s1
rjmp s3 ; }
; else
s2: ; {
ldi s_data,0x00 ; wrser
(0x00); // SPI write (byte 3)
rcall wrser
s3: ; }
cpi device,S8252 ; if (device != S8252)
breq s4 ; {
ldi s_data,0x00 ; wrser(0x00); //
SPI write (byte 4)
rcall wrser
s4: ; }
ldi temp1,0x10 ; delay(0x10);
rcall delay
ret
;
***************************************************************************
;*
;* FUNCTION
;* show_id
;*
;* DESCRIPTION
;* Show our ID ("AVR ISP") on the serial line.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* RESET
;*
;* DESCRIPTION
;* Initialization
;*
;
***************************************************************************
;
***************************************************************************
;*
;* PROGRAM
;* waitcmd -> main
;*
;* DESCRIPTION
;* Wait for and execute commands.
;*
;
***************************************************************************
w7:
cpi device,S1200C ; if ((device != S1200C) &&
breq w72
cpi device,S1200D ; (device != S1200D) &&
breq w72
cpi device,S8515A ; (device != S8515A) &&
breq w72
cpi device,S4414A ; (device != S4414A) &&
breq w72
cpi device,S2313A ; (device != S2313A) &&
breq w72
cpi device,S8252 ; (device != S8252) &&
breq w72
cpi device,S01838C ; (device != S01838C) &&
breq w72
cpi device,S01838D ; (device != S01838D) &&
breq w72
cpi device,S2323A ; (device != S2323A))
breq w72
rjmp put_err ; goto put_err();
;* USAGE
;* wait_pm(byte cmd, byte c_data);
;*
;* cmd : 0x28 - wait for high byte written
;* 0x20 - wait for low byte written
;* u_data : current data written
;wait_pm: ; do
; ; {
; mov s_data,cmd ; wrser
(cmd); // SPI write (byte 1)
; rcall wrser
; mov s_data,addrh ; wrser
(addrh); // SPI write (byte 2)
; rcall wrser
; mov s_data,addrl ; wrser
(addrl); // SPI write (byte 3)
; rcall wrser
; rcall rdser ; s_data = rdser
(); // SPI read (byte 4)
; }
; cp s_data,u_data ; while(s_data != u_data);
; brne wait_pm
; ret
ldi s_data,0xc0
rcall wrser
mov s_data,addrh
rjmp w111
w17call:ldi s_data,0x30
rcall wrser
ldi s_data,0x00
rcall wrser
mov s_data,param1
rcall wrser
rcall rdser
mov u_data,s_data
rcall putc
ret
rcall getc
mov cmd1,u_data
rcall getc
mov cmd2,u_data
rcall getc
mov cmd3,u_data
rcall universal
ldi temp1,0xff ; delay(0xFF); //
0x20 = 24585 cycles delay
rcall delay
rjmp put_ret
universal:
mov s_data,cmd1
rcall wrser
mov s_data,cmd2
rcall wrser
mov s_data,cmd3
rcall wrser
rcall rdser
mov u_data,s_data
rcall putc
ret
w99:
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
***************************************************************************
.include "2313def.inc"
;
***************************************************************************
;*
;* CONSTANTES
;*
;
***************************************************************************
;
***************************************************************************
;*
;* PORTS
;* Ports Definitions
;*
;* DESCRIPTION
;* Change the following definitions if the RESET pin
to the
;* target moves and/or if the SCK/MISO/MISO/LED moves.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* MACROS
;* Program Macros
;*
;* DESCRIPTION
;* Change the following macros if the RESET pin to the
;* target moves and/or if the SCK/MISO/MISO/LED moves.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* Global Register Variables
;*
;
***************************************************************************
;
***************************************************************************
;*
;* Interrupt Vectors
;*
;
***************************************************************************
.CSEG
rjmp INIT ; Reset Handle
;
***************************************************************************
;*
;* FUNCTION
;* u_init
;*
;* DESCRIPTION
;* Initialize UART.
;*
;
***************************************************************************
u_init:
ldi temp1,N ; set baud
rate
out UBRR,temp1
ldi temp1,(1<<TXEN)|(1<<RXEN) ;
initialize UART for TX and RX
out UCR,temp1
ret
;
***************************************************************************
;*
;* FUNCTION
;* getc
;*
;* DESCRIPTION
;* Wait for start bit and receive a character on the
UART Rx line.
;*
;
***************************************************************************
getc:
sbis USR,RXC ; wait until a
character has been received
rjmp getc
in u_data,UDR ; Read byte
from the UART
ret
;
***************************************************************************
;*
;* FUNCTION
;* putc
;*
;* DESCRIPTION
;* Send a character on the UART Tx line.
;*
;
***************************************************************************
putc:
sbis USR,UDRE ; test for TX
register empty
rjmp putc ; loop until TX
empty
out UDR,u_data ; send the
byte
ret
;
***************************************************************************
;*
;* FUNCTION
;* put_string
;*
;* DESCRIPTION
;* Send Z - pointed null-terminated string on the UART
Tx line.
;*
;
***************************************************************************
put_string:
lpm
tst r0
breq ps_ret ; check for end of
string (0x00)
mov u_data,r0
rcall putc ; putc(char)
adiw ZL,1 ; next char
rjmp put_string
ps_ret: ret
;
***************************************************************************
;*
;* FUNCTION
;* put_table
;*
;* DESCRIPTION
;* Send Z - pointed table on the UART Tx line.
;*
;
***************************************************************************
put_table:
lpm
tst r0
breq pt_ret ; check for end of
table (0x00)
mov u_data,r0
rcall putc ; putc(Byte)
adiw ZL,2 ; skip MSB
rjmp put_table
pt_ret: ret
;
***************************************************************************
;*
;* FUNCTION
;* bel_table
;*
;* DESCRIPTION
;* C=0 if device belongs to table.
;*
;
***************************************************************************
bel_table:
lpm ;
read table
tst r0 ;
check for end of table
breq c1_ret
cp device,r0
breq c0_ret ; C=0
adiw ZL,2 ; skip MSB
rjmp bel_table
c1_ret: sec ;
C=1
c0_ret: ret
;
***************************************************************************
;*
;* FUNCTION
;* set_pagesize
;*
;* DESCRIPTION
;* sets programming Page size for selected Device.
;*
;
***************************************************************************
set_pagesize:
lpm ; read table
tst r0 ; check for end of
table
breq spa_end ; no Pagesize to set
cp device,r0
breq spa_set ; C=0
adiw ZL,2 ; skip MSB
rjmp set_pagesize
spa_set:
adiw ZL,1 ; Point to high
Byte of Word
lpm ; get Pagesize to R0
mov Pagewords,r0
mov Bcnt3,Pagewords ; initiate Counter
spa_end:
ret
;
***************************************************************************
;*
;* FUNCTION
;* set_pollcode
;*
;* DESCRIPTION
;* sets Code for Polling Flash for selected Device.
;*
;
***************************************************************************
set_pollcode:
lpm ; read table
tst r0 ; check for end of
table
breq spo_end ; no Pollcode to set
cp device,r0
breq spo_set ; C=0
adiw ZL,2 ; skip MSB
rjmp set_pollcode
spo_set:
adiw ZL,1 ; Point to high
Byte of Word
lpm ; get Pagesize to R0
mov PollcodeF,r0 ; Set Pollcode for
Flash Rom
spo_end:
ret
;
***************************************************************************
;*
;* FUNCTION
;* delay
;*
;* DESCRIPTION
;* Make delay 1mS (x temp1).
;*
;
***************************************************************************
delay:
ldi temp2,40
dl2: ldi temp3,(XTAL/120)
dl1: dec temp3
brne dl1
dec temp2
brne dl2
dec temp1
brne delay
ret
;
***************************************************************************
;*
;* FUNCTION
;* spi123
;*
;* DESCRIPTION
;* Write bytes 1 to 3 on the SPI. Byte 1 must be
loadet into s_data
;* Byte 2 ist addrh, Byte 3 ist addrl
;*
;
***************************************************************************
spi123:
rcall wrser ; wrser(s_data) SPI
write (byte 1)
mov s_data,addrh
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
ret
;
***************************************************************************
;*
;* FUNCTION
;* w1234 (for Code simplification, not used yet)
;*
;* DESCRIPTION
;* Write SPI bytes 1 to 4.
; Byte 1 must be loadet into cmd1
; Byte 2 must be loadet into cmd2
; Byte 3 must be loadet into cmd3
; Byte 4 must be loadet into u_data
;*
;
***************************************************************************
w1234:
mov s_data,cmd1
rcall wrser
mov s_data,cmd2
rcall wrser
mov s_data,cmd3
rcall wrser
mov s_data,u_data
rcall wrser
ret
;
***************************************************************************
;*
;* FUNCTION
;* w123r4 (for Code simplification, not used yet)
;*
;* DESCRIPTION
;* Write SPI bytes 1 to 3, read Byte 4 to serial.
; Byte 1 must be loadet into cmd1
; Byte 2 must be loadet into cmd2
; Byte 3 must be loadet into cmd3
;*
;
***************************************************************************
w123r4:
mov s_data,cmd1
rcall wrser
mov s_data,cmd2
rcall wrser
mov s_data,cmd3
rcall wrser
rcall rdser
mov u_data,s_data
rcall wrser ; get Byte 4 from
serial
rcall putc
ret
;
***************************************************************************
;*
;* FUNCTION
;* rdser, wrser
;*
;* DESCRIPTION
;* Write and read bytes on the SPI.
;*
;
***************************************************************************
rdser:
clr s_data
wrser:
ldi temp1,8 ; load bit counter
ldi rd_s_data,0
wrs0:
rol s_data
brcc wrs1
set_MOSI ; MOSI = 1
rjmp wrs2
wrs1:
clr_MOSI ; MOSI = 0
wrs2:
lsl rd_s_data
sbic_MISO ; read MISO
ori rd_s_data,1
pulse_SCK ; pulse SCK
dec temp1 ; advance bit
counter
brne wrs0 ; loop
mov s_data,rd_s_data
ret
;
***************************************************************************
;*
;* FUNCTION
;* read_send_progmem
;*
;* DESCRIPTION
;* Read one adress (2 Byte) from Program Memory and
send it through UART
;*
;
***************************************************************************
read_send_progmem:
tst device
brmi rsp1 ; S89 device
ldi s_data,0x20 ; read low Byte
rcall wrser ; wrser(0x28) SPI
write (byte 1)
mov s_data,addrh
rjmp rsp2
rsp1:
mov s_data,addrh ; s_data = (addrh
<< 3) | 0x01;
rcall shift_s_data3
ori s_data,0x01
rsp2:
rcall wrser ; wrser(addrh) SPI
write (byte 2) (S89=byte1)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
tst device
brmi rsp3 ; S89 device
ldi s_data,0x28 ; read High
Byte
rcall wrser ; wrser(0x20) SPI
write (byte 1)
mov s_data,addrh
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
rsp3:
adiw addrl,1 ; Auto increment
address
ret
;
***************************************************************************
;*
;* FUNCTION
;* read_send_datamem
;*
;* DESCRIPTION
;* Read one Byte from Data Memory (eeprom) and send
it through UART
;*
;
***************************************************************************
read_send_datamem: ; Subroutine to
read one eeprom Address
tst device
brmi rsd1 ; S89 device
ldi s_data,0xa0
rcall wrser ; wrser(0xa0) SPI
write (byte 1)
mov s_data,addrh
rjmp rsd2
rsd1:
cpi device,0x87 ; if (device == S53)
breq rsd3 ; no Support for
89S53 device due to Bug in AVRProg V1.37
mov s_data,addrh
rcall shift_s_data3
ori s_data,0x05
rsd2:
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
adiw addrl,1 ; Auto increment
address
ret
rsd3:
pop temp1 ; remove return
Adress from Stack in case of Error
pop temp1
rjmp put_err
;
***************************************************************************
;*
;* FUNCTION
;* eeprom_write
;*
;* DESCRIPTION
;* Write u_data to Data Memory (eeprom)
;*
;
***************************************************************************
eeprom_write:
tst device
brmi eew1 ; S89 device
ldi s_data,0xc0
rcall wrser ; wrser(0xc0) SPI
write (byte 1)
mov s_data,addrh
rjmp eew2
eew1:
cpi device,0x87 ; if (device == S53)
breq eew3
mov s_data,addrh
rcall shift_s_data3
ori s_data,0x06
eew2:
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
mov s_data,u_data
rcall wrser ; wrser(u_data) SPI
write (byte 4)
ldi temp1,10 ; delay 10mS
rcall delay
;
***************************************************************************
;*
;* FUNCTION
;* shift_s_data3
;*
;* DESCRIPTION
;* Shift s_data 3 times left for S89 device.
;*
;
***************************************************************************
shift_s_data3:
lsl s_data
lsl s_data
lsl s_data
brcc s3_ret
cpi device,0x87 ; if (device != S53)
brne s3_ret
sbr s_data, 4 ; a13 +
s3_ret: ret
;
***************************************************************************
;*
;* FUNCTION
;* healthcheck
;*
;* DESCRIPTION
;* changes color of dual color led.
;*
;
***************************************************************************
;
***************************************************************************
;
***************************************************************************
;
***************************************************************************
;*
;* INIT
;*
;* DESCRIPTION
;* Initialization
;*
;
***************************************************************************
;
***************************************************************************
;
***************************************************************************
INIT:
ldi temp1,RAMEND
out SPL,temp1 ; Locate stack
ldi temp1,PAGESIZE ; default Pagesize
mov Pagewords,temp1
mov Bcnt3,Pagewords ; set counter for
Pagesize
ldi device,0x20 ; S2313 as default
clr B_Mode ; Flag for Block
Modes (see Note 16)
clr B_Flag ; Flag for eNhanced
Block write
init_ports ; Initialize ports
release_ports ; Release ports
rcall u_init ; Initialize UART
rcall healthcheck ; show that Prog is
working after Powerup (LED test)
;
***************************************************************************
;*
;* PROGRAM
;* waitcmd -> main
;*
;* DESCRIPTION
;* Wait for and execute commands.
;*
;
***************************************************************************
waitcmd:
rcall getc ; while (getc() ==
ESC) {};
cpi u_data,0x1b
breq waitcmd
w0:
cpi u_data,'S' ; 'S' Return
software identifier
brne w1
table ID_Str
rcall put_string ; put string "AVR
ISP"
rjmp waitcmd
w1:
cpi u_data,'V' ; 'V' Return
software version
brne w2
table SW_Ver
rcall put_string ; put software
version
rjmp waitcmd
w2:
cpi u_data,'v' ; 'v' Return
hardware version
brne w3
table HW_Ver
rcall put_string ; put hardware
version
rjmp waitcmd
w3:
cpi u_data,'t' ; 't' Show
supported devices
brne w4
table Dev_S
rcall put_table ; put supported
devices codes
table Dev_M
rcall put_table ; put supported
devices codes
ldi u_data,0x00 ; putc(0x00) - end
of device list
rcall putc
rjmp waitcmd
w4:
cpi u_data,'p' ; 'p' Return
programmer type
brne w5
ldi u_data,'S' ; putc('S') -
serial programmer
rcall putc
rjmp waitcmd
w5:
cpi u_data,'a' ; 'a' Return
address auto increment
brne w51
ldi u_data,'Y' ; putc('Y') -
supports autoinc
rcall putc
rjmp waitcmd
w51:
; cpi u_data,'M' ; 'M' Return
enhanced mode Support
; brne w52
; ldi u_data,'Y' ; putc('Y') -
supports enhanced Mode
; rcall putc
; rjmp waitcmd
w52:
cpi u_data,'i' ; 'i' Return Chip ID
brne w53
table ChipID
rcall put_string ; put Chip ID
string
ldi u_data,0x0a ; putc(LF)
rcall putc
rjmp put_ret
w53:
cpi u_data,'b' ; 'b' Return
enhanced mode Support
brne w6
ldi u_data,'Y' ; putc('Y') -
supports enhanced Mode
rcall putc
ldi u_data,high(BUFSIZE) ; putc((BUFSIZE>
>8) & 0xff);
rcall putc
ldi u_data,low(BUFSIZE) ; putc
(BUFSIZE&0xff);
rcall putc
rjmp waitcmd
w6:
cpi u_data,'x' ; 'x' Set LED (LED
off or green)
brne w61
rcall getc ; get parameter
set_LED
rjmp put_ret
w61:
cpi u_data,'y' ; 'y' Clear LED
(LED on or red)
brne w7
rcall getc ; get parameter
clr_LED
rjmp put_ret
;
===========================================================================
w7:
table Dev_S ; load pointer
rcall bel_table
brcc w71 ; device belongs to
table
table Dev_M
rcall bel_table
brcc w71 ; device belongs to
table
rjmp put_err ; not match, goto
put_err();
w71:
cpi u_data,'P' ; 'P' Enter
programming mode
breq w70
rjmp w8
w70:
clr_LED ; LED on
catch_ports ; catch ports
clr_SCK ; clear SCK
pas_RESET ; set RESET passive
ldi temp1,50 ; delay 50mS;
rcall delay
act_RESET ; set RESET active
ldi temp1,50 ; delay 50mS;
rcall delay
ldi s_data,0xac
rcall wrser ; wrser(0xac) SPI
write (byte 1)
ldi s_data,0x53
rcall wrser ; wrser(0x53) SPI
write (byte 2)
; SPI
Synchronization (fix!)
cpi device,0x20 ; if ( (device >
= 0x20) && (device <= 0x7F) )
brlo s2
tst device
brmi s2
ldi temp3,32 ; count = 32;
s1: rcall rdser ; SPI read (byte 3)
cpi s_data,0x53 ; if (rdser == 0x53)
breq s3 ; break
ldi
s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 4)
pulse_SCK ; pulse SCK
ldi s_data,0xac
rcall wrser ; wrser(0xac) SPI
write (byte 1)
ldi s_data,0x53
rcall wrser ; wrser(0x53) SPI
write (byte 2)
dec temp3 ; count-1
brne s1 ; loop
rjmp s3 ; else
s2: ldi s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 3)
s3: tst device
brmi s4 ; S89 device
ldi s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 4)
s4: ldi temp1,4 ; delay 4mS;
rcall delay
rjmp put_ret
w8:
cpi u_data,'c' ; 'c' Write program
memory, low byte
brne w9
rcall getc ; get data byte
w8b: ldi s_data,0x40
mov pol_cmd,s_data ; save command for
polling
tst device
brmi w81 ; S89 device
rcall wrser ; wrser(0x40) SPI
write (byte 1)
mov s_data,addrh
rjmp w82
w81:
mov s_data,addrh ; s_data = (addrh
<< 3) | 0x02;
rcall shift_s_data3
ori s_data,0x02
w82:
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
mov s_data,u_data
rcall wrser ; wrser(u_data) SPI
write (byte 4)
mov p_data,u_data ; save data for
polling
mov pol_al,addrl ; save address for
polling
mov pol_ah,addrh
tst device
brpl w83
adiw addrl,1 ; Auto increment
address for S89 device
w83:
rjmp wait_S ; write FLASH delay
w9:
cpi u_data,'C' ; 'C' Write program
memory, high byte
brne w92
rcall getc ; get data byte
w9a: tst device
brmi w91 ; S89 device
ldi s_data,0x48
mov pol_cmd,s_data ; save command for
polling
rcall wrser ; wrser(0x48) SPI
write (byte 1)
mov s_data,addrh
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
mov s_data,u_data ; wrser(u_data) SPI
write (byte 4)
rcall wrser
mov p_data,u_data ; save data for
polling
mov pol_al,addrl ; save address for
polling
mov pol_ah,addrh
adiw addrl,1 ; Auto increment
address
rjmp wait_S ; write FLASH delay
w91:
rjmp put_err ; S89 device have
byte wide program memory!
w92:
cpi u_data,'B' ; 'B' Block Write
Program Memory
breq w92a
rjmp w10
w92a:
rcall getc ; get count High
Byte
tst u_data
breq w92b
ldi u_data,1
rjmp put_err
w92b:
rcall getc ; get count Low Byte
cpi u_data,BUFSIZE+1 ; check maximum
count
brlo w92c
ldi u_data,2
rjmp put_err
w92c:
mov Bcnt1, u_data ; ignore BUFSIZE
high Byte (must be 0 here)
mov Bcnt2, u_data
rcall getc ; get Memory type
to write
mov Memtype,u_data ; Flag for Memtype
clr XH
ldi XL, RAMSTART ; set X pointer to
SRAM begin
w93:
rcall getc ; get data until
Bcnt1 is reached
st X+, u_data ; store data to SRAM
dec Bcnt1
brne w93
clr XH
ldi XL, RAMSTART ; set X pointer to
SRAM begin
ldi temp3,1
mov B_Mode,temp3 ; B_Mode != 0
mov u_data,Memtype ; restore Memtype
cpi u_data,'F' ; 'F' Flash Memory
ist to write
breq w94a
cpi u_data,'E' ; 'E' eeprom Memory
ist to write
breq w94 ; Entry Point for
Data Memory Block write
ldi u_data,3
rjmp put_err
w94: ; write
Data Memory
ld u_data,X+
rcall eeprom_write
dec Bcnt2
brne w94
rjmp put_ret
w10:
cpi u_data,'R' ; 'R' Read program
memory
brne w10B
tst device
brmi rpm1 ; S89 device
ldi s_data,0x28 ; read high
Byte (order is different from Block Read!)
rcall wrser ; wrser(0x28) SPI
write (byte 1)
mov s_data,addrh
rjmp rpm2
rpm1:
mov s_data,addrh ; s_data = (addrh
<< 3) | 0x01;
rcall shift_s_data3
ori s_data,0x01
rpm2:
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
tst device
brmi rpm3 ; S89 device
ldi s_data,0x20 ; read Low
Byte
rcall wrser ; wrser(0x20) SPI
write (byte 1)
mov s_data,addrh
rcall wrser ; wrser(addrh) SPI
write (byte 2)
mov s_data,addrl
rcall wrser ; wrser(addrl) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
rpm3:
adiw addrl,1 ; Auto increment
address
rjmp waitcmd ; goto waitcmd();
w10B:
cpi u_data,'g' ; 'g' Block Read
Program Memory
brne w11
rcall getc ; XH = getc();
mov XH,u_data
rcall getc ; XL = getc();
mov XL,u_data
rcall getc ; getc(Memorytype);
cpi u_data,'F'
breq w10B2
cpi u_data,'E'
breq w10B1
rjmp put_err
w10B1:
rcall read_send_datamem
sbiw XL, 1
brne w10B1
rjmp waitcmd ; goto waitcmd();
w10B2:
rcall read_send_progmem
tst device
brmi w10B3
sbiw XL, 2
brne w10B2
rjmp waitcmd
w10B3:
sbiw XL, 1
brne w10B2
rjmp waitcmd ; goto waitcmd();
w11:
cpi u_data,'A' ; 'A' Load address
brne w12
rcall getc ; addrh = getc();
mov addrh,u_data
rcall getc ; addrl = getc();
mov addrl,u_data
rjmp put_ret ; goto reply();
w12:
cpi u_data,'D' ; 'D' Write data
memory
brne w13
rcall getc ; get data
rcall eeprom_write
rjmp put_ret
w13:
cpi u_data,'d' ; 'd' Read data
memory
brne w14
rcall read_send_datamem
rjmp waitcmd ; goto waitcmd();
w14:
cpi u_data,'L' ; 'L' Leave
programming mode
brne w142
w141:
pas_RESET ; set RESET passive
release_ports ; release ports
set_LED ; LED off
rjmp put_ret
w142:
cpi u_data,'E' ; 'E' xit
brne w15
rjmp w141 ; exit command for
AVR Prog
w15:
cpi u_data,'e' ; 'e' Chip erase
brne w16
ldi s_data,0xac
rcall wrser ; wrser(0xac) SPI
write (byte 1)
tst device
brmi w151 ; S89 device
ldi s_data,0x80
rcall wrser ; wrser(0x80) SPI
write (byte 2)
w151:
ldi s_data,0x04
rcall wrser ; wrser(0x04) SPI
write (byte 3)
ldi s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 4)
ldi temp1,40 ; delay 40mS
rcall delay
rjmp put_ret
w17:
cpi u_data,'s' ; 's' Read
signature bytes
brne w18
tst device
brmi w171 ; S89 device
ldi param1,0x02 ; param1 = 0x02
rcall ca17
ldi param1,0x01 ; param1 = 0x01
rcall ca17
ldi param1,0x00 ; param1 = 0x00
rcall ca17
rjmp waitcmd
w171:
rjmp put_err
ca17:
ldi s_data,0x30
rcall wrser ; wrser(0x30) SPI
write (byte 1)
ldi s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 2)
mov s_data,param1
rcall wrser ; wrser(param1) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
ret
w18:
cpi u_data,'m' ; 'm' Write Program
Memory Page
brne w19
ldi s_data,0x4c
rcall wrser ; wrser(0x4c) SPI
write (byte 1)
; mov s_data,addrh ; original, reload
address
mov s_data,pol_ah ; for speeding up
transfer
rcall wrser ; wrser(addrh) SPI
write (byte 2)
; mov s_data,addrl ; original, reload
address
mov s_data,pol_al ; for speeding up
transfer
rcall wrser ; wrser(addrl) SPI
write (byte 3)
ldi s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 4)
rjmp wait_M ; write FLASH delay
w19:
cpi u_data,':' ; ':' Universal
Command
brne w20
rcall getc ; get data1
mov cmd1,u_data ; cmd1 = data1
rcall getc ; get data2
mov cmd2,u_data ; cmd2 = data2
rcall getc ; get data3
mov cmd3,u_data ; cmd3 = data3
mov s_data,cmd1
rcall wrser ; wrser(cmd1) SPI
write (byte 1)
mov s_data,cmd2
rcall wrser ; wrser(cmd2) SPI
write (byte 2)
mov s_data,cmd3
rcall wrser ; wrser(cmd3) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
ldi temp1,50 ; delay 50mS
rcall delay
rjmp put_ret
w20:
cpi u_data,'.' ; '.' New Universal
Command
brne w21
rcall getc ; get data1
mov cmd1,u_data ; cmd1 =
data1
rcall getc ; get data2
mov cmd2,u_data ; cmd2 =
data2
rcall getc ; get data3
mov cmd3,u_data ; cmd3 =
data3
rcall getc ; get data4
mov s_data,cmd1
rcall wrser ; wrser(cmd1) SPI
write (byte 1)
mov s_data,cmd2
rcall wrser ; wrser(cmd2) SPI
write (byte 2)
mov s_data,cmd3
rcall wrser ; wrser(cmd3) SPI
write (byte 3)
mov s_data,u_data
rcall wrser ; wrser(u_data) SPI
write (byte 4)
mov u_data,rd_s_data
rcall putc ; send data
ldi temp1,50 ; delay 50mS
rcall delay
rjmp put_ret
w21:
cpi u_data,'r' ; 'r' Read lock bits
brne w30
ldi s_data,0x58
rcall wrser ; wrser(0x58) SPI
write (byte 1)
; ldi s_data,0x00
clr s_data
rcall wrser ; wrser(0x00) SPI
write (byte 2)
; ldi s_data,0x00
rcall wrser ; wrser(0x00) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
mov u_data,s_data
rcall putc ; send data
rjmp put_ret
wait_S:
table Dev_M
rcall bel_table
brcs ws_pol ; No Page Mode,
poll last Byte
rjmp put_ret ; in Byte Mode time
is long enougt to get next Byte...
Bws_pol: ; entry adress for
Block mode delay
ldi temp3,1
mov B_Flag,temp3 ; set Flag that
ws_poll comes back with ret ...
ws_pol:
tst PollcodeF ; if polling not
applicable, standart delay
breq ws_del ; polling not used
ws_def:
cp p_data,PollcodeF ; if (data ==
PollcodeF)
breq ws_del ; wait default delay
andi pol_cmd,0x0f ; write command:
0x48, 0x40
ori pol_cmd,0x20 ; read command:
0x28, 0x20
clr temp3 ; clear polling
counter
ws_cy:
tst device
brmi ws_89 ; S89 device
mov s_data,pol_cmd
rcall wrser ; wrser(pol_cmd)
SPI write (byte 1)
mov s_data,pol_ah
rjmp ws_90
ws_89:
mov s_data,pol_ah ; s_data = (pol_ah
<< 3) | 0x01;
rcall shift_s_data3
ori s_data,0x01
ws_90:
rcall wrser ; wrser(pol_ah) SPI
write (byte 2) (S89=byte1)
mov s_data,pol_al
rcall wrser ; wrser(pol_al) SPI
write (byte 3) (S89=byte2)
rcall rdser ; SPI
read (byte 4) (S89=byte3)
tst device
brpl ws_cb
andi s_data,0x80 ; compare only MSB
for S89 device
andi p_data,0x80
ws_cb:
cp s_data,p_data
breq ws_ok ; s_data = p_data
dec temp3
brne ws_cy ; loop
ws_del: ; 256
polling cycles are over, give additional standart Time
ldi temp1,10 ; delay 10mS
rcall delay
ws_ok:
tst B_Flag
breq put_ret
clr B_Flag ; Reset B_Flag for
normal operation
ret
wait_M:
cpi device,0x41
breq wm_del ; polling
inapplicable for m103
cpi device,0x23
breq poll_t2313 ; polling different
for t2313
cpi p_data, 0xFF ; if last Byte was
0xFF give standart delay
breq wm_del
andi pol_cmd,0x0f ; write command:
0x48, 0x40
ori pol_cmd,0x20 ; read command:
0x28, 0x20
clr temp3 ; clear polling
counter
wm_cy:
mov s_data,pol_cmd
rcall wrser ; wrser(pol_cmd)
SPI write (byte 1)
mov s_data,pol_ah
rcall wrser ; wrser(pol_ah) SPI
write (byte 2)
mov s_data,pol_al
rcall wrser ; wrser(pol_al) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
cp s_data,p_data
breq wm_ok ; s_data = p_data
dec temp3
breq wm_del ; 256 polling
cycles are over, give another 50ms delay...
rjmp wm_cy ; loop
wm_del:
ldi temp1,50 ; delay 50mS
rcall delay
wm_ok:
tst B_Mode
breq wm_end
tst Bcnt2
breq wm_end
rjmp w95
wm_end:
clr B_Mode ; Reset Block Mode
Flag
rjmp put_ret
poll_t2313: ; Polling
ATTiny2313 is different
ldi pol_cmd,0xf0 ; Byte1= 0xF0
clr temp3 ; clear polling
counter
mov pol_ah,temp3 ; Byte2= 0x00
p2313_1:
mov s_data,pol_cmd
rcall wrser ; wrser(pol_cmd)
SPI write (byte 1)
mov s_data,pol_ah
rcall wrser ; wrser(pol_ah) SPI
write (byte 2)
mov s_data,pol_al
rcall wrser ; wrser(pol_al) SPI
write (byte 3)
rcall rdser ; SPI
read (byte 4)
andi s_data,0x01 ; last Bit tells if
polling OK
breq wm_ok ; s_data = p_data
dec temp3
breq wm_del ; 256 polling
cycles are over, give another 50ms delay...
rjmp p2313_1 ; loop
put_ret:
ldi u_data,0x0d ; putc(0x0D)
rcall putc ; send CR
rjmp waitcmd
;
***************************************************************************
;*
;* TABLE
;* device codes
;*
;* DESCRIPTION
;* The following device codes must be used by the host
computer. Note
;* that the device codes are arbitrary selected, they
do not have any
;* thing in common with the signature bytes stored in
the device.
;* This are the device Codes recognized by the AVRprog
Software. Some
;* Devices may require special hardware or a
different, not yet
;* implemented Protocol! Use at your own risk.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* TABLE
;* revision codes
;*
;
***************************************************************************
SW_Ver:
.db "37",0,0
HW_Ver:
.db "12",0,0
;
***************************************************************************
;*
;* TABLE
;* ID string "AVR ISP"
;*
;
***************************************************************************
ID_Str:
.db "AVR ISP",0
;
***************************************************************************
;*
;* TABLE
;* Chip ID string to identify the Firmware
;*
;
***************************************************************************
ChipID:
.db "Ver.3.7e (AVR109 Mode, 7.3728Mhz, 115.200
baud) for AN910, AT90S2313"
.db "www.mikrocontroller-projekte.de 14.Jan.2005",0
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
.include "1200def.inc"
;
***************************************************************************
;*
;* CONSTANTS
;* device codes
;*
;* DESCRIPTION
;* The following device codes must be used by the host
computer. Note
;* that the device codes are arbitrary selected, they
do not have any
;* thing in common with the signature bytes stored in
the device.
;*
;* The following devices are supported (make a new
table for each
;* software release):
;*
;* SW_MAJOR=1, SW_MINOR=5
;* AT90S1200 rev. C (abbreviated S1200C)
;* AT90S1200 rev. D (abbreviated S1200D)
;* AT90S8515 rev. A (abbreviated S8515A)
;* AT89S8252 (abbreviated S8252)
;*
;* SW_MAJOR=1, SW_MINOR=6
;* AT90S1200 rev. C (abbreviated S1200C)
;* AT90S1200 rev. D (abbreviated S1200D)
;* AT90S8515 rev. A (abbreviated S8515A)
;* AT89S8252 (abbreviated S8252)
;* ATmega103 rev. A (abbreviated S01838A)
;*
;
***************************************************************************
;
***************************************************************************
;*
;* MACROS
;* Program Macros
;*
;* DESCRIPTION
;* Change the following four macros if the RESET pin
to the
;* target moves and/or if the SCK/MISO/MOSO moves.
;*
;
***************************************************************************
.macro set_reset
sbi portb,4
.endm
.macro clr_reset
cbi portb,4
.endm
.macro ddrd_init
nop
; sbi ddrd,3
.endm
.macro ddrb_init
ldi temp1,0xdf
out ddrb,temp1 ; PB5 is input, the rest is
output
.endm
.macro ddrb_release
ldi temp1,(1<<PB4)
out ddrb,temp1 ; PB4 (RESET) is output,
the rest is input
.endm
.macro pulse_sck
sbi portb,SCK
ldi temp2,6
m0: dec temp2
brne m0
cbi portb,SCK
ldi temp2,1 ; 3
m1: dec temp2
brne m1
.endm
;*****************
;* SPI Constants *
;*****************
;******************
;* UART Constants *
;******************
.equ TXPIN = 1
.equ RXPIN = 0 ; Receive pin must
be external interrupt !!
;*****************************
;* Global Register Variables *
;*****************************
;*********************
;* Interrupt Vectors *
;*********************
.CSEG
rjmp RESET ; Reset Handle
reti ; IRQ0 Handle (not used)
rjmp TIM0_OVF ; Timer0 Overflow Handle
reti ; Analog Comparator Handle
(not used)
;
***************************************************************************
;*
;* INTERRUPT
;* TIM0_OVF - Software UART Service Routine
;*
;
***************************************************************************
TIM0_OVF:
in r0,SREG ; store SREG
ldi temp1,(256-N+8)
out TCNT0,temp1 ; reset T/C0 to one bit
lenght
inc bit_cnt ; increment bit counter
sbrs u_stat,TXC ; if (transmit complete
flag clear)
rjmp transmit ; goto transmit
transmit:
cpi bit_cnt,1 ; if (bit_cnt == 1) \\
start bit
brne to_2 ; {
cbi PORTD,TXPIN ; generate start bit
rjmp to_1 ; exit
to_2: ; }
cpi bit_cnt,10 ; if (bit_cnt == 10) \\
stop bit
brne to_3 ; {
sbi PORTD,TXPIN ; generate stop bit
clr temp1 ; disable TC0
overflow interrupt
out TIMSK,temp1
sbr u_stat,1<<TXC ; set transmit
complete bit
rjmp to_1 ; exit
to_3: ; }
sbrc u_data,0 ; if (LSB set)
sbi PORTD,TXPIN ; PD3 = HIGH
sbrs u_data,0 ; if (LSB clear)
cbi PORTD,TXPIN ; PD3 = LOW
lsr u_data ; shift left u_data
rjmp to_1 ; exit
;
***************************************************************************
;*
;* FUNCTION
;* u_init
;*
;* DESCRIPTION
;* Initialize UART.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* FUNCTION
;* putc
;*
;* DESCRIPTION
;* Send a character on the UART Tx line.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* FUNCTION
;* getc
;*
;* DESCRIPTION
;* Wait for start bit and receive a character on the
UART Rx line.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* FUNCTION
;* delay
;*
;* DESCRIPTION
;* Make a small delay.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* FUNCTION
;* wrser
;*
;* DESCRIPTION
;* Write a byte to the SPI.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* FUNCTION
;* rdser
;*
;* DESCRIPTION
;* Read a byte from the SPI.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* FUNCTION
;* spiinit (Enter programming mode)
;*
;* DESCRIPTION
;* Initialize SPI interface on AVR or 'AT89 device.
;*
;
***************************************************************************
; // SPI Synchronization
(fix!)
cpi device,0x20 ; if ( (device >= 0x20) &&
(device <= 0x7F) )
brlo s2
tst device
brmi s2
s0b: ; {
ldi count,32 ; count = 32;
s1: ; do {
rcall rdser ; if (rdser
== 0x53) // SPI read (byte 3)
cpi s_data,0x53
breq s3 ;
break;
ldi s_data,0x00 ; wrser
(0x00); // SPI write (byte 4)
rcall wrser
pulse_sck ; pulse SCK
ldi s_data,0xac ; wrser
(0xac); // SPI write (byte 1)
rcall wrser
ldi s_data,0x53 ; wrser
(0x53); // SPI write (byte 2)
rcall wrser
dec count ; } while(--count);
brne s1
rjmp s3 ; }
; else
s2: ; {
ldi s_data,0x00 ; wrser
(0x00); // SPI write (byte 3)
rcall wrser
s3: ; }
cpi device,S8252 ; if (device != S8252)
breq s4 ; {
ldi s_data,0x00 ; wrser(0x00); //
SPI write (byte 4)
rcall wrser
s4: ; }
ldi temp1,0x10 ; delay(0x10);
rcall delay
ret
;
***************************************************************************
;*
;* FUNCTION
;* show_id
;*
;* DESCRIPTION
;* Show our ID ("AVR ISP") on the serial line.
;*
;
***************************************************************************
;
***************************************************************************
;*
;* RESET
;*
;* DESCRIPTION
;* Initialization
;*
;
***************************************************************************
;
***************************************************************************
;*
;* PROGRAM
;* waitcmd -> main
;*
;* DESCRIPTION
;* Wait for and execute commands.
;*
;
***************************************************************************
w7:
cpi device,S1200C ; if ((device != S1200C) &&
breq w72
cpi device,S1200D ; (device != S1200D) &&
breq w72
cpi device,S8515A ; (device != S8515A) &&
breq w72
cpi device,S4414A ; (device != S4414A) &&
breq w72
cpi device,S2313A ; (device != S2313A) &&
breq w72
cpi device,S8252 ; (device != S8252) &&
breq w72
cpi device,S01838C ; (device != S01838C) &&
breq w72
cpi device,S01838D ; (device != S01838D) &&
breq w72
cpi device,S2323A ; (device != S2323A))
breq w72
rjmp put_err ; goto put_err();
;* USAGE
;* wait_pm(byte cmd, byte c_data);
;*
;* cmd : 0x28 - wait for high byte written
;* 0x20 - wait for low byte written
;* u_data : current data written
;wait_pm: ; do
; ; {
; mov s_data,cmd ; wrser
(cmd); // SPI write (byte 1)
; rcall wrser
; mov s_data,addrh ; wrser
(addrh); // SPI write (byte 2)
; rcall wrser
; mov s_data,addrl ; wrser
(addrl); // SPI write (byte 3)
; rcall wrser
; rcall rdser ; s_data = rdser
(); // SPI read (byte 4)
; }
; cp s_data,u_data ; while(s_data != u_data);
; brne wait_pm
; ret
ldi s_data,0xc0
rcall wrser
mov s_data,addrh
rjmp w111
w17call:ldi s_data,0x30
rcall wrser
ldi s_data,0x00
rcall wrser
mov s_data,param1
rcall wrser
rcall rdser
mov u_data,s_data
rcall putc
ret
rcall getc
mov cmd1,u_data
rcall getc
mov cmd2,u_data
rcall getc
mov cmd3,u_data
rcall universal
ldi temp1,0xff ; delay(0xFF); //
0x20 = 24585 cycles delay
rcall delay
rjmp put_ret
universal:
mov s_data,cmd1
rcall wrser
mov s_data,cmd2
rcall wrser
mov s_data,cmd3
rcall wrser
rcall rdser
mov u_data,s_data
rcall putc
ret
w99:
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
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
;
***************************************************************************
;*
;* REGISTER DEFINITIONS
;*
;
***************************************************************************
;
***************************************************************************
;*
;* MACROS
;* Program Macros
;*
;* DESCRIPTION
;* Change the following macros if a port other than
PORTB is used.
;*
;
***************************************************************************
.macro ss_active
cbi portb,nss
.endm
.macro ss_inactive
sbi portb,nss
.endm
.macro sck_hi
sbi portb,sck
.endm
.macro sck_lo
cbi portb,sck
.endm
.macro mosi_hi
sbi portb,mosi
.endm
.macro mosi_lo
cbi portb,mosi
.endm
.macro addi
subi @0, -@1 ;subtract the negative of
an immediate value
.endm
;
***************************************************************************
;*
;* SAMPLE APPLICATION, READY TO RUN ON AN AT90S1200
;*
;
***************************************************************************
.cseg
.org 0
Rvect: rjmp Reset
;
***************************************************************************
;*
;* FUNCTION
;* init_spi
;*
;* DESCRIPTION
;* Initialize our port pins for use as SPI master.
;*
;* CODE SIZE:
;* 8 words
;*
;
***************************************************************************
init_spi:
ss_inactive ;set latch bit hi (inactive)
sbi ddrb,nss ;make it an output
;
sck_lo ;set clk line lo
sbi ddrb,sck ;make it an output
;
mosi_lo ;set data-out lo
sbi ddrb,mosi ;make it an output
;
cbi ddrb,miso ;not really required, it
powers up clr'd!
ret
;
***************************************************************************
;*
;* FUNCTION
;* ena_spi
;*
;* DESCRIPTION
;* Init data & clock lines, then assert /SS. Note
that if more than
;* one slave is used, copies of this could be made
that would each
;* reference a different /SS port pin (use SS_ACTIVE0,
SS_ACTIVE1, ...)
;*
;* CODE SIZE:
;* 4 words
;*
;
***************************************************************************
ena_spi:
sck_lo ;(should already be
there...)
mosi_lo
ss_active
ret
;
***************************************************************************
;*
;* FUNCTION
;* disa_spi
;*
;* DESCRIPTION
;* De-assert /SS. Since this routine is so short, it
might be better
;* to use the SS_INACTIVE statement directly in higher
level code.
;* Again, if multiple slaves exist, additional copies
of this could
;* be created; or ONE routine that disabled ALL /ss
signals could be
;* used instead to make the code less error-prone due
to calling the
;* wrong Disable routine.
;*
;* CODE SIZE:
;* 2 words
;*
;
***************************************************************************
disa_spi:
ss_inactive
ret
;
***************************************************************************
;*
;* FUNCTION
;* rw_spi
;*
;* DESCRIPTION
;* Write a word out on SPI while simultaneously
reading in a word.
;* Data is sent MSB-first, and info read from SPI goes
into
;* the same buffer that the write data is going out
from.
;* Make sure data, clock and /SS are init'd before
coming here.
;* SCK high time is ((delay * 3) + 1) AVR clock cycles.
;*
;* If 8-bit use is needed, change LDI TEMP,16 to ,8
and also
;* eliminate the ROL SPI_HI statement.
;*
;* CODE SIZE:
;* 21 words
;* NUMBER OF CYCLES:
;* Overhead = 8, loop = 16 * (16 + (2*
(delay_value*3)))
; (With call + return + delay=4, it is about 648
cycles.)
;*
;
***************************************************************************
rw_spi:
ldi temp,16 ;init loop counter to 16
bits
;ldi temp,8 ;use THIS line instead if 8-
bit desired
;
spi_loop:
lsl spi_lo ;move 0 into D0, all other
bits UP one slot,
rol spi_hi ; and C ends up being first
bit to be sent.
;If 8-bit desired, also comment out the preceding ROL
SPI_HI statement
;
brcc lo_mosi
mosi_hi
rjmp mosi_done ;this branch creates setup
time on MOSI
lo_mosi:
mosi_lo
nop ;also create setup time on
MOSI
mosi_done:
;
sck_hi
;
;must now time the hi pulse - not much else we can do
here but waste time
;
set_delay temp,4 ;(4 * 3) cycle delay; range
is from 1 to 7!
time_hi:
inc_delay temp ;inc upper nibble until it
rolls over; then,
brcs time_hi ; C gets CLEARED, & temp
has original value
;
sck_lo ;drop clock line low
;
;must now delay before reading in SPI data on MISO
;
set_delay temp,4
time_lo:
inc_delay temp
brcs time_lo
;
sbic pinb,miso ;after delay, read in SPI
bit & put into D0
inc spi_lo ;we FORCED D0=0, so use INC
to set D0.
;
dec temp
brne spi_loop
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
i2c_hp_delay:
ldi i2cdelay,2
i2c_hp_delay_loop:
dec i2cdelay
brne i2c_hp_delay_loop
ret
i2c_qp_delay:
ldi i2cdelay,1
i2c_qp_delay_loop:
dec i2cdelay
brne i2c_qp_delay_loop
ret
;
***************************************************************************
;*
;* FUNCTION
;* i2c_rep_start
;*
;* DESCRIPTION
;* Assert repeated start condition and sends slave
address.
;*
;* USAGE
;* i2cadr - Contains the slave address and transfer
direction.
;*
;* RETURN
;* Carry flag - Cleared if a slave responds to the
address.
;*
;* NOTE
;* IMPORTANT! : This funtion must be directly followed
by i2c_start.
;*
;
***************************************************************************
i2c_rep_start:
sbi DDRD,SCLP ; force SCL low
cbi DDRD,SDAP ; release SDA
rcall i2c_hp_delay ; half period delay
cbi DDRD,SCLP ; release SCL
rcall i2c_qp_delay ; quarter period
delay
;
***************************************************************************
;*
;* FUNCTION
;* i2c_start
;*
;* DESCRIPTION
;* Generates start condition and sends slave address.
;*
;* USAGE
;* i2cadr - Contains the slave address and transfer
direction.
;*
;* RETURN
;* Carry flag - Cleared if a slave responds to the
address.
;*
;* NOTE
;* IMPORTANT! : This funtion must be directly followed
by i2c_write.
;*
;
***************************************************************************
i2c_start:
mov i2cdata,i2cadr ; copy address to
transmitt register
sbi DDRD,SDAP ; force SDA low
rcall i2c_qp_delay ; quarter period
delay
;
***************************************************************************
;*
;* FUNCTION
;* i2c_write
;*
;* DESCRIPTION
;* Writes data (one byte) to the I2C bus. Also used
for sending
;* the address.
;*
;* USAGE
;* i2cdata - Contains data to be transmitted.
;*
;* RETURN
;* Carry flag - Set if the slave respond transfer.
;*
;* NOTE
;* IMPORTANT! : This funtion must be directly followed
by i2c_get_ack.
;*
;
***************************************************************************
i2c_write:
sec ; set carry flag
rol i2cdata ; shift in carry
and out bit one
rjmp i2c_write_first
i2c_write_bit:
lsl i2cdata ; if transmit
register empty
i2c_write_first:
breq i2c_get_ack ; goto get
acknowledge
sbi DDRD,SCLP ; force SCL low
rjmp i2c_write_bit
;
***************************************************************************
;*
;* FUNCTION
;* i2c_get_ack
;*
;* DESCRIPTION
;* Get slave acknowledge response.
;*
;* USAGE
;* (used only by i2c_write in this version)
;*
;* RETURN
;* Carry flag - Cleared if a slave responds to a
request.
;*
;
***************************************************************************
i2c_get_ack:
sbi DDRD,SCLP ; force SCL low
cbi DDRD,SDAP ; release SDA
rcall i2c_hp_delay ; half period delay
cbi DDRD,SCLP ; release SCL
i2c_get_ack_wait:
sbis PIND,SCLP ; wait SCL high
;(In case wait
states are inserted)
rjmp i2c_get_ack_wait
;
***************************************************************************
;*
;* FUNCTION
;* i2c_do_transfer
;*
;* DESCRIPTION
;* Executes a transfer on bus. This is only a
combination of i2c_read
;* and i2c_write for convenience.
;*
;* USAGE
;* i2cadr - Must have the same direction as when
i2c_start was called.
;* see i2c_read and i2c_write for more information.
;*
;* RETURN
;* (depends on type of transfer, read or write)
;*
;* NOTE
;* IMPORTANT! : This funtion must be directly followed
by i2c_read.
;*
;
***************************************************************************
i2c_do_transfer:
sbrs i2cadr,b_dir ; if dir = write
rjmp i2c_write ; goto write
data
;
***************************************************************************
;*
;* FUNCTION
;* i2c_read
;*
;* DESCRIPTION
;* Reads data (one byte) from the I2C bus.
;*
;* USAGE
;* Carry flag - If set no acknowledge is given to
the slave
;* indicating last read operation
before a STOP.
;* If cleared acknowledge is given to
the slave
;* indicating more data.
;*
;* RETURN
;* i2cdata - Contains received data.
;*
;* NOTE
;* IMPORTANT! : This funtion must be directly followed
by i2c_put_ack.
;*
;
***************************************************************************
i2c_read:
rol i2cstat ; store acknowledge
; (used by
i2c_put_ack)
ldi i2cdata,0x01 ; data = 0x01
i2c_read_bit: ; do
sbi DDRD,SCLP ; force SCL
low
rcall i2c_hp_delay ; half period
delay
;
***************************************************************************
;*
;* FUNCTION
;* i2c_put_ack
;*
;* DESCRIPTION
;* Put acknowledge.
;*
;* USAGE
;* (used only by i2c_read in this version)
;*
;* RETURN
;* none
;*
;
***************************************************************************
i2c_put_ack:
sbi DDRD,SCLP ; force SCL low
;
***************************************************************************
;*
;* FUNCTION
;* i2c_stop
;*
;* DESCRIPTION
;* Assert stop condition.
;*
;* USAGE
;* No parameters.
;*
;* RETURN
;* None.
;*
;
***************************************************************************
i2c_stop:
sbi DDRD,SCLP ; force SCL low
sbi DDRD,SDAP ; force SDA low
rcall i2c_hp_delay ; half period delay
cbi DDRD,SCLP ; release SCL
rcall i2c_qp_delay ; quarter period
delay
cbi DDRD,SDAP ; release SDA
rcall i2c_hp_delay ; half period delay
ret
;
***************************************************************************
;*
;* FUNCTION
;* i2c_init
;*
;* DESCRIPTION
;* Initialization of the I2C bus interface.
;*
;* USAGE
;* Call this function once to initialize the I2C bus.
No parameters
;* are required.
;*
;* RETURN
;* None
;*
;* NOTE
;* PORTD and DDRD pins not used by the I2C bus
interface will be
;* set to Hi-Z (!).
;*
;* COMMENT
;* This function can be combined with other PORTD
initializations.
;*
;
***************************************************************************
i2c_init:
clr i2cstat ; clear I2C status
register (used
; as a temporary
register)
out PORTD,i2cstat ; set I2C pins to
open colector
out DDRD,i2cstat
ret
;
***************************************************************************
;*
;* PROGRAM
;* main - Test of I2C master implementation
;*
;* DESCRIPTION
;* Initializes I2C interface and shows an example of
using it.
;*
;
***************************************************************************
RESET:
main: rcall i2c_init ;
initialize I2C interface
sec ; Set no
acknowledge (read is followed by a stop condition)
rcall i2c_do_transfer ; Execute transfer
(read)
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
*************************************************************************
;* Start TWI Comunication in Master Mode
; In: X - Address of IO_CTR Block
;
; R17 - count of byte
; R18 - Slave Address
; R19 - Internal Address of Slave
; Out: c = 1 error
;
TWI_StartRead:
rcall WaitToTWI
ldi R16,Low(RBlock0)
sts TWI_SADR+0,R16
ldi R16,High(RBlock0)
sts TWI_SADR+1,R16
TWI_Common:
sts TWI_CTL+0,XL
sts TWI_CTL+1,XH
sts TWI_Count,R17
sts TWI_Slave,R18
sts TWI_ADR,R19
lds R16,TWI_Flag
ori R16,1 ;TWI in use!
andi R16,0b11111101 ;TWI no error
sts TWI_Flag,R16
ldi R16,0b11100101
sts TWCR,R16 ;7 – TWINT: TWI
Interrupt Flag
;6 – TWEA: TWI
Enable Acknowledge
;5 – TWSTA: TWI
START Condition
;4 – TWSTO: TWI
STOP Condition
;3 – TWWC: TWI
Write Collision
;2 – TWEN: TWI
Enable
;1 – Res: Reserved
;0 – TWIE: TWI
Interrupt Enable
TWIRET:
ret
;
*************************************************************************
;* Start TWI Comunication in Master Mode - Write!
; In: X - Address of IO_CTR Block
; R17 - count of byte
; R18 - Slave Address
; R19 - Internal Address of Slave
; Out: c = 1 error
;
TWI_StartWrite:
rcall WaitToTWI
ldi R16,Low(WBlock0)
sts TWI_SADR+0,R16
ldi R16,High(WBlock0)
sts TWI_SADR+1,R16
rjmp TWI_Common
;
*************************************************************************
;* TWI interrupt
;*
TWI: ; Two-wire Serial Interface
Interrupt Handler
push ZL
push ZH
in ZL,SREG ;preserve main OS status
reg.
push ZL
push R16
push R0
push R17
in ZL,RAMPZ
push ZL
lds ZL,TWI_SADR+0
lds ZH,TWI_SADR+1
icall
pop ZL
out RAMPZ,ZL
pop R17
POP R0
POP R16
POP ZL
OUT SREG,ZL
POP ZH
POP ZL
RETI
;
************************************************************************************************************
;*** R E A D B L O C K
;***
;
;***********************
; Read Block of data - State 0
; Start bit sended
RBlock0:
cpi R16,0x08 ;A
START condition has been transmitted
breq Rbl0
cpi R16,0x10 ;A
Repeated START condition has been transmitted
breq Rbl0
rjmp TWI_ReadError
Rbl0:
lds R16,TWI_Slave
andi R16,0b11111110 ;Write SLA
sts TWDR,R16 ;Send Slave
Address
ldi R16,Low(RBlock1)
sts TWI_SADR+0,R16
ldi R16,High(RBlock1)
sts TWI_SADR+1,R16
ldi R16,Low(RBlock2)
sts TWI_SADR+0,R16
ldi R16,High(RBlock2)
sts TWI_SADR+1,R16
ldi R16,(1< Repeated Satrt send
RBlock2:
cpi R16,0x28 ;
SlaveAddress sended + ACK received
breq Rbl21
rjmp TWI_ReadError
Rbl21:
ldi R16,Low(RBlock3)
sts TWI_SADR+0,R16
ldi R16,High(RBlock3)
sts TWI_SADR+1,R16
ldi R16,Low(RBlock4)
sts TWI_SADR+0,R16
ldi R16,High(RBlock4)
sts TWI_SADR+1,R16
lds R16,TWI_Count
cpi R16,1
breq TWILAstByte
ldi R16,Low(RBlock5)
sts TWI_SADR+0,R16
ldi R16,High(RBlock5)
sts TWI_SADR+1,R16
ldi R16,Low(WBlock2)
sts TWI_SADR+0,R16
ldi R16,High(WBlock2)
sts TWI_SADR+1,R16
ldi R16,(1< Write data
WBlock2:
cpi R16,0x28 ;Data byte
has been transmitted + ACK received
breq WB12
rjmp TWI_WriteError
WB12: ;
Send data byte continous
lds ZL,TWI_CTL+0
lds ZH,TWI_CTL+1
ld R0,Z+
sts TWDR,R0 ;next data
byte
sts TWI_CTL+0,ZL
sts TWI_CTL+1,ZH
lds R16,TWI_Count
cpi R16,1
breq TWI_WriteLastByte
dec R16
sts TWI_Count,R16
ldi R16,(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
;
*************************************************************************
;* Start TWI Comunication in Master Mode
; In: X - Address of IO_CTR Block
;
; R17 - count of byte
; R18 - Slave Address
; R19 - Internal Address of Slave
; Out: c = 1 error
;
TWI_StartRead:
rcall WaitToTWI
ldi R16,Low(RBlock0)
sts TWI_SADR+0,R16
ldi R16,High(RBlock0)
sts TWI_SADR+1,R16
TWI_Common:
sts TWI_CTL+0,XL
sts TWI_CTL+1,XH
sts TWI_Count,R17
sts TWI_Slave,R18
sts TWI_ADR,R19
lds R16,TWI_Flag
ori R16,1 ;TWI in use!
andi R16,0b11111101 ;TWI no error
sts TWI_Flag,R16
ldi R16,0b11100101
out TWCR,R16 ;7 – TWINT: TWI
Interrupt Flag
;6 – TWEA: TWI
Enable Acknowledge
;5 – TWSTA: TWI
START Condition
;4 – TWSTO: TWI
STOP Condition
;3 – TWWC: TWI
Write Collision
;2 – TWEN: TWI
Enable
;1 – Res: Reserved
;0 – TWIE: TWI
Interrupt Enable
TWIRET:
ret
;
*************************************************************************
;* Start TWI Comunication in Master Mode - Write!
; In: X - Address of IO_CTR Block
; R17 - count of byte
; R18 - Slave Address
; R19 - Internal Address of Slave
; Out: c = 1 error
;
TWI_StartWrite:
rcall WaitToTWI
ldi R16,Low(WBlock0)
sts TWI_SADR+0,R16
ldi R16,High(WBlock0)
sts TWI_SADR+1,R16
rjmp TWI_Common
;
*************************************************************************
;* TWI interrupt
;*
TWI: ; Two-wire Serial Interface
Interrupt Handler
push ZL
push ZH
in ZL,SREG ;preserve main OS status
reg.
push ZL
push R16
push R0
push R17
lds ZL,TWI_SADR+0
lds ZH,TWI_SADR+1
icall
pop R17
POP R0
POP R16
POP ZL
OUT SREG,ZL
POP ZH
POP ZL
RETI
;
************************************************************************************************************
;*** R E A D B L O C K
;***
;
;***********************
; Read Block of data - State 0
; Start bit sended
RBlock0:
cpi R16,0x08 ;A
START condition has been transmitted
breq Rbl0
cpi R16,0x10 ;A
Repeated START condition has been transmitted
breq Rbl0
rjmp TWI_ReadError
Rbl0:
lds R16,TWI_Slave
andi R16,0b11111110 ;Write SLA
out TWDR,R16 ;Send Slave
Address
ldi R16,Low(RBlock1)
sts TWI_SADR+0,R16
ldi R16,High(RBlock1)
sts TWI_SADR+1,R16
ldi R16,Low(RBlock2)
sts TWI_SADR+0,R16
ldi R16,High(RBlock2)
sts TWI_SADR+1,R16
ldi R16,(1< Repeated Satrt send
RBlock2:
cpi R16,0x28 ;
SlaveAddress sended + ACK received
breq Rbl21
rjmp TWI_ReadError
Rbl21:
ldi R16,Low(RBlock3)
sts TWI_SADR+0,R16
ldi R16,High(RBlock3)
sts TWI_SADR+1,R16
ldi R16,Low(RBlock4)
sts TWI_SADR+0,R16
ldi R16,High(RBlock4)
sts TWI_SADR+1,R16
lds R16,TWI_Count
cpi R16,1
breq TWILAstByte
ldi R16,Low(RBlock5)
sts TWI_SADR+0,R16
ldi R16,High(RBlock5)
sts TWI_SADR+1,R16
ldi R16,Low(WBlock2)
sts TWI_SADR+0,R16
ldi R16,High(WBlock2)
sts TWI_SADR+1,R16
ldi R16,(1< Write data
WBlock2:
cpi R16,0x28 ;Data byte
has been transmitted + ACK received
breq WB12
rjmp TWI_WriteError
WB12: ;
Send data byte continous
lds ZL,TWI_CTL+0
lds ZH,TWI_CTL+1
ld R0,Z+
out TWDR,R0 ;next data
byte
sts TWI_CTL+0,ZL
sts TWI_CTL+1,ZH
lds R16,TWI_Count
cpi R16,1
breq TWI_WriteLastByte
dec R16
sts TWI_Count,R16
ldi R16,(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
http://avr-asm.tripod.com/twi8.html (1 of 2)1/20/2009 9:03:20 PM
16 BIT MATH (AVR 202)
ISP 1200
AVR SPI ;
*****************************************************************************
I2C 300 .CSEG
I2C 302
I2C TWI26
I2C/TWI 128
I2C/TWI AT8 ;************************************************************************
;*********************** 1-Wire Bus *************************************
DALLAS-1W ;************************************************************************
DALLAS CRC
DS1Wire_Init:
ETHNET 8019 clr R16,
TEA sts CRC,R16
sts BadCRC,R16
ADC 128
ADC 10B cbi DS1wire_PORT,DS1wire
cbi DS1wire_DIR,DS1wire
ADC 400
ret
ADC 401
THERM 232
;
IRD 410 *******************************************************************************
LCD HD44 ;****** T O U C H R E S E T
;
LCD 2313 *******************************************************************************
LCD44 2313 ;
;Inicialization procedure "Reset and PreSence Pulses"
KBD 240 ;
MUX 242 ; Ez a rutin egy Reset jelet general a mikrovrzerlo ketiranyu DS_BIT nevu
laban,
KBD PS2
;a Touch Memory fele es figyeli a visszajovo PreSence jelet.
KBD PC/128 ;Ha a PreSence jel megerkezett, akkor C=1 kulonben C=0 (nincs eszkoz a
PS2 EMU buszon)
;
BOOT MG8 ; |-Master Rx "Presence Pulse"-|
BOOT DR8 ; |---Master Reset Tx Pulse---| |----t(RSTH)---------------|
; __ t(RSTL) _____ _____ \\ ___
ALM CLK ; \ / \ / \
CLOCK 8564 ; \_________________________/ \______/ \__ ...
; |-----|-------|
90 DAYS
; t(PDH) t(PDL)
DELAYS ; t(R) <-- |-|
;
CALL ID
; 480us<=t(RSTL)< . t(RSTL)+t(R)<960us
DTMF 314 ; 480us<=t(RSTH)<
PWM 6CH ; 15us<=t(PDH)<=60us
; 60us<=t(PDL)<=240us
PWM 10K ;
ENCODE ; C-flag = 1 DS1990A a buszon van
; = 0 DS1990A nincs a buszon
STH-11 ;
ATMEL CORP ; R16, X
AVR
TouchReset:
BUTTERFLY
AVR BOOK SBI DS1wire_DIR,DS1wire ; 1-wire = Master LOW ,
Start the reset pulse
ldi YL,low((480*SYSCLK)/(1000000*4))
ldi YH,high((480*SYSCLK)/(1000000*4));loop cycle = 4
TR0: sbiw YL,1 ;[2]
brne TR0 ;[1/2] 480us wait with data
low
ldi YL,low((60*SYSCLK)/(1000000*6))
ldi YH,high((60*SYSCLK)/(1000000*6));loop cycle = 6
TR1: SBIS DS1wire_PIN,DS1wire ;[1/2]
RJMP WL ;[2] Exit loop if line low
sbiw YL,1 ;[2]
BRNE TR1 ;[1/2] 60 us wait with data
low
RJMP SHORT ;[2] Line could not go low
WL:
ldi YL,low((240*SYSCLK)/(1000000*6))
ldi YH,high((240*SYSCLK)/(1000000*6));loop cycle = 6
TR3: SBIC DS1wire_PIN,DS1wire ;[1/2]
RJMP WH ;[2] Exit loop if line hi
sbiw YL,1 ;[2]
BRNE TR3 ;[1/2] us wait with data low
WH:
ldi YL,low((480*SYSCLK)/(1000000*4))
ldi YH,high((480*SYSCLK)/(1000000*4))
TR4: sbiw YL,1 ;[2]
BRNE TR4 ;[1/2] us wait with data low
;
****************************************************************************
;******* TOUCHBYTE
;
****************************************************************************
;R0-ban megadott byte-ot kikuldi a touchmemory-nak
;es szimultan beolvas egy byte-ot onnan az R1-be
;Hasznalja a R17, R16 R3, R2, X
;
TouchByte:
LDI R17,8 ;[1]
BIT_LOOP:
ROR R1 ;[1]
RCALL TOUCHBIT ;[3]
ROR R0 ;[1]
DEC R17 ;[1]
BRNE BIT_LOOP ;[1/2]
RET ;[1]
TOUCHBIT:
sbi DS1wire_DIR,DS1wire ;[2] Start Window line = L,
1us <= Tlowr <= 15us
ldi YL,low((2*SYSCLK)/(1000000*4)) ;[1] 2us
ldi YH,high((2*SYSCLK)/(1000000*4)) ;[1] loop cycle = 4
BW0: sbiw YL,1 ;[2]
BRNE BW0 ;[1/2] eddig
IN R2,DS1wire_PIN ;[1]
BST R2,DS1wire ;[1]
BLD R1,7 ;[1]
;***********************************************************************
;.......................................................................
;Read ROM
; In: X = address
; Out:
;c=1 Chip kiolvasva
;c=0 Chip nincs
;(Beolvas egy chippet az X-ban megadott cimre)
;
;Hasznalja a R18, R17, R16, R3, R2, R0;
;.......................................................................
ReadDS:
LDI XL,LOW(DSRD)
LDI XH,HIGH(DSRD) ;ide olvassa DS Chipet
clr R16
sts CRC,R16 ;CRC=0
rcall TouchReset
BRCS RDS1 ;ESZKOZ A BUSZON VAN
CLC
RET
RDS1:
LDI R16,DSReadROM ;SEARCH ROM COMMAND
MOV R0,R16
LDI R19,7 ;7-SZER OLVASUNK BE
RCALL TouchByte
RDS2: LDI R16,0xFF ;BEOLVASUNK 8 BITET
MOV R0,R16
RCALL TouchByte
ST X+,R1
RCALL CRCGEN
DEC R19
BRNE RDS2
LDI R16,0xFF ;BEOLVASSUK A CRC-t
MOV R0,R16
RCALL TouchByte
ST X+,R1
ldi YL,low((480*SYSCLK)/4000000)
ldi YH,high((480*SYSCLK)/4000000)
RDS3: sbiw YL,1
brne RDS3
SEC ;CHIP RENDBEN
RET
;***********************************************************************
;.......................................................................
;Read Scratchpad
; In: X = address
; Out:
;c=1 Chip kiolvasva
;c=0 Chip nincs
;(Beolvassa a Scratchpadot az X-ban megadott cimre)
;
;Hasznalja a R19, R18, R17, R16, R3, R2, R0; X
;.......................................................................
ReadScratchpadMem:
LDI XL,LOW(DSRDMem)
LDI XH,HIGH(DSRDMem) ;ide olvassa DS Chipet
ldi R16,DSReadScratchpad
mov R0,R16
RCALL TouchByte
clr R16
sts CRC,R16 ;CRC=0
ldi YL,low((480*SYSCLK)/4000000)
ldi YH,high((480*SYSCLK)/4000000)
RDS3s: sbiw YL,1
brne RDS3s
RET
;***********************************************************************
;.......................................................................
;Convert Temperature to digital
; In: -
; Out: -
;c=1 Chip convert ok
;c=0 Chip none
;
;Hasznalja a R18, R17, R16, R3, R2, R0; SWTmr0
;.......................................................................
ConvTemp:
LDI R16,DSConvertTemp ;Convert T Command
MOV R0,R16
RCALL TouchByte
;*************************************************************************
;.........................................................................
; DS1990A CRC GENERATOR
;IN: R1
;USE: R21,R20, R4,R3, R0, R18
;.........................................................................
CRCGEN: PUSH R1
LDI R20,8
LDI R18,0x18
PUSH R1
POP R1
RET
;*************************************************************************
;.........................................................................
; wait until Dallas 1-wire device is on bus
;IN:
;USE:
;.........................................................................
EszkVan: CLI
rcall TouchReset
rcall ReadDS
SEI
brcs EszkVan ;mig eszkoz van a buszon, addig nem
megy tovabb
;*************************************************************************
;.........................................................................
; Extend DS1920 & DS1820 temperature
;IN:
; out R23:R22 - temperature
;USE:
;
;Tc=8T-2+(8*Count-8*Remainder)/8Count
;.........................................................................
ComuteT: LDI ZL,LOW(DSRDMem)
LDI ZH,HIGH(DSRDMem) ;ide olvassa DS Chipet
SUB dd16uL,R22
SBC dd16uH,R23
MOV R0,dv16uL
OR r0,dv16uH
BRNE DIV1 ;0-VAL NEM OSZTUNK
LDI R16,0
LDI R17,0
RJMP LKI1
LKI1: CLC
SBCI dres16uL,2
SBCI dres16uH,0 ;eredmeny-2
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
http://avr-asm.tripod.com/dallas1.html (1 of 2)1/20/2009 9:03:56 PM
16 BIT MATH (AVR 202)
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
;
*****************************************************************************
;
; RTL ISR Register Bits
;
;
****************************************************************************/
.EQU ISR_RST = 7
.EQU ISR_RDC = 6
.EQU ISR_OVW = 4
.EQU ISR_PTX = 1
.EQU ISR_PRX = 0
;
*****************************************************************************
;
; RTL Register Initialization Values
;
;
****************************************************************************
;RCR : accept broadcast
packets and packets destined to this MAC
; drop short frames
and receive errors
.equ RCR_INIT = 0x04
;buffer boundaries -
transmit has 6 256-byte pages
; receive has 26 256-byte
pages
; entire available packet
buffer space is allocated
.equ TXSTART_INIT = 0x40
.equ RXSTART_INIT = 0x46
.equ RXSTOP_INIT = 0x60
;
*********************************************************
;* Receive RTL8019's Ring Buffer Page Header Layout
;* This is the 4-byte header that resides infront of
the
;* data packet in the receive buffer.
;
*********************************************************
.equ enetpacketstatus= 0x00
.equ nextblock_ptr = 0x01
.equ enetpacketLenL = 0x02
.equ enetpacketLenH = 0x03
;
*****************************************************************************
;
; Ethernet constants
;
;
****************************************************************************
.equ ETHERNET_MIN_PACKET_LENGTH = 0x3C
.equ ETHERNET_HEADER_LENGTH = 0x0E
.equ IP_TCP_HEADER_LENGTH = 40
.equ TOTAL_HEADER_LENGTH = IP_TCP_HEADER_LENGTH
+ETHERNET_HEADER_LENGTH
;
***************************************************************************
.ESEG
;
***************************************************************************
.DSEG
; packet[LANBUFSIZE]
;
; The packet array is used to hold incoming and
outgoing packets.
; The device driver fills this with incoming packets.
ETHADDR: .byte 6
;
***************************************************************************
.CSEG
;*****************************************************
;** SetLANToActive
;**
;** IN: -
;**
;** Out: -
;*
;* Alt: R16
;*
;* Description: Sets LAN to Active & SRAM to Inactive
;*
;
SetLANToActive:
SBI RAMCS_PORT,RAMCS
nop
CBI LANCS_PORT,LANCS
nop
ret
;*****************************************************
;** SetLANToInactive
;**
;** IN: -
;**
;** Out: -
;*
;* Alt: R16
;*
;* Description: Sets LAN to Inactive LANCS=H
;*
;
SetLANToInactive:
SBI LANCS_PORT,LANCS
nop
ret
;*****************************************************
;** SetISAReset
;**
;** IN: R0 -> 1 ISA Reset, 0 Normal mode
;**
;** Out: -
;*
;* Alt: -
;*
;* Description: Sets ISA RESET Line to R0; 0 = low, 1 =
hi
;*
;
SetISAReset:
sbrs R0,0
CBI LANRES_PORT,LANRES
sbrc R0,0
SBI LANRES_PORT,LANRES
nop
ret
;*****************************************************
;** Wait1ms
;**
;** In: R16 - 16*1ms varakozas
;**
;** Out: -
;**
;**
;** Alt R16, XL,XH
;**
;** Description: wating for R16 * 1 ms
;*
Wait1ms:
ldi XL,low(SYSCLK/(5*1000))
ldi Xh,high(SYSCLK/(5*1000))
Waitx1: sbiw XL,1 ;[2] \
nop ;[1] - 5 cycles in
loop
brne Waitx1 ;[2] /
dec R16
brne Wait1ms
ret
;******************************************************
;** RTLHW_Reset
;**
;** In: -
;**
;** Out: -
;**
;** ALt: R0, R16, XL, XH
;**
;** Description: Power-up initialization of the RTL8019
and ISA
;*
RTLHW_Reset:
rcall SetLANToInactive
clr R0
inc R0
rcall SetISAReset
ldi R16,10
rcall Wait1ms ;10ms
warakozas
clr R0
rcall SetISAReset
ret
;
*****************************************************************************
;** RTLreadReg
;**
;** IN: R16 - RTL_ADDRESS offset
;**
;** Out: R17 - register data
;**
;** Alt: -
;**
;** Description: Reads byte from RTL8019 register
;*
RTLReadReg:
rcall SetLANToActive
push XL
push XH
ldi XL,low(NICBASE)
add XL,R16
ldi XH,high(NICBASE)
ldi R17,0
adc XH,R17 ;X
= NIC real address to ISA
ld R17,X
rcall SetLANToInactive
pop XH
pop XL
ret
;
*****************************************************************************
;** RTLWriteReg
;**
;** IN: R16 - RTL_ADDRESS offset
;** R17 - RTL_DATA
;**
;** Out: -
;**
;** Alt: R0
;**
;** Description: Writes byte to RTL8019 register.
;*
RTLWriteReg:
rcall SetLANToActive
push XL
push XH
clr R0
ldi XL,low(NICBASE)
add XL,R16
ldi XH,high(NICBASE)
adc XH,R0 ;X
= NIC real address to ISA
st X,R17
rcall SetLANToInactive
pop XH
pop XL
ret
;
***********************************************************************
;** RTL8019_Init
;**
;** IN: -
;**
;** Out: -
;**
;** ALt: R0, R16, XL, XH
;**
;* Description: Sets up the RTL8019 NIC hardware
interface, and initializes
;* the buffers and configuration of the NIC
;
RTL8019_Init:
rcall RTLHW_Reset
;do soft
reset & clear pending interrupt
ldi R16,NICISR ;clear
Interrupt register
rcall RTLReadReg
ldi R16,NICISR
rcall RTLWriteReg
; CONFIGx
ldi R16,NICCR
ldi R17,0xC0 ;select
Page3
rcall RTLWriteReg
ldi R16,0x04
ldi R17,0b10000000 ;IRQ0, Base
0x300
rcall RTLWriteReg
ldi R16,0x05
ldi R17,0b00100000 ;
AutoDetect, ROM Disabled
rcall RTLWriteReg
ldi R16,0x06
ldi R17,0b00010000 ;
Halfduplex, LED0 - link, LED1 - RX led2 - TX
rcall RTLWriteReg
ldi R16,0x0D
ldi R17,0x00
rcall RTLWriteReg
ldi R16,NICCR9346
ldi R17,0x00 ;End Config
rcall RTLWriteReg
; !!!!
ldi R16,NICDCR
ldi R17,DCR_INIT ;0x58
Normal Operation, FIFO Treshold, Auto Init Remote
rcall RTLWriteReg
ldi R16,NICRBCR0
ldi R17,0x00
rcall RTLWriteReg
ldi R16,NICRBCR1
rcall RTLWriteReg ;Remote DMA
Byte Count =0x0000
ldi R16,NICRCR
ldi R17,0x04 ;only
packets with broadcast
rcall RTLWriteReg ;
destination address are accepted
ldi R16,NICTPSR
ldi R17,TXSTART_INIT ;Transmit
Page Start Register=40
rcall RTLWriteReg
ldi R16,NICTCR
ldi R17,0x02 ;Internal
loopback
rcall RTLWriteReg
ldi R16,NICPSTART
ldi R17,RXSTART_INIT ;page
address of the receive buffer ring = 46
rcall RTLWriteReg
ldi R16,NICBNRY ;utolso
olvasott page = 46
rcall RTLWriteReg
ldi R16,NICPSTOP
ldi R17,RXSTOP_INIT ;stop page
address of the receive buffer ring = 60
rcall RTLWriteReg
ldi R16,NICCR
ldi R17,0x61 ;Stop &
Abort DMA
rcall RTLWriteReg
ldi R16,2 ;2ms
varakozas
rcall Wait1ms
ldi R16,NICCURR
ldi R17,RXSTART_INIT ;Rx Page =
46
rcall RTLWriteReg
adiw ZL,1
call EERead
sts ETHADDR+1,R0
mov R17,R0
ldi R16,NICPAR1
rcall RTLWriteReg
adiw ZL,1
call EERead
sts ETHADDR+2,R0
mov R17,R0
ldi R16,NICPAR2
rcall RTLWriteReg
adiw ZL,1
call EERead
sts ETHADDR+3,R0
mov R17,R0
ldi R16,NICPAR3
rcall RTLWriteReg
adiw ZL,1
call EERead
sts ETHADDR+4,R0
mov R17,R0
ldi R16,NICPAR4
rcall RTLWriteReg
adiw ZL,1
call EERead
sts ETHADDR+5,R0
mov R17,R0
ldi R16,NICPAR5
rcall RTLWriteReg
ldi R16,NICCR
ldi R17,0x21 ;Stop NIC,
Abort DMA
rcall RTLWriteReg
ldi R16,NICDCR
ldi R17,DCR_INIT ;58 Normal
operation...
rcall RTLWriteReg
ldi R16,NICCR
ldi R17,0x22 ;Start
Command, DMA abort
rcall RTLWriteReg
ldi R16,NICISR
ldi R17,0xFF
rcall RTLWriteReg ;Clear
pending Interrupt
ldi R16,NICIMR
ldi R17,IMR_INIT ;11,
Interrupt Enable
rcall RTLWriteReg ;packet
received with no errors
;receive
buffer has been exhausted
ldi R16,NICTCR
ldi R17,TCR_INIT ;00 -
Normal operation
rcall RTLWriteReg
ldi R16,NICCR
ldi R17,0x22
rcall RTLWriteReg ;start the
NIC
ret
;
***********************************************************************
;** RTL8019endPacketSend
;**
;** In : -
;**
;**
;** Alt :
;**
;* Description: Ends a packet send operation and
instructs the NIC to transmit
;* the frame over the network
;
RTL8019endPacketSend:
ldi R16,NICCR ;send the contents
of the transmit buffer onto the network
ldi R17,0x24
rcall RTLWriteReg
;clear the remote
DMA interrupt
ldi R16,NICISR
ldi R17,(1< sendPacketLength
push R16 ;R17:R16 - >
packetLength
ldi R16,NICCR
ldi R17,0x22
rcall RTLWriteReg ;start the NIC
;load beginning
page for transmit buffer
ldi R16,NICTPSR
ldi R17,TXSTART_INIT
rcall RTLWriteReg
invpointer:
ldi R16,NICBNRY
ldi R17,RXSTART_INIT
rcall RTLWriteReg
ldi R16,NICCR
ldi R17,0x62
rcall RTLWriteReg
ldi R16,NICCURR
ldi R17,RXSTART_INIT
rcall RTLWriteReg
ldi R16,NICCR
ldi R17,0x22
rcall RTLWriteReg
clc
ret ;Z= meg
mindig 0!!
jopointer:
ldi R16,NICRBCR0 ;initiate
DMA to transfer the RTL8019 packet header
ldi R17,0x04
rcall RTLWriteReg
ldi R16,NICRBCR1
ldi R17,0x00
rcall RTLWriteReg ;Remote
Byte Count = 4
ldi R16,NICRSAR0
ldi R17,0x00
rcall RTLWriteReg
ldi R16,NICRSAR1
mov R17,R20
rcall RTLWriteReg ;Remote
start address= Start boundary page
ldi R16,NICCR
ldi R17,0x0A
rcall RTLWriteReg ;Start
Remote Read DMA
rcall WaitToDMA
lds ZL,pageheader+enetpacketLenL
lds ZH,pageheader+enetpacketLenH ;
Z=rxlen
lds R16,pageheader+nextblock_ptr ;
nextPage
sts nextPage,R16 ;
eltaroljuk ,aborthoz kell
ldi R17,4
sts currentRetreiveAddress+0,R17
sts currentRetreiveAddress+1,R20 ;
innen folytatjuk majd a kiolvasast (offset cim)
ldi R18,RXSTOP_INIT
cp R16,R18
brsh pageErr1
ldi R18,RXSTART_INIT
cp R16,R18
brcs pageErr1 ;if((nextPage >=
RXSTOP_INIT) || (nextPage < RXSTART_INIT))
clr R18
sub ZL,R17
sbc ZH,R18 ;rxlen-4
sec
ret
pageErr1: clr Zl
clr ZH
clc
ret
;
*****************************************************************************
; Device Manager
; A foprogrambol ezek hivhatoak
;
*****************************************************************************
;* RTL8019dev_send
;*
;* In:
;*
;* Out:
;*
;* Alt:
;*
;* Description: Sends the packet contained in
packet over the network
;
RTL8019dev_send:
ldi R16,low(LANBUFSIZE)
ldi R17,high(LANBUFSIZE)
RTL8019dev_sendA:
push R16
push R17
rcall RTL8019beginPacketSend
ldi XL,Low(packet)
ldi XH,high(packet)
pop ZH
pop ZL
rcall RTL8019sendPacketData
rcall RTL8019endPacketSend
ret
;
*****************************************************************************
;* RTL8019dev_poll
;*
;* In: -
;*
;* Out: Z = Length of the packet retreived, or zero if
no packet retreived
;* Y = Address of retreived packet
;* c flag = 0, no packet
;*
;* Description: Polls the RTL8019 looking for an
overflow condition or a new
;* packet in the receive buffer. If a new
packet exists and will
;* fit in packet, it is retreived, and the
length is returned.
;* A packet bigger than the buffer is discarded
;
*****************************************************************************/
;
RTL8019dev_poll:
rcall RTL8019beginPacketRetreive ;Z =
packetLength
brcs Vanpacket2 ;if there's
no packet or an error
;exit
without ending the operation
ret
Vanpacket2:
cpi ZL,low(LANBUFSIZE+1)
ldi R16,high(LANBUFSIZE+1) ;drop
anything too big for the buffer
cpc ZH,R16
brcs PacketSizejo
;Ezt el
kell dobni, tul nagy
rcall RTL8019endPacketRetreive
clr ZL
clr ZH
clc
ret
PacketSizejo:
push ZL ;copy the
packet data into the IP packet buffer
push ZH
ldi XL,low(packet)
ldi XH,high(packet)
rcall RTL8019retreivePacketData
rcall RTL8019endPacketRetreive
pop ZH
pop ZL
sts pageheader+enetpacketLenL,ZL
sts pageheader+enetpacketLenH,ZH
ldi YL,low(packet)
ldi YH,high(packet)
sec
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
TEA PROTOCOL
HOME
RETRO_DAN
;(C)2005 wek http://www.efton.sk
ASM FORUM ;free for personal use
ASM MATH ;for commercial use, please contact [email protected]
TUTORIAL #1
;implementation of original TEA algorithm by
TUTORIAL #2 Needham&Wheeler for AVR
TUTORIAL #3 ;
MATH 202
MATH 202 .dseg
DEC ASCII
ydata: .byte 4
INT ASCII zdata: .byte 4
HX2ASC
;register definitions
AVG8 222 .def ZL = r30
FFT7 .def ZH = r31
.def YL = r28
COPY 102 .def YH = r29
LPM 108
EPROM 100 .def tmp0 = r1
SER EPROM .def tmp1 = r2
.def tmp2 = r3
DFLASH AT45
.def tmp3 = r4
FLASH CARD .def tmp4 = r5
.def tmp5 = r6
VFX SMIL
.def tmp6 = r7
VFX MEM .def tmp7 = r8
SORT 220 .def tmp8 = r9
eor tmp0,tmp5
eor tmp1,tmp6
eor tmp2,tmp7
eor tmp3,tmp8
dec RoundCnt
brne TeaRoundA
ret
TeaRoundA:
sbrs RoundCnt,0
rjmp TeaRound
rjmp TeaSubRound
Key:
; .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db $0f,$1e,$2d,$3c
.db $4b,$5a,$69,$78
.db $87,$96,$a5,$b4
.db $c3,$d2,$e1,$f0
;***** Code
wait_edge1:
sbic ACSR,ACO ;if output is high
rjmp wait_edge1 ; wait
we1_1: sbis ACSR,ACO ;if output is low
rjmp we1_1 ; wait
;
***************************************************************************
;*
;* "wait_edge2"
;*
;* This piece of code waits until the output of the
comparator (the ACO-bit
;* in ACSR) goes high. This is a more secure solution,
since the interrupt
;* flag is polled. This allows the user to insert code
within the wait loop
;* because hardware "remembers" pulses of shorter
duration than the polling
;* interval. Another positive feature is that there is
no need to wait for
;* a preceeding negative edge.
;*
;* Number of words :5
;* Number of cycles :Inital setup :2
;* Flag clearing:1
;* Loop :4
;* Response time:3 - 5
;* Low registers used :None
;* High registers used :None
;*
;
***************************************************************************
;***** Code
wait_edge2:
sbi ACSR,ACIS0
sbi ACSR,ACIS1 ;enable interrupt on rising
output edge
;***** Wait
;
***************************************************************************
;*
;* "ana_init"
;*
;* This code segment enables Analog Comparator
Interrupt on output toggle.
;* The program then enters an infinite loop.
;* The 16-bit counter is cleared prior to enabling the
interrupt.
;*
;* Performance figures apply to interrupt
initialization only.
;*
;* Number of words :4
;* Number of cycles :5
;* Low registers used :None
;* High registers used :1 (temp)
;*
;
***************************************************************************
;***** Code
ana_init:
clr cntL
clr cntH
forever:rjmp forever
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
StartADC:
in ZL,ADCSRA
ori ZL,0b11011000
out ADCSRA,ZL
ret
;****************************************
;ADC Conversion Complete Handler
;
;
ADC:
PUSH ZL
PUSH ZH
IN ZL,SREG
PUSH ZL
push R0
in ZL,ADCL
push ZL
in R0,ADCH
push R0
in ZL,ADMUX
inc ZL
andi ZL,7
out ADMUX,ZL ;kovetkezo
csatorna kivalasztva
clr R0
dec ZL
andi ZL,7
add ZL,ZL
ldi ZH,Low(ADCCH0+2)
add ZL,ZH
ldi ZH,high(ADCCH0+2)
adc ZH,R0
pop R0
st -Z,R0
pop R0
st -Z,R0
pop R0
POP ZL
OUT SREG,ZL
POP ZH
POP ZL
RETI
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
**************************************************************************
;*
;* convert_init - Subroutine for A/D converter
initialization
;*
;*
;* DESCRIPTION
;* This routine initializes the A/D converter. It sets
the timer and the
;* analog comparator. The analog comparator interrupt
is being initiated by
;* a rising edge on AC0. To enable the A/D converter
the global interurrupt
;* flag must be set (with SEI).
;*
;* The conversion complete flag (t) is cleared.
;*
;* Total number of words : 6
;* Total number of cycles : 10
;* Low register usage : 0
;* High register usage : 1 (result)
;* Status flag usage : 0
;*
;
**************************************************************************
convert_init:
ldi result,$0B ;Initiate comparator
out ACSR,result ;and enable
comparator interrupt
;
**************************************************************************
;*
;* AD_convert - Subroutine to start an A/D conversion
;*
;* DESCRIPTION
;* This routine starts the conversion. It loads the
offset value into the
;* timer0 and starts the timer. It also starts the
charging of the
;* capacitor.
;*
;*
;* Total number of words : 7
;* Total number of cycles : 10
;* Low register usage : 0
;* High register usage : 1 (result)
;* Status flag usage : 1 (t flag)
;*
;
**************************************************************************
AD_convert:
ldi result,preset ;Clear counter
out TCNT0,result ;and load offset
value
;
**************************************************************************
;*
;* Example program
;*
;* This program can be used as an example on how to set
up the A/D
;* converter properly.
;* NOTE! To ensure proper operation, make sure the
discharging period
;* of the capacitor is longer than 200us in front of
each conversion.
;* The results of the conversion is presented on port B.
;* To ensure proper discharging we have added a delay
loop. This loop is
;* 11 thousand cycles. This will give a 550us delay
with a 20MHz oscillator
;* (11ms with a 1MHz oscillator).
;*
;
**************************************************************************
RESET:
rcall convert_init ;Initialize A/D
converter
sei ;Enable global
interrupt
ldi result,$ff ;set port B as
output
out DDRB,result
Delay: clr result ;Clear temp
counter 1
ldi temp,$f0 ;Reset temp counter
2
loop1: inc result ;Count up
temp counter 1
brne loop1 ;Check if inner
loop is finished
inc temp ;Count up temp
counter 2
brne loop1 ;Check if delay is
finished
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
AVR ISP
ISP 2313 ;Port B pins
.equ AIN0 =0
ISP 1200 .equ AIN1 =1
AVR SPI .equ Ref1 =2
.equ Ref2 =3
I2C 300 .equ LED =4
I2C 302 .equ T =7
I2C TWI26
.equ PRESC =2 ;Timer clocked at CK/8
I2C/TWI 128 .equ VrefAddr=0 ;EEPROM Address holding Vref
I2C/TWI AT8
DALLAS-1W .include "1200def.inc"
DALLAS CRC
.cseg
ETHNET 8019 .org 0
TEA rjmp reset ;Reset handler
reti
ADC 128
ADC 10B .org OVF0addr
;** Timer/counter 0 overflow interrupt
ADC 400
******************************
ADC 401 T0_int: inc TH ;Increase
THERM 232 timer high-byte
reti
IRD 410
LCD HD44
;*** Reset handler
LCD 2313 **************************************************
LCD44 2313 reset: sbi DDRB,LED ;PB4 and
ser temp ;Port D as output,
KBD 240 used to
MUX 242 out DDRD,temp ;drive LEDs
KBD PS2
ldi temp,(1< multiplier
KBD PC/128 ldi temp,128 ;128 ->
PS2 EMU multiplicand ( = 2.5 volts)
mov mc9u,temp
BOOT MG8 rcall mpy9u ;Tref x 128
BOOT DR8
clr divH ;(Tref x 128)
ALM CLK mov divL,TinL ; -----------
CLOCK 8564 rcall div17u ; Tcal
90 DAYS
ldi temp,VrefAddr ;Store Vref
DELAYS out EEAR,temp
out EEDR,dresL
CALL ID
sbi EECR,EEWE
DTMF 314
PWM 6CH calibrate1: sbic EECR,EEWE
rjmp calibrate1
PWM 10K
ENCODE
STH-11 ;Main program
ATMEL CORP main: cbi PORTB,T ;Turn off
pull-up on T-pin
AVR
BUTTERFLY ldi temp,VrefAddr ;Read Vref from
AVR BOOK EEPROM
out EEAR,temp
sbi EECR,EERE
in Vref,EEDR
tst dresH
breq write
out PORTD,dresL
rol dresL
brcs wr1
cbi PORTB,LED
rjmp loop
ret
ret
;
********************************************************************
;*
;* This routine divides a 17 bit number (carry:didH:
didLL) on
;* a 16 bit number (divH:divL).
;* The result is placed in (dresH:dresL)
;*
;* The carry flag must contain the 17th bit of the
divident before
;* the routine is executed.
;*
;* The routine is based on the div16u - 16/16 Bit
Unsigned Division
;* routine found in the avr200.asm application note file
;*
;
********************************************************************
d17u_2: sec
d17u_3: rol didL ;shift left
dividend
rol didH
dec temp ;decrement counter
brne d17u_1 ;if done
ret ; return with
value in didL
;
***************************************************************************
;*
;* "mpy9u" - 9x8 Bit Unsigned Multiplication
;*
;* This subroutine multiplies the two register
variables (carry:mp9u) and mc9u.
;* The result is placed (carry:m8uH:m8uL)
;*
;* Number of words :11 (return included)
;* Number of cycles : (return included)
;* Low registers used :3 (mp9u,mc9/m9uL,m9uH)
;* High registers used :1 (temp)
;*
;* Note: Result Low byte and the multiplier share the
same register.
;* This causes the multiplier to be overwritten by the
result.
;*
;
***************************************************************************
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
CRC 236
XMODEM REC .EQU LEDPORT = DDRB
.EQU LED = 3 ;A LED bitcime
UART 304
UART 305
;SPI selector - 00 LCD
UART 128
.EQU SS0PORT= DDRB
UART BUFF .EQU SS0= BP4
USB 232 .EQU SS1PORT= DDRB
.EQU SS1= BP2
AVR ISP
ISP 2313
;
ISP 1200 **************************************************************************
AVR SPI ;* UART Def
.EQU BaudRate=11 ;11 - 9600
I2C 300 ;7 - 14400
I2C 302 ;5 - 19200
;1 - 57600
I2C TWI26
I2C/TWI 128
I2C/TWI AT8
;
DALLAS-1W ***************************************************************************
DALLAS CRC ;***** Divide Subroutine Register Variables
.macro Select_LCD
CBI SS0PORT+1,SS0
cbi SS1PORT+1,SS1
.endm
;
***************************************************************************
;*
;* SPI MACROS
;* Program Macros
.macro AT_active
cbi portb,ATss
.endm
.macro AT_inactive
sbi portb,ATss
.endm
.macro sck_hi
sbi portb,sck
.endm
.macro sck_lo
cbi portb,sck
.endm
.macro mosi_hi
sbi portb,mosi
.endm
.macro mosi_lo
cbi portb,mosi
.endm
;.macro addi
; subi @0, -@1 ;subtract the negative of an immediate value
;.endm
;
******************************************************************************
;**** CONST
;FLAGS
.EQU Active = 2 ;Imo Active bit
;
******************************************************************************
;**** VARIABLES
.DSEG
DS1: .BYTE 1 ;Flagbitek
; 0. = 1 RPM overflow
; 1. = 1 Velocity overflow
; 2. = 1 Immo. Active
; 4. = 1 LED kijelzo frissites kell
;*Variables Offset to Y
;
**************************************************************************************
.ESEG
KEY1: .DB 0x01
.DB 0x88
.DB 0xDD
.DB 0x07
.DB 0x02
.DB 0x00
.DB 0x00
KEY2: .DB 0x01
.DB 0x6D
.DB 0xB9
.DB 0x07
.DB 0x02
.DB 0x00
.DB 0x00
;
*****************************************************************************
;**** I N T E R R U P T S
;****
;
*****************************************************************************
.CSEG
rjmp RESET ;Reset Handle
rjmp EXT_INTO ;IRQ0 Handle
rjmp EXT_INT1 ;IRQ1 Handle
rjmp TIM_CAPT1 ;Timer1 capture Handle
rjmp TIM_COMP1 ;Timer1 compare Handle
rjmp TIM_OVF1 ;Timer1 overflow Handle
rjmp TIM_OVF0 ;Timer0 overflow Handle
rjmp UART_RXC ;UART RX Complete Handle
rjmp UART_DRE ;UDR Empty Handle
rjmp UART_TXC ;UART TX Complete Handle
rjmp ANA_COMP ;Analog Comparator Handle
;***********
;* RESET
;***********
RESET: CLI ;GLOBAL INTERRUP DIS.
LDI R16,RAMEND
OUT SPL,R16 ;STACK A BELSO RAM VEGETOL INDUL LEFELE
LDI R16,2
OUT TIMSK,R16 ;7. = 1 TC1 OWRF EN. *
;6. = 1 TC1 COMP MATCH EN.
;3. = 1 TC1 INP CAPTURE EN.
;1. = 1 TC0 OWRF EN. *
LDI R16,0
OUT TCCR1A,R16 ;TC1 Disconected from OC1 pin, PWM Dis.
LDI R16,3
OUT TCCR1B,R16 ;Input Capture Dis., f=CLK/64
LDI R16,T0Freq
OUT TCNT0,R16 ;50Hz
LDI R16,5
OUT TCCR0,R16 ;f(TC1)=CLK/1024
LDI YL,LOW(DS1)
LDI YH,HIGH(DS1) ;BAZIS 'X' +0
LDI R16,0
STD Y+CNT1L,R16
STD Y+CNT1H,R16 ;CNT1=0
LDI R16,(1< R0
ADIW ZL,1
MOV R16,R0
STD Y+TXT+0,ZL
STD Y+TXT+1,ZH
CPI R16,0
BRNE MoreTXT ;VAN MEG SZOVEG
LDI R16,low(UReti)
STD Y+UTx+0,R16
LDI R16,high(UReti)
STD Y+UTx+1,R16 ;UART TX INT. ADDR
CPSE R16,R16 ;AZERT, HOGY
AKOVETKEZO SOR KIMARADJON
;*************************************************************************
;* Text Const
;*
Copyr: .DB "(C) 2000, DS1820 Thermometer V1.0 ", 10,13
Ready: .DB "Ready>>",0
Hiba: .DB "Error..",10,13,0
;***********************************************************************
;***********************************************************************
;******** M A I N ********
;******** ********
;***********************************************************************
Main: LDI R16,10
STD Y+CNT1L,R16
LDI R16,0
STD Y+CNT1H,R16 ;CNT1=25 0.5s
wait: ;SLEEP
ldd R16,Y+TEMP
CPI R16,'R'
BREQ WHTROM
CPI R16,'r'
BREQ WHTROM
CPI R16,'T'
BREQ RDTH
CPI R16,'t'
BREQ RDTH
rjmp Csokkent
RDTH: cli
rcall ReadTh
sei
brcc CMDsEND ;ha nincs eszkoz a buszon, akkor
kihagy
MOV R0,R23
rcall TOUART
MOV R0,R22
rcall TOUART
LDI XL,LOW(DSRD)
LDI XH,HIGH(DSRD) ;ide olvasta a DS Chipet
LDI R19,8 ;8 byteot kuldunk ki
rjmp WHTR1
WHTROM: CLI
rcall ReadROM
SEI
brcc CMDsEND ;ha nincs eszkoz a buszon, akkor
kihagy
WHTR1: LD R16,X+
MOV R0,R16
rcall TOUART
Wt4: SBIS USR,UDRE ;a kovetkezo kimarad, ha a TX
reg ures
RJMP Wt4
LDI R16,' '
OUT UDR,R16
dec R19
BRNE WHTR1
;Kell-e villogni?
LDD R16,Y+FLAGS
SBRS R16,Active ;a kovetkezo kimarad ha az Active=1
rjmp Main
; Led villogtato
;CRC-t ellenorzi
; LD R1,X+ ;olvasott CRC
; LDD R0,Y+CRCOff ;szamolt CRC
; CP R1,R0
; BREQ CRCOK ;GoodCRC
MOV R16,R0
SWAP R16
ANDI R16,0x0F
CPI R16,10
BRCS Kicsi1
ADD R16,R18
Kicsi1: ADD R16,R17
OUT UDR,R16
MOV R16,R0
ANDI R16,0x0F
CPI R16,10
BRCS Kicsi0
ADD R16,R18
Kicsi0: ADD R16,R17
OUT UDR,R16
ret
.include "div16.asm"
.include "SPI.asm"
;************************************************************************
;*********************** 1-Wire Bus *************************************
;************************************************************************
;------------------------------------------------------------------------
;Kiolvasott DS chip tartalmat osszehasonlitja az EEpromban taroltakkal
;
; R14 a KEY Offsetcime
;
;C=0 Nem jo
;C=1 Kulcs jo
DScomp:
LDI XL,LOW(DSRD)
LDI XH,HIGH(DSRD) ;ide olvassa DS Chipet
OUT EEAR,R24 ;EEPROM address
;***********************************************************************
;.......................................................................
;Read DS1820
;c=1 Chip kiolvasva
;c=0 Chip nincs
;(Beolvas egy chippet az Y-ban megadott cimre)
;
;Hasznalja a R18, R17, R16, R3, R2, R0;
;.......................................................................
ReadROM:
LDI XL,LOW(DSRD)
LDI XH,HIGH(DSRD) ;ide olvassa DS Chipet
LDI R16,0
STD Y+CRCoff,R16 ;CRC=0 ;
RCALL TouchReset
BRCS RDS1 ;ESZKOZ A BUSZON VAN
CLC
RET
LDI R19,0xFF
RDS3: DEC R19
BRNE RDS3
SEC ;CHIP RENDBEN
RET
;
****************************************************************************
;******* TOUCHBYTE
;
****************************************************************************
;
;R0-ban megadott byte-ot kiküldi a touchmemory-nak
;és szimultán beolvas egy byte-ot onnan az R1-be
;Hasznalja a R17, R16 R3, R2
;
TouchByte:
LDI R17,8 ;[1]
BIT_LOOP:
ROR R1 ;[1]
RCALL TOUCHBIT ;[3]
ROR R0 ;[1]
DEC R17 ;[1]
BRNE BIT_LOOP ;[1/2]
RET ;[1]
TOUCHBIT:
SBI DS1820_PORT,DS1820_BIT ;[2]
LDI R16,3 ;[1]
BW0: DEC R16 ;[1]
BRNE BW0 ;[1/2]
SBRC R0,0 ;[1/2]
CBI DS1820_PORT,DS1820_BIT ;[2]
LDI R16,8 ;[1]
BW1: DEC R16 ;[1]
BRNE BW1 ;[1/2]
IN R2,DS1820_PORT-1 ;[1]
BST R2,DS1820_BIT ;[1]
BLD R1,7 ;[1]
LDI R16,26 ;[1]
TCHL: DEC R16 ;[1]
BRNE TCHL ;[1/2]
CBI DS1820_PORT,DS1820_BIT ;[2]
RET ;[4]
;
*******************************************************************************
;****** T O U C H R E S E T
;
*******************************************************************************
;
;Inicialization procedure "Reset and PreSence Pulses"
;
; Ez a rutin egy Reset jelet general a mikrovrzerlo ketiranyu DS_BIT nevu
laban,
;a Touch Memory fele es figyeli a visszajovo PreSence jelet.
;Ha a PreSence jel megerkezett, akkor C=1 kulonben C=0 (nincs eszkoz a
buszon)
;
; |-Master Rx "Presence Pulse"-|
; |---Master Reset Tx Pulse---| |----t(RSTH)---------------|
; __ t(RSTL) _____ _____ \\ ___
; \ / \ / \
; \_________________________/ \______/ \__ ...
; |-----|-------|
; t(PDH) t(PDL)
; t(R) <-- |-|
;
; 480us<=t(RSTL)< . t(RSTL)+t(R)<960us
; 480us<=t(RSTH)<
; 15us<=t(PDH)<=60us
; 60us<=t(PDL)<=240us
;
; C-flag = 1 DS1990A a buszon van
; = 0 DS1990A nincs a buszon
;
; R16
;*************************************************************************
;.........................................................................
; DS1990A CRC GENERATOR
;IN: R1
;USE: R21,R20, R4,R3, R0, R18
;.........................................................................
CRCGEN: PUSH R1
LDI R20,8
LDI R18,0x18
PUSH R1
POP R1
RET
;***********************************************************************
;.......................................................................
;Read DS1820
;c=1 Chip kiolvasva
;c=0 Chip nincs
;(Beolvas egy chippet az Y-ban megadott cimre)
;
;Hasznalja a R18, R17, R16, R3, R2, R0;
;.......................................................................
ReadTh:
LDI XL,LOW(DSRD)
LDI XH,HIGH(DSRD) ;ide olvassa DS Chipet
LDI R16,0
STD Y+CRCoff,R16 ;CRC=0
RCALL TouchReset
BRCS DSVAN ;ESZKOZ A BUSZON VAN
CLC
RET
nop
nop
nop
nop
nop
nop
nop
nop
nop
LDI R16,0
STD Y+CRCoff,R16 ;CRC=0 ;
RCALL TouchReset
BRCS DS2VAN ;ESZKOZ A BUSZON VAN
CLC
RET
DS2VAN:
LDI R16,0xCC ;Skip ROM Command
MOV R0,R16
RCALL TouchByte
nop
nop
LDI R19,0xFF
DS3T: DEC R19
BRNE DS3T
RCALL TouchReset
SEC ;CHIP RENDBEN
RET
;Tc=8T-2+(8*Count-8*Remainder)/8Count
SUB dd16uL,R22
SBC dd16uH,R23
MOV R0,dv16uL
OR r0,dv16uH
BRNE DIV1 ;0-VAL NEM OSZTUNK
LDI R16,0
LDI R17,0
RJMP LKI1
LKI1: CLC
SBCI dres16uL,2
SBCI dres16uH,0 ;eredmeny-2
;
***************************************************************************
;*
;* EERead_seq
;*
;* This subroutine increments the address stored in EEAR and reads the
;* EEPROM into the register variable "EEdrd_s".
;*
;* Number of words :8515 ; 7 + return
;* Number of cycles :8515 ; 11 + return (if EEPROM is ready)
;* Low Registers used :R0
;* High Registers used: :R24
;*
;
***************************************************************************
EERead_seq:
sbic EECR,EEWE ;if EEWE not clear
rjmp EERead_seq ; wait more
;The above sequence for EEWE = 0
;can be skipped if no write is initiated.
in R24,EEAR ;get address low 8515
inc R24 ;increment address 8515
out EEAR,R24 ;output address 8515
;
***************************************************************************
;*
;* FUNCTION
;* ena_LCD
;*
;* DESCRIPTION
;* Init data & clock lines, then assert /CS for LCD.
;*
;* CODE SIZE:
;* 4 words
;*
;
***************************************************************************
ena_LCD:
sck_lo ;(should already be there...)
mosi_lo
Select_LCD
ret
;* DESCRIPTION
;* This Application Note lists subroutines for the following
;* Divide applications. Routines are straight-line implementations
;* optimized for speed:
;*
;* 16 / 16 = 16 + 16 bit unsigned
;*
;
***************************************************************************
;
***************************************************************************
;*
;* "div16u" - 16/16 Bit Unsigned Division
;*
;* This subroutine divides the two 16-bit numbers
;* "dd16uH:dd16uL" (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)
;*
;
***************************************************************************
;***** Code
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
MATH 202
MATH 202 .equ INPUT =2 ;PD2
.equ SYS_ADDR =0 ;The system address
DEC ASCII
INT ASCII
.def S =R0
HX2ASC
.def inttemp =R1
AVG8 222 .def ref1 =R2
FFT7 .def ref2 =R3
sbic PIND,INPUT
rjmp bit_is_a_1 ;Jump if line high
;Synchronize timing
bit_is_a_0a: cp timerL,ref2 ;If no edge
within 3/4 bit time
brge fault ; exit
sbis PIND,INPUT ;Wait for rising
edge
rjmp bit_is_a_0a ;in the middle of
the bit
clr timerL
rjmp nextbit
clr timerL
;Clear remaining
bits
andi command,0b01111111
andi system,0x1F
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
ETHNET 8019
TEA
ADC 128 ;
ADC 10B ***************************************************************************
;**** VARIABLES
ADC 400
.DSEG
ADC 401
THERM 232
IRD 410 ;
LCD HD44 ***************************************************************************
.ESEG
LCD 2313
LCD44 2313
;
KBD 240 ***************************************************************************
MUX 242 ;**** CODE SEG
;
KBD PS2
***************************************************************************
KBD PC/128 .CSEG
PS2 EMU
BOOT MG8 ;*****************************************************
BOOT DR8 ;** Wait1ms
;**
ALM CLK ;** In: R16 - 16*1ms varakozas
CLOCK 8564 ;**
;** Out: -
90 DAYS
;**
DELAYS ;**
;** Alt R16
CALL ID
;**
DTMF 314 ;** Description: wating for R16 * 1 ms
PWM 6CH ;*
Wait1ms:
PWM 10K ldi XL,low(SYSCLK/(5*1000))
ENCODE ldi XH,high(SYSCLK/(5*1000))
Waitx1: sbiw XL,1 ;[2] \
STH-11 nop ;[1] - 5 cycles in
ATMEL CORP loop
brne Waitx1 ;[2] /
AVR
dec R16
BUTTERFLY brne Wait1ms
AVR BOOK ret
;*****************************************************
;** LCD_pulseE
;**
;** In: -
;**
;** Out: R0 - Data on LCDDat pin
;**
;**
;** Alt
;**
;** Description: Generate ENABLE signal to LCD
;*
LCD_pulseE:
sbi LCDEN_PORT,LCDEN ;Enable high
nop ;Wait 500ns
@16MHz
nop
nop
nop
nop
nop
nop
nop
in R0,LCDDAT_PIN
cbi LCDEN_PORT,LCDEN ;Enable
low, latch data
ret
;*****************************************************
;** LCD_Init
;**
;** In: -
;**
;** Out: -
;**
;**
;** Alt:
;**
;** Description: Initialize LCD in 4 bit mode
;*
LCD_Init:
sbi LCDEN_DIR,LCDEN ;LCD I/O
Disabled
cbi LCDEN_PORT,LCDEN
lds R16,LCDDAT_PORT
andi R16,255-LCDDAT_PORT
ori R16,0b00000011 ;3x
probalkozunk 8 bit mode-ba rakni
sts LCDDAT_PORT,R16
nop
nop
cbi LCDRS_PORT,LCDRS ;Set to
Command Reg.
cbi LCDRW_PORT,LCDRW ;read
rcall LCD_pulseE ;1
ldi R16,15
rcall Wait1ms ;wait 5ms
lds R16,LCDDAT_PORT
andi R16,255-LCDDAT_PORT
ori R16,0b00000010 ;4bit bus
mode
sts LCDDAT_PORT,R16
rcall LCD_pulseE
ldi R16,5
rcall Wait1ms ;wait 5ms
rcall LCD_Clear
ret
;*****************************************************
;** LCD_Clear
;**
;** In: -
;**
;** Out: -
;**
;**
;** Alt:
;**
;** Description:
;** Clears the display and sends the cursor home.
;
LCD_Clear:
ldi R16,0b00000001 ;Clear LCD
rcall LCD_SendCmd
ldi R16,0b00000010 ;Send the
cursor home
rcall LCD_SendCmd
ret
;*****************************************************
;** LCD_WaitBusy
;**
;** In: -
;**
;** Out: -
;**
;**
;** Alt: R0, R16
;**
;** Description:
;** Waits for the busy flag to go low. Since we're in
4-bit mode,
;** the register has to be read twice (for a total of 8
bits).
;*
LCD_WaitBusy:
push R16
lds R16,LCDDAT_DIR
andi R16,255-LCDDAT_Mask ;LCD data
bits going to input
sts LCDDAT_DIR,R16
lds R16,LCDDAT_PORT
ori R16,LCDDAT_Mask ;pull-up
sts LCDDAT_PORT,R16
rjmp LCDWait1
LCDWait0:
ldi R16,2 ;Wait min.
~1us
LCDWait01: nop
dec R16
brne LCDWait01
LCDWait1:
cbi LCDRS_PORT,LCDRS ;Set to
Command Reg.
sbi LCDRW_PORT,LCDRW ;read
rcall LCD_pulseE ;Busy Flag
read bit 7.
mov R16,R0
rcall LCD_pulseE ;lower
nibble must read
sbrc R16,3 ;Check busy
flag
rjmp LCDWait0
;*****************************************************
;** LCD_SendCmd
;**
;** In: R16 - Command byte
;**
;** Out: -
;**
;**
;** Alt: R0, R1, R16, R17
;**
;** Description:
;** Routine to write a command to the instruction
register.
;
LCD_SendCmd:
rcall LCD_WaitBusy
mov R1,R16
swap R16
andi R16,LCDDAT_Mask ;send upper
nibble first
lds R17,LCDDAT_PORT
andi R17,255-LCDDAT_Mask
or R17,R16
sts LCDDAT_PORT,R17
cbi LCDRS_PORT,LCDRS ;Set to
Command Reg.
cbi LCDRW_PORT,LCDRW ;Write
rcall LCD_PulseE ;Latch
upper nibble
mov R16,R1
andi R16,LCDDAT_Mask ;send lower
nibble
lds R17,LCDDAT_PORT
andi R17,255-LCDDAT_Mask
or R17,R16
sts LCDDAT_PORT,R17
cbi LCDRS_PORT,LCDRS ;Set to
Command Reg.
cbi LCDRW_PORT,LCDRW ;Write
rcall LCD_PulseE ;Latch
lower nibble
ret
;*****************************************************
;** LCD_SendChar
;**
;** In: R16 - character code
;**
;** Out: -
;**
;**
;** Alt: R0,R1, R16, R17
;**
;** Description:
;** Routine to write a character to the data register.
;
LCD_SendChar:
rcall LCD_WaitBusy
mov R1,R16
swap R16
andi R16,LCDDAT_Mask ;send upper
nibble first
lds R17,LCDDAT_PORT
andi R17,255-LCDDAT_Mask
or R17,R16
sts LCDDAT_PORT,R17
sbi LCDRS_PORT,LCDRS ;Set to
data Reg.
cbi LCDRW_PORT,LCDRW ;Write
rcall LCD_PulseE ;Latch
upper nibble
mov R16,R1
andi R16,LCDDAT_Mask ;send lower
nibble
lds R17,LCDDAT_PORT
andi R17,255-LCDDAT_Mask
or R17,R16
sts LCDDAT_PORT,R17
sbi LCDRS_PORT,LCDRS ;Set to
Data Reg.
cbi LCDRW_PORT,LCDRW ;Write
rcall LCD_PulseE ;Latch
lower nibble
ret
;*****************************************************
;** LCD_Goto
;**
;** In: R16 - position
;** 0x00 - 1.row, 1.col
;** 0x40 - 1.row, 2.col
;**
;** Out: -
;**
;**
;** Alt: R0, R1, R16, R17
;**
;** Description:
;**
;
LCD_Goto:
ori R16,0b10000000 ;Set
address Command
rcall LCD_SendCmd
ret
;*****************************************************
;** LCD_PrnFLASHStr
;**
;** In: Z+RAMP - start address of string
;**
;** Out: -
;**
;**
;** Alt: R0, R1, R16, R17
;**
;** Description:
;** Print a null terminated string to LCD
;
LCD_PrnFLASHStr:
elpm R16,Z+
tst R16
breq LCD_PrnFLSH0
rcall LCD_SendChar
rjmp LCD_PrnFLASHStr
LCD_PrnFLSH0:
ret
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
COPY 102
LPM 108 ;Variablendefinition
EPROM 100 .def zeichen = r0 ;Zeichen aus der Tabelle
SER EPROM .def buffer = r16 ;RX/TX Daten von/zu LCD
.def counter = r17 ;Zaehler fuer den Text
DFLASH AT45
.def temp = r18
FLASH CARD
VFX SMIL
.CSEG
VFX MEM .ORG 0x00 ; Programm beginnt bei 0
SORT 220 rjmp main ; Starte Hauptprogramm
CRC 236 ;
XMODEM REC **************************************************************
; Subroutine init
UART 304 ; Initialisiere PORTD
UART 305 ;
**************************************************************
UART 128
UART BUFF init: ldi temp,0b11111111 ;PORTD ist Ausgang
USB 232 out DDRD,temp
cbi PORTD,E ;E initialisieren
AVR ISP cbi PORTD,RS
ISP 2313 cbi PORTD,RW
ret
ISP 1200
AVR SPI
I2C 300 ;
I2C 302 ***************************************************************
; Subroutine busy_flag
I2C TWI26
; Diese Routine testet, ob die LCD-Anzeige bereit ist,
I2C/TWI 128 einen
I2C/TWI AT8 ; neuen Befehl oder weitere Daten zu empfangen.
;
DALLAS-1W ***************************************************************
DALLAS CRC
busy_flag: ldi temp,0b00000000 ;PORTB ist Eingang
ETHNET 8019 out DDRB,temp
TEA cbi PORTD,RS ;Befehl wird gesendet
sbi PORTD,RW ;setze LCD in Lesemodus
ADC 128 sbi PORTD,E ;spreche LCD an
ADC 10B nop
nop
ADC 400
sbic PINB,BF ;LCD bereit?
ADC 401 rjmp busy_flag ;nein, wiederhole
THERM 232 cbi PORTD,E ;disable LCD
ret ;LCD bereit
IRD 410
LCD HD44
;
LCD 2313 ***************************************************************
LCD44 2313 ; Subroutine write_data
; Diese Routine sendet Daten zur LCD-Anzeige.
KBD 240 ; Die Daten muessen im Register buffer uebergeben
MUX 242 werden.
;
KBD PS2
***************************************************************
KBD PC/128
PS2 EMU write_data: rcall busy_flag ;LCD bereit?
ldi temp,0b11111111 ;PORTB ist Ausgang
BOOT MG8 out DDRB,temp
BOOT DR8 sbi PORTD,RS ;Daten werden gesendet
cbi PORTD,RW ;LCD in Schreibmodus
ALM CLK sbi PORTD,E ;spreche LCD an
CLOCK 8564 out PORTB,buffer ;sende Daten
cbi PORTD,E ;disable LCD
90 DAYS
ret
DELAYS
CALL ID
;
DTMF 314 ***************************************************************
PWM 6CH ; Subroutine write_instr
; Diese Routine sendet Befehle zur LCD-Anzeige.
PWM 10K ; Der Befehl muss im Register buffer uebergeben werden.
ENCODE ;
***************************************************************
STH-11
ATMEL CORP write_instr: rcall busy_flag ;LCD bereit?
ldi temp,0b11111111 ;RB ist Ausgang
AVR
out DDRB,temp
BUTTERFLY cbi PORTD,RS ;Befehl wird gesendet
AVR BOOK cbi PORTD,RW ;LCD in Schreibmodus
sbi PORTD,E ;spreche LCD an
out PORTB,buffer ;sende Befehl
cbi PORTD,E ;disable LCD
ret
;
***************************************************************
; Hauptprogramm
; Schreibt "AT90S2313" in die erste Zeile und "LCD-
Routine"
; in die zweite Zeile des LCDs.
;
***************************************************************
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;-----------------------------------------------------------------
;
; Variables
.dseg
;-----------------------------------------------------------------
;
; Interrupt service vectors
.cseg
.org 0
rjmp Reset ; Reset vector
.org OVF0addr
rjmp Timer0 ; Timer tick
;-----------------------------------------------------------------
;
; Start of actual code.
;
;-----------------------------------------------------------------
;
; Timer 0 overflow - decreases tick count in tickcount until it
; reaches 0, then ripples the count along to the next biggest
; counter, all the way up to the "days" count.
;
; We get through to here once every 4 or 5 timer ticks, in
; other words, 100 times every second.
;
;
; However we get here, the most recently incremented value is in
rITEMP,
; and Y points to where we got it from.
;
Timer0_Done:
st Y,rITEMP ; store valid value back again
;-----------------------------------------------------------------
;
; WaitTick
; Waits for between rPARAM1 and rPARAM1+1 timer ticks, depending
; on exactly when the next tick is about to happen. Each tick
takes
; 20ms on a 4MHz clock, or 25ms on a 3.6864MHz clock. This is
enough
; to act as a timed delay for those commands which take more than
; the 40us "standard" delay.
WaitTick:
inc rPARAM1
mov rITICK,rPARAM1
WaitTick_Loop:
and rITICK,rITICK
brne WaitTick_Loop
ret
;-----------------------------------------------------------------
;
; Reset vector - generic system.
Reset:
ldi rTEMP,RAMEND-1 ; Set stack to end of RAM
out SPL,rTEMP
;
; And allow timer interrupts
;
sei
ldi rTEMP,$00
out PORTB,rTEMP
ldi rTEMP,$FF
out DDRB,rTEMP
;
; Now initialize the display
;
rcall InitDisplay
;
; And reset the displayed time to 00 00:00:00.00
;
clr rTEMP
sts tickcount,rTEMP
sts centi,rTEMP
sts second,rTEMP
sts minute,rTEMP
sts hour,rTEMP
sts day, rTEMP
ldi rPARAM1,0x00
rcall LCDGoto ; go to display position 0
ldi ZL,low(String*2)
ldi ZH,high(String*2)
rcall LCDString ; and send string
Loop:
ldi rPARAM1,0x40
rcall LCDGoto ; go to display position 0x40 (2nd line)
;-----------------------------------------------------------------
;
; InitDisplay
; Initialize display as shown in data sheet.
InitDisplay:
ldi rPARAM1,5
rcall WaitTick
; Wait again
; Wait again
; Wait
;
; We can now use the normal functions for writing data,
; which are designed to work with 4-bit mode data timings
;
; Function set
; Display on
; Display clear
ldi rPARAM1,0x01
rcall WriteInstruction
ret
;-----------------------------------------------------------------
;
; LCDGoto
; Go to character position rPARAM1
LCDGoto:
ori rPARAM1,0x80
rjmp WriteInstruction
;-----------------------------------------------------------------
;
; LCDNumber
; Write number from 00 to 99 at current position
LCDNumber:
mov rPARAM2,rPARAM1
ldi rTEMP,'0'
LCD10s: subi rPARAM2,10
brmi LCD1s
inc rTEMP
rjmp LCD10s
;-----------------------------------------------------------------
;
; LCDString
; Write string at Z from flash to LCD at current position
LCDString:
lpm
and r0,r0
breq LCDString_End
adiw ZL,1
mov rPARAM1,r0
rcall WriteData
rjmp LCDString
LCDString_End:
ret
;-----------------------------------------------------------------
;
; WriteData
; Write rPARAM1 as data
WriteData:
ldi rTEMP,(1< rjmp Write
;-----------------------------------------------------------------
;
; WriteInstruction
; Write rPARAM1 as instruction
WriteInstruction:
ldi rTEMP,0
Write:
mov rTEMP2,rPARAM1
swap rTEMP2
andi rTEMP2,$0F
or rTEMP2,rTEMP
rcall Strobe
mov rTEMP2,rPARAM1
andi rTEMP2,$0F
or rTEMP2,rTEMP
rcall Strobe
rjmp Wait40
;-----------------------------------------------------------------
;
; Strobe
; Output rTEMP2 to PortB and then strobe the enable line
Strobe:
out PORTB,rTEMP2
nop
nop
nop
sbi PORTB,bEN
nop
nop
nop
cbi PORTB,bEN
ret
;-----------------------------------------------------------------
;
; Wait40, WaitMicro
; Wait 40 (or rPARAM1) microseconds
Wait40:
ldi rPARAM1,40 ; 40uS
WaitMicro: ; 4 cycles
nop ; per loop
dec rPARAM1 ; at 4 MHz
brne WaitMicro ; = 1 uS per loop
ret
;-----------------------------------------------------------------
;
; ReadStatus
; Read Status into rReturn.
ReadStatus:
ldi rTEMP,(1< rjmp Read
;-----------------------------------------------------------------
;
; ReadData
; Read Data into rReturn
ReadData:
ldi rTEMP,(1<
Read: out PORTB,rTEMP
nop
sbi PORTB,bEN
nop
nop
in rTEMP,PINB
cbi PORTB,bEN
andi rTEMP,0x0F
swap rTEMP
sbi PORTB,bEN
mov rRETURN,rTEMP
nop
in rTEMP,PINB
cbi PORTB,bEN
andi rTEMP,0x0F
or rRETURN,rTEMP
rjmp Wait40
;-----------------------------------------------------------------
;
; WaitBusy
; Waits until device is not busy
WaitBusy:
rcall ReadStatus
and rRETURN,rRETURN
brmi WaitBusy ; if bit 7 still set, go round again
ret
;-----------------------------------------------------------------
;
; Strings to display
String:
.db "Time since start:", 0
;-----------------------------------------------------------------
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
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
;****Interrupt service
routine***************************************
scan:
in status,SREG ;preserve status
register
sbis PINB,ROW1 ;find row of
keypress
ldi key,0 ;and set ROW pointer
sbis PINB,ROW2
ldi key,4
sbis PINB,ROW3
ldi key,8
sbis PINB,ROW4
ldi key,12
ldi temp,0x0F ;change port B I/O
to
out DDRB,temp ;find column press
ldi temp,0xF0 ;enable pull ups and
out PORTB,temp ;write 0s to rows
rcall settle ;allow time for
port to settle
sbis PINB,COL1 ;find column of
keypress
ldi temp,0 ;and set COL pointer
sbis PINB,COL2
ldi temp,1
sbis PINB,COL3
ldi temp,2
sbis PINB,COL4
ldi temp,3
add key,temp ;merge ROW and COL
for pointer
ldi temp,0xF0 ;reinitialise port
B as I/O
out DDRB,temp ; 4 OUT 4 IN
ldi temp,0x0F ;key columns all
low and
out PORTB,temp ;active pull ups on
rows enabled
out SREG,status ;restore status
register
ldi temp,0x00
out GIMSK,temp ;disable external
interrupt
;have to do this,
because we're
;using a level-
triggered interrupt
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;Port B pins
;Port D pins
.include "1200def.inc"
table1: .db
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
;digit 0 1 2 3 4 5 6 7
8 9
.db 0x86,0x8E,0xA3,0xAB,0XFF,0XFF
;digit E f o n BLANK special
characters
;key 1 2 3 F 4 5 6 E 7 8 9 D A
0 B C
table2: .db 1, 2, 3,15, 4, 5, 6,14, 7, 8, 9,
13, 10, 0, 11, 12
;value 0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
;****Source
code***************************************************
.cseg ;CODE
segment
.org 0
rjmp reset ;Reset handler
nop ;unused ext.
interrupt
rjmp tick ;timer counter
overflow (5 ms)
nop ;unused analogue
interrupt
reset:
ser temp ;
out DDRB,temp ;initialize port B
as all Outputs
out DDRD,temp ;initialize port D
as all Outputs
out PORTB,temp ;key columns all
high/LEDs off
out PORTD,temp ;turn off LEDs and
loads off
ldi temp,0x04 ;timer
prescalar /256
out TCCR0,temp
ldi timer,176 ;load timer for 5 ms
out TCNT0,timer ;(256 - n)
*256*0.2441 us
ldi temp,0x02 ;enable timer
interrupts
out TIMSK,temp
clr flags ;clear control flags
clr tock ;clear 5 ms tick
clr bounce ;clear key bounce
counter
clr flash
clr blink
sei ;enable global
interrupts
do:
clr mask ;do housekeeping
cpi blink,100 ;is half second up
brne nohalf
clr blink
com flash ;invert flash
nohalf:
cpi second,60 ;is one minute up?
brne nochange ;no
clr second ;yes clear seconds
and
inc minute ;add one to minutes
mov temp,minute
andi temp,0x0f ;mask high minute
cpi temp,10 ;is it ten minutes?
brne nochange ;no
andi minute,0xf0 ;clear low minutes
ldi temp,0x10
add minute,temp ;increment high
minutes
cpi minute,0x60 ;is it 60 minutes?
brne nochange ;no
clr minute ;yes, clear minutes
and
inc hour ;add one to hours
mov temp,hour
andi temp,0x0f ;mask high hour
cpi temp,10 ;is 10 hours up?
brne nochange ;no
andi hour,0xf0 ;yes, increment
ldi temp,0x10
add hour,temp ;high hours
nochange:
cpi hour,0x24 ;is it 24
hours?
brne sameday ;no,
clr hour ;yes, clear time
variables
clr minute ;to start new day
clr second
sameday: ;update times
mov lobyte,minute
mov hibyte,hour
rcall display ;show time for 20 ms
brtc case1 ;if not SET
rcall setrtc ;and reset
time
mov hour,hiset ;and reload
hours
mov minute,loset ;and minutes
clt ;else, clear T
flag
case1: sbrc flags,ld1 ;is load 1
active?
rjmp chkload1 ;yes, check load 1
case2: sbrc flags,ld2 ;is load 2
active
rjmp chkload2 ;yes, check load 2
case3: sbrc flags,ld1on ;is load 1
on time reset
rjmp setld1on ;yes reset on time
case4: sbrc flags,ld1off ;is load 1
off time reset
rjmp setld1off ;yes reset off time
case5: sbrc flags,ld2on ;is load 2
on time reset
rjmp setld2on ;yes reset on time
case6: sbrc flags,ld2off ;is load 2
on time reset
rjmp setld2off ;yes reset on time
case7: rjmp do ;repeat
housekeeping loop
setld1off:
tick:
in status,SREG ;preserve status
register
inc tock ;add one to 5 ms
'tock' counter
inc blink ;and blink rate
counter
inc bounce ;and bounce rate
delay
sbr flags,0x80 ;set 5 ms flag for
display time
cpi tock,200 ;is one second up?
breq onesec ;yes, add one to
seconds
nop ;balance interrupt
time
rjmp nosecond ;no, escape
onesec: inc second ;add one to
seconds
clr tock ;clear 5 ms counter
nosecond: ldi timer,176 ;reload timer
out TCNT0,timer
out SREG,status ;restore status
register
reti ;return to main
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
;
***************************************************************************
.ESEG
;
***************************************************************************
.CSEG
;
***************************************************************************
; PS/2 Billentyuzet inicializalasa
;
Init_PS2: CBI PS2_CLKPort,KCLK
CBI PS2_CLKDIR,KCLK ;CLK pin tre-
stated external pull-up res!!
CBI PS2_DATPort,KDATA
CBI PS2_DATDIR,KDATA ;DATA pin tre-
stated external pull-up res!!
clr R16
sts Kb_ScHead,R16 ;ScanCode
Pointer Head = 0
sts Kb_ScTail,R16
sts kb_ComStat,R16
sts kb_ResendCnt,R16
sts kb_Status,R16
sts kb_SWStatus,R16
ldi R16,255
sts kb_lastAction,R16 ;normal mukodes
ldi ZL,low(NormalUzem)
ldi ZH,high(NormalUzem)
sts jumptabla+0,ZL
sts jumptabla+1,ZH
in R16,MCUCR
cbr R16,0b00000011 ;mask for 1,0
bits
sbr R16,0b00000010 ;set for falling
edge
OUT MCUCR,R16 ;1:0 = Inerrupt
Sense Control for INT0
; 00 -> Low
Level INT0
; 01 -> Reserved
; 10 -> Falling
Edge INT0
; 11 -> Rising
Edge INT0
in R16,GIMSK
ori R16,64 ;INT0 enabled
OUT GIMSK,R16 ;6. = 1 EXT INT0
ACTIVE
WTCTO:
rcall kb_CMD_Reset
rcall WaitToComplete
brcs KeybErr
cpi R16,KEYBOARD_COMPLETE_SUCCESS
brne KeybErr
rcall kb_CMD_ReadID
rcall WaitToComplete
brcs KeybErr
ldi R18,64
cpi R16,0xDE
brne nonPS2
cpi R17,0xD0 ;0x83AB
nem tudom mi lehet minden billentyu
breq storeType ;0x9EAB -
vel ter vissza
;0xDED0
csak MAGOR HI-01 lehet
nonPS2: ldi R18,04 ;
Itt csak szabvany billentyu lehet
storeType:
sts kb_SWStatus,R18 ;
keyboard tipus eltarolva, majd kesobb kell meg
rcall kb_CMD_ALLMakeBrake
rcall WaitToComplete
brcs KeybErr
cpi R16,ST_Success
brne KeybErr
ldi R17,0
rcall kb_CMD_SetLEDs ;LEDek
kikapcsolva
rcall WaitToComplete
brcs KeybErr
cpi R16,ST_Success
brne KeybErr
ldi R16,low(ps2stszov*2)
ldi R17,high(ps2stszov*2)
lds R18,kb_SWStatus
andi R18,0b11000000 ;csak a
bill tipusa kell
breq kszoveg
ldi R16,low(magorszov*2)
ldi R17,high(magorszov*2)
rjmp kszoveg
KeybErr:
ldi R16,Low(kbTimeOutErr*2)
ldi R17,High(kbTimeOutErr*2)
kszoveg: rcall SendMSG
ret
;************************************************
;* WaitToComplete
;* kivarja egy billentyuparancs vegrehajtasat vagy time-out
;* R17:R16 ststus kod (redszerint csak az R16 kell)
; c=1 error
WaitToComplete:
ldi R16,40 ;ha 400ms-ig
nincs valasz hiba @100Hz rendszermegwszakitas mellett
sts SWTmr0,R16
WTC1: lds R16,SWTmr0
tst R16
breq WTCTimeOut
lds R16,kb_Status+0
cpi R16,0x33
breq WTC1
ldi R17,kb_Status+1
clc
ret
WTCTimeOut: sec
ret
;
******************************************************************************
;* INERRUPT: R E C E I V E
;*
;* External generated clock & data - host changes the Data
line only when
;* the Clock line is low, and data is latched on the falling
edge of the clock pulse
;* Host may abort transmission at time before the 11th clock
pulse (acknowledge bit)
;* by holding Clock low for at least 100 microseconds.
;*
;*
EXT_INT0: push ZL
push ZH
in ZL,SREG ;
preserve main OS status reg.
push ZL
push R16
push R2
in R2,PS2_DATPIN
bst R2,KDATA ;T-ben a
vett bit
lds ZL,PtrINT0+0
lds ZH,PtrINT0+1
icall ;Int0
vegrehajto rutin meghivasa
ldi R16,64 ;INT0
IRQ flag torlese
out GIFR,R16 ;lehet,
hogy ez nem kell majd!!!!
pop R2
pop R16
pop ZL
out SREG,ZL ;
restore previous status reg
pop ZH
pop ZL
reti
;*****************************************
; Receive 11 keyboard bit
;
Kb_Rec_Start: lds R16,Kb_BitCounter
dec R16
sts Kb_BitCounter,R16
cpi R16,10 ;start bitnel
tartunk
breq JaStartbit
cpi R16,1 ;Paritasbit jon?
breq JaParitasJon
cpi R16,0 ;Stopbit jon?
breq JaStopJon
;************************************** ;8
adatbit vetele
;* 8 DATA BIT
kb_Rec_end1: ret
;**************************************
;* START BIT
Kb_StartErr:
;ide jon az az eset, ha a start bit = 1 ,azaz
hiba van!!!!
;de Vigyazat! Meg interrupt rutinban vagyuk!!!!
ret
;**************************************
; PARITAS BIT
ret
;************************************
;* STOP BIT
lds R16,kb_lastAction
cpi R16,255
breq NemParancsvolt
lds R16,ResevedBits
cpi R16,RESEND
brne nemresend
lds R16,kb_ResendCnt
inc R16
sts kb_ResendCnt,R16
cpi R16,4 ;ha mar
haromszor probaltuk elkuldeni, de nem ment
;akkor resend
error
brne Mehettovabb
ldi R16,255
sts kb_lastAction,R16 ;vissza anormal
mukodesre
ldi R16,ST_ResendError
sts kb_Status,R16
ret
Mehettovabb:
rcall NextComdData
ret
NemParancsvolt:
rcall Put_ScanC ;Scankod a
bufferbe
clr R16
sts kb_ComStat,R16 ;Stop tilalom
feloldva!
ret
clr R16
sts kb_ComStat,R16 ;Stop tilalom
feloldva!
ret
;************************************************
;* The Put_ScanC FIFO manager *
;* in: - *
;* out c=1 hiba *
;************************************************
Put_ScanC: lds R16,Kb_ScHead
ldi ZL,Kb_ScData_Lenght
lds R2,Kb_ScTail
sub R2,R16
breq PSC4 ;T=H, akkor
Kb_ScData_Lenght hely van
brcs PSC2
clr ZL
PSC2: add ZL,R2
dec ZL
PSC4: cpi ZL,1 ;ZL = hely a
bufferben
brcs PSCExitwError ;ha <1 nincs elg
hely! Hiba!
clr R2
ldi ZL,low(Kb_ScData) ;Pointer to the
buffer (FIFO)
ldi ZH,high(Kb_ScData)
add ZL,R16
adc ZH,R2 ;add address
offset..
lds R2,ResevedBits ;ez elobb vet 8
kb_data bit
st Z,R2 ;eltarolva a
scankod bufferben
inc R16
cpi R16,Kb_ScData_Lenght ;Pointer>Len
brcs PSC3
clr R16 ;ha igen
Pointer=0, atfordult
PSC3: sts Kb_ScHead,R16
ScanCexit: clc ; Nincs hiba
ret
sec ;Hiba!!
ret
;**************************************
; FIFO Manager folytatasa
; mar nem interruptbol megy!!!!
; Out: c=0, R0 = scankod
;
Get_ScanC: clr R0
lds R18,Kb_ScTail
lds R19,Kb_ScHead
cp R19,R18
breq ScanErrExit ;nincs adat a
bufferben
;***************************************************
;* Send data to keyboard
;* start bit sending
;
Kb_StartSend:
lds R16,Kb_BitCounter
dec R16
sts Kb_BitCounter,R16
cpi R16,2
breq SendParitas
cpi R16,1
breq SendStopbit
cpi R16,0
breq GetAckBit
lds R16,kb_SendByte
lds R2,Kb_Paritas
ror R16
sts kb_SendByte,R16
brcs send1bit
CBI PS2_DATPort,KDATA ;send
bit 0
inc R2
rjmp kb_sendbitx
send1bit:
SBI PS2_DATPort,KDATA ;send
bit 1
kb_sendbitx: ;
uj adatbit a porton
sts Kb_Paritas,R2 ;uj
paritas eltarolasa
ret
;**************************************
;* Paritas bit kuldese
SendParitas:
lds R16,Kb_Paritas
ror R16
brcc send1paritas
CBI PS2_DATPort,KDATA ;send
bit 0
ret
send1paritas:
SBI PS2_DATPort,KDATA ;paritas
bit = 1
ret
;***************************************
;* Stop bit kuldese
;
SendStopbit:
CBI PS2_DATPort,KDATA
CBI PS2_DATDIR,KDATA ;DATA pin tre-
stated external pull-up!!
ret
;**************************************
;* Get Ack bit from keyboard
;
GetAckBit:
ldi R16,11 ;1 start
+8 adat +1 par +1 stop
sts Kb_BitCounter,R16 ;a kovetkezo
adat vetelehez
;***************************************************
;** Parancskuldes kezdemenyezese a keyboard fele
;** In : R0 data to keyboard
;** Out: c=0 sikeres kuldes meginidtasa
;** c=1 sikertelen kuldes
TrySendCmd:
lds R2,kb_ComStat ;Stop tilalom
van-e?
tst R2
breq TrySend
sec
NormalUzem: ret
TrySend:
sts jumptabla+0,ZL
sts jumptabla+1,ZH
sts kb_CmdBuffer+0,R16
sts kb_CmdBuffer+1,R17
sts kb_CmdBuffer+2,R18
ldi R16,0x33
sts kb_Status,R16
clr R16
sts kb_lastAction,R16 ;0. byte kuldese
lesz
NewParam:
clr R16
sts kb_ResendCnt,R16
NextComdData:
clr R16
lds R2,kb_lastAction ;a kovetkezo
byte kuldese
ldi ZL,low(kb_CmdBuffer)
ldi ZH,high(kb_CmdBuffer)
add ZL,R2
adc ZH,R16
ld R0,Z
sts kb_SendByte,R0
in R16,GIMSK
andi R16,0b10111111
OUT GIMSK,R16 ;6. = 0 EXT INT0
inactive
;hogy ne
okozzunk megszakitas
;mikor
leallitjuk a CLK vonalat
ldi ZL,low(wait100us/5)
ldi ZH,high(wait100us/5) ;100us idozito
konstans
w100us: nop ;[1]
sbiw ZL,1 ;[2]
brne w100us ;[2]
ldi R16,3
sts kb_ComStat,R16 ;Stop tilalom
lesz az adas allat...
clr R16
sts Kb_Paritas,R16 ;paritas
szamolashoz kell
in R16,GIMSK
ori R16,64
OUT GIMSK,R16 ;6. = 1 EXT INT0
ujra aktive
clc
ret
;jump tablak
;**********************
;* Reset keyboard
;* In: R17,R18,R19 parameter ahol kell
;* Out: status
;
kb_CMD_Reset:
ldi R16,KEYBOARD_RESET
kb_CMD_single: ldi ZL,low(Egyvalasz)
ldi ZH,high(Egyvalasz)
rjmp TrySendCmd
kb_CMD_ALLMakeBrake:
ldi R16,SET_ALL_TYPEMATIC_MAKE_BREAK
ldi ZL,low(CsakACKkell)
ldi ZH,high(CsakACKkell)
rjmp TrySendCmd
kb_CMD_Echo:
ldi R16,KEYBOARD_ECHO
ldi ZL,low(StoreResult)
ldi ZH,high(StoreResult)
rjmp TrySendCmd
kb_CMD_SetLEDs:
andi R17,0b00111111 ;csak az
also 6 bit kell -> 6 LEDek
lds R16,kb_SWStatus
andi R16,0b11000000
or R16,R17
sts kb_SWStatus,R16
ldi R16,SET_KEYBOARD_INDICATORS
param1: ldi ZL,low(EgyParameter)
ldi ZH,high(EgyParameter)
rjmp TrySendCmd
kb_CMD_SetSpeed:
ldi R16,SET_KEYBOARD_TYPEMATIC
rjmp param1
kb_CMD_ReadID:
ldi R16,READ_KEYBOARD_ID
ldi ZL,low(ketparamjon)
ldi ZH,high(ketparamjon)
rjmp TrySendCmd
;
*************************************************************
;* subrutinok a keyboard parancsok vegrehajtasahoz
;
CsakACKkell:
cpi R16,ACKNOWLEDGE
ldi R16,ST_Success
breq StoreResult
ldi R16,ST_Unsuccess
rjmp StoreResult
ldi R16,ST_ACKnotreseived
StoreResult:
ldi ZL,low(NormalUzem)
ldi ZH,high(NormalUzem)
sts jumptabla+0,ZL
sts jumptabla+1,ZH
nyugtamegjott:
ldi ZL,low(StoreResult)
ldi ZH,high(StoreResult)
sts jumptabla+0,ZL
sts jumptabla+1,ZH
ret
EgyParameter:
cpi R16,ACKNOWLEDGE
breq Elsonyugtaok
ldi R16,ST_ACKnotreseived
rjmp StoreResult
Elsonyugtaok:
lds R16,kb_lastAction ;a kovetkezo
byte kuldese
inc R16
sts kb_lastAction,R16
ldi ZL,low(CsakACKkell)
ldi ZH,high(CsakACKkell)
sts jumptabla+0,ZL
sts jumptabla+1,ZH
rjmp NewParam
ketparamjon:
sts kb_Status+1,R16
rjmp nyugtamegjott
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
startbit:
sbic PIND,PD1 ; Start bit = 0?
rjmp starterr ; no...go send error message
rjmp main ; yes..go look for data bits
databit:
bclr 0 ; pre-clear Carry flag
sbic PIND,PD1 ; SDA = 0?
bset 0 ; no, then set Carry flag
brbc 0,rotate ; now check status of Carry
flag for parity chk
in flags,SREG ; save
push flags ; status register
inc parity ; for parity check later
pop flags ; restore
out SREG,flags ; status register
rotate:
ror keydata ; rotate contents of
Carry flag into keydata
rjmp main ; go get another bit
;
; Parity checking.....
; this routine is based on Odd Parity; meaning if there
are an even number of 1's
; in the data byte the Parity bit will be 1 so that an
odd number of 1's now exist,
; if there are already an odd number of 1's then the
Parity bit will be 0.
;
; I will keep track of Parity by incrementing the
parity register once for every 1
; that is received on the data line. If there are an
odd number of 1's the lsb of
; parity register will always be 1
;
; Therefore, if the lsb of the parity register = 1 (odd
number of 1's) then the
; Parity bit should be 0 (there were an odd number of
1's already. This condition
; can be checked by exclusive ORing those 2 bits. As
long as they are opposite
; the parity checks out good.
;
paritybit:
in flags,PIND ; SDA = PD1
ror flags ; rotate SDA into bit 0
position
andi flags,0x01 ; clear all but bit 0
position
andi parity,0x01 ; again, clear all but
bit 0
eor flags,parity ; exclusive-or to find
out if lsb's of flags
; and parity the same
breq parerr ; report error if they are
the same
rjmp main ; return and get stop bit now
stopbit:
sbis PIND,PD1 ; SDA = 1?
rjmp stoperr ; no, go report error
cpi keydata,0xAA ; BAT message from
keyboard?
brne chkforbrkcode ; no, check for next code
of interest
ldi ZH,high(2*batmsg) ; pre-load BAT message
address
ldi ZL,low(2*batmsg)
call sendmsg ; go send message
rjmp init ; go look for another key
press
chkforbrkcode:
cpi keydata,0xF0 ; Break code (0xF0):?
brne sendkeychar ; no, go send ASCII key
code
ldi ZH,high(2*brkmsg) ; yes, now pre-load
Break message address
ldi ZL,low(2*brkmsg)
call sendmsg ; go send message
rjmp init ; look for another keypress
starterr:
ldi ZH,high(2*sterrmsg) ; load high part of
message address in ZH
ldi ZL,low(2*sterrmsg) ; load low part of
message address in ZL
call senderrmsg
parerr:
ldi ZH,high(2*parerrmsg); load high part of
message address in ZH
ldi ZL,low(2*parerrmsg) ; load low part of
message address in ZL
call senderrmsg
stoperr:
ldi ZH,high(2*sperrmsg) ; load high part of
message address in ZH
ldi ZL,low(2*sperrmsg) ; load low part of
message address in ZL
call senderrmsg
scllo:
sbic PIND,PD0 ; PD0(SCL) = 0?
rjmp scllo ; no...continue checking SCL
ret ; yes...return main program
sclhi:
sbis PIND,PD0 ; PD0(SCL) = 1?
rjmp sclhi ; no...continue checking SCL
ret ; yes..return to main
program
getsda:
bclr 0 ; pre-clear the Carry flag
sbic PIND,PD1 ; check state of SDA
bset 0 ; if SDA = 1, set Carry flag
ret ; if SDA = 0. Carry flag is
already cleared
;
******************************************************************************
senderrmsg:
; the calling program will have to load ZH and ZL with
the appropriate message
; address
loop:
cbi UCSR0B,TXEN0 ; disable transmitter
rjmp loop ; program stops here when
error occurs, user
; will have to reset the
STK500 and try again
;
******************************************************************************
sendmsg:
; the calling program will have to load ZH and ZL with
the appropriate message
; address
;
******************************************************************************
sendkeychar:
getchar:
lpm ; load appropriate key
character into R0
out UDR0,R0 ; no...transmit
character
call chkxmitend ; wait for transmit to
finish
cbi UCSR0B,TXEN0 ; disable transmitter
ret
;
******************************************************************************
chkxmitend:
sbis UCSR0A,UDRE0 ; data register empty flag
= 1
rjmp chkxmitend ; no...keep checking
ret ; yes..continue with program
;************* MESSAGES
******************************************************
batmsg:
.db " Basic Assurance Test complete ",0
brkmsg:
.db " Break ",0
sterrmsg:
.db "Start Bit Error",0
parerrmsg:
.db "Parity Bit Error"
.db 0,0
sperrmsg:
.db "Stop Bit Error"
.db 0,0
ascii:
; 0x00 - 0x0F
.db
'?','F','?','F','F','F','F','F','?','F','F','F','F','T','`','?'
; 0x10 - 0x1F
.db
'?','L','L','?','L','q','1','?','?','?','z','s','a','w','2','?'
; 0x20 - 0x2F
.db
'?','c','x','d','e','4','3','?','?','S','v','f','t','r','5','?'
; 0x30 - 0x3F
.db
'?','n','b','h','g','y','6','?','?','?','m','j','u','7','8','?'
; 0x40 - 0x4F
.db
'?',',','k','i','o','0','9','?','?','.','/','l',';','p','-','?'
; 0x50 - 0x5F
.db
'?','?',''','?','[','=','?','?','C','R','E',']','?','\','?','?'
; 0x60 - 0x6F
.db
'?','?','?','?','?','?','B','?','?','1','?','4','7','?','?','?'
; 0x70 - 0x7F
.db
'0','.','2','5','6','8','E','N','F','+','3','-','*','9','S','?'
; 0x80 - 0x83
.db '?','?','?','F'
AVR
<< Prev | Ring Hub | Join | Rate| Next
>>
© WebRing Inc. Search
ALM CLK
CLOCK 8564
.EQU Row0 = 0 ;PortB kiosztasa
90 DAYS
.EQU Row1 = 1
DELAYS .EQU Row2 = 2
.EQU Row3 = 3
CALL ID
.EQU Row4 = 4
DTMF 314 .EQU LED3 = 5 ;
PWM 6CH LED3
.EQU LED4 = 6 ;
PWM 10K LED4
ENCODE .EQU LED5 = 7 ;
LED5
STH-11
ATMEL CORP .EQU LED345 = PORTB
.EQU Row01234 = PORTB
AVR
BUTTERFLY
AVR BOOK .EQU LED0 = 0 ;PortD kiosztasa
LED0
.EQU LED1 = 1 ;
LED1
.EQU LED2 = 4 ;
LED2
.EQU Row5 = 5
.EQU Row6 = 6
.EQU Row7 = 7
;
******************************************************************************
;**** VARIABLES
.DSEG
Flag1: .BYTE 1 ;Flagbitek
;2 = paros/paratlan
szamlalo led villogtatashoz
;1:0 = scan mode 01 =
scan1, 10 = scan2, 11 = scan3
CNT1L: .BYTE 1
CNT1H: .BYTE 1 ;software Timer
CNT2L: .BYTE 1
CNT2H: .BYTE 1 ;LED villogtatas
freki
.EQU KeyBuffLen = 17
KeyBuff: .BYTE KeyBuffLen ;Transmit key-buffer
;
**************************************************************************************
.ESEG
.db "MAGOR HI-01 Keyboard-matrix Controller by
VFX. V1.1.0 [orig. 2001.09.16] "
.db "Last Upd. [2001.10.14] Info: [email protected]
Data area>>"
;
*****************************************************************************
;**** I N T E R R U P T S
;****
;
*****************************************************************************
.CSEG
rjmp RESET ; Reset Handler
rjmp EXT_INT0 ; IRQ0 Handler
rjmp EXT_INT1 ; IRQ1 Handler
rjmp TIM1_CAPT ; Timer1 Capture Handler
rjmp TIM1_COMPA ; Timer1 CompareA Handler
rjmp TIM1_COMPB ; Timer1 CompareB Handler
rjmp TIM1_OVF ; Timer1 Overflow Handler
rjmp TIM0_OVF ; Timer0 Overflow Handler
rjmp SPI_INT ; SPI Transfer Complete
Handler
rjmp UART_RXC ; UART RX Complete Handler
rjmp UART_DRE ; UDR Empty Handler
rjmp UART_TXC ; UART TX Complete Handler
rjmp ACI_INT ; Analog Comparator Handler
;*********************
EXT_INT0: RETI
EXT_INT1: RETI
TIM1_CAPT: RETI
;************************
;* Key Deleay & Rep Time
;************************
TIM1_COMPA: PUSH ZL
IN ZL,SREG
PUSH ZL
ldd ZL,Y+WRep+1-RAMSTRT
out OCR1AH,ZL
ldd ZL,Y+WRep+0-RAMSTRT
out OCR1AL,ZL ;rep. timer
beallitasa
ldi ZL,1
or R15,Zl ;timer
lejart ismetles mehet Flag
POP ZL
OUT SREG,ZL
POP ZL
RETI
;**
TIM1_COMPB: RETI
TIM1_OVF: RETI
;*********************
;* RealTime Clock Int
;*********************
;*
TIM0_OVF: PUSH ZL
PUSH ZH
IN ZL,SREG
PUSH ZL
LDI ZL,T0Freq
OUT TCNT0,ZL ;Reload
Timer
LDD ZL,Y+CNT1L-RAMSTRT
LDD ZH,Y+CNT1H-RAMSTRT
OR ZL,ZH
BREQ TIM_01
LDD ZL,Y+CNT1L-RAMSTRT
SBIW ZL,1
STD Y+CNT1L-RAMSTRT,ZL
STD Y+CNT1H-RAMSTRT,ZH
TIM_01:
LDD ZL,Y+CNT2L-RAMSTRT
LDD ZH,Y+CNT2H-RAMSTRT
OR ZL,ZH
BREQ TIM_02
LDD ZL,Y+CNT2L-RAMSTRT
SBIW ZL,1
STD Y+CNT2L-RAMSTRT,ZL
STD Y+CNT2H-RAMSTRT,ZH
TIM_02: POP ZL
OUT SREG,ZL
POP ZH
POP ZL
RETI
;********************
;* SPI Int Handle
;********************
SPI_INT: RETI
UART_RXC: RETI
UART_DRE: RETI
UART_TXC: RETI
EPR_INT: RETI
ACI_INT: RETI
;
**********************************************************************
;* Iclude files
.include "keyb.asm"
.include "ps2.asm"
.include "EEprom.asm"
;
**********************************************************************
;* RESET
;
**********************************************************************
RESET: CLI ;GLOBAL INTERRUP
DIS.
clr R15 ;Flags!!!