ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Пятница
22 ноября
275359 Топик полностью
MBedder, терминатор (29.09.2011 01:29, просмотров: 277) ответил Vit на интересно, почему должны?
Какой смысл делать одноразовые МНОГОСТРОЧНЫЕ макросы, применяемые в проекте лишь единожды? Вот для примера один из моих универсальных макрофайлов, включаемый в РАЗНЫЕ проекты: .nolist ;----------------------------------------------------------------------------------------- .macro ldiw ; ; Writes a 16-bit immediate value to a 16-bit wxyzH/wxyzL register pair. ; Usage: ldiw W[or X, or Y, or Z],value. ; *** Note: WL/WH must be .def'd somewhere *** ; ldi @0L,low(@1) ldi @0H,high(@1) .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro ldil ; ; Writes a 32-bit immediate value to a high 4-register block named as xxxl0/1/2/3. ; Usage: ldil xxx,value. ; ldi @0l0,byte1(@1) ldi @0l1,byte2(@1) ldi @0l2,byte3(@1) ldi @0l3,byte4(@1) .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro ldst ; ; Loads a 3-register block named as xxxl0/1/2 from 3 consequent direct RAM locations. ; Usage: ldsl xxx,address. ; lds @0l0,@1+0 lds @0l1,@1+1 lds @0l2,@1+2 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro ldsl ; ; Loads a 4-register block named as xxxl0/1/2/3 from 4 consequent direct RAM locations. ; Usage: ldsl xxx,address. ; lds @0l0,@1+0 lds @0l1,@1+1 lds @0l2,@1+2 lds @0l3,@1+3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro lddl ; ; Loads a 4-register block named as xxxl0/1/2/3 from 4 consequent indirect RAM locations. ; Usage: ldsl xxx,X[or Y, or Z]. ; ldd @0l0,@1+0 ldd @0l1,@1+1 ldd @0l2,@1+2 ldd @0l3,@1+3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro stsi ; ; Writes an 8-bit immediate value to a 8-bit direct RAM location. ; Usage: stsi addr,value ; Uses/trashes a tmp register for operation. ; ldi tmp,@1 sts @0,tmp .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro stsw ; ; Stores a 2-register block named as xxxL/xxxH into 2 consequent direct RAM locations. ; Usage: stsw xxx,address ; sts @0,@1l sts @0+1,@1h .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro stst ; ; Stores a 3-register block named as xxxl0/1/2 into 3 consequent direct RAM locations. ; Usage: stsw xxx,address ; sts @0+0,@1l0 sts @0+1,@1l1 sts @0+2,@1l2 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro stsl ; ; Stores a 4-register block named as xxxl0/1/2/3 into 4 consequent direct RAM locations. ; Usage: stsw xxx,address ; sts @0+0,@1l0 sts @0+1,@1l1 sts @0+2,@1l2 sts @0+3,@1l3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro stdl ; ; Stores a 4-register block named as xxxl0/1/2/3 into 4 consequent indirect RAM locations. ; Usage: stsw X[or Y, or Z],xxx ; std @0+0,@1l0 std @0+1,@1l1 std @0+2,@1l2 std @0+3,@1l3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro stsiw ; ; Writes a 16-bit immediate value to a 16-bit RAM location. ; Usage: stsiw addr,value ; Uses/trashes a tmp register for operation. ; ldi tmp,low(@1) sts @0,tmp ldi tmp,high(@1) sts @0+1,tmp .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro outi ; ; Writes a 8-bit immediate value to an 8-bit i/o SFR. ; Usage: outi IOREG8,value. ; Uses/trashes a tmp register for operation. ; ldi tmp,@1 out @0,tmp .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro outiw ; ; Writes a 16-bit immediate value to a 16-bit xxxH/xxxL i/o SFR pair. ; Usage: outiw IOREG16,value. ; Uses/trashes a tmp register for operation. ; ldi tmp,high(@1) ; @1 = second macro argument, out @0H,tmp ; @0 = first macro argument. ldi tmp,low(@1) ; Up to 10 macro arguments can be used (@0...@9) out @0L,tmp ; H/L is appended to an argument literally .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro adi ; ; Adds 8-bit immediare value to a high register ; Usage: adi r16{or r17...r31],value ; subi @0,-@1 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro adci ; ; Adds 8-bit immediare value and carry to a high register ; Usage: adci r16{or r17...r31],value ; sbci @0,-@1 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro addiw ; ; Adds 16-bit immediare value to a L/H named register pair ; Usage: addiw W[or X, Y, Z],value ; subi @0L,low(-@1) sbci @0H,high(-@1) .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro addl ; ; Adds two 4-register blocks named as xxxl0/1/2/3 and yyyl0/1/2/3 ; Usage: addl xxx,yyy ; add @0l0,@1l0 adc @0l1,@1l1 adc @0l2,@1l2 adc @0l3,@1l3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro subl ; ; Subtracts two 4-register blocks named as xxxl0/1/2/3 and yyyl0/1/2/3 ; Usage: subl xxx,yyy ; sub @0l0,@1l0 sbc @0l1,@1l1 sbc @0l2,@1l2 sbc @0l3,@1l3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro subiw ; ; Subtracts a 16-bit immediate value from a high register pair named as xxxl0/1 ; Usage: subit xxx,yyy ; subi @0l0,byte1(@1) sbci @0l1,byte2(@1) .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro subit ; ; Subtracts a 24-bit immediate value from a high 3-register block named as xxxl0/1/2 ; Usage: subit xxx,yyy ; subi @0l0,byte1(@1) sbci @0l1,byte2(@1) sbci @0l2,byte3(@1) .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro subil ; ; Subtracts a 32-bit immediate value from a high 4-register block named as xxxl0/1/2/3 ; Usage: subil xxx,yyy ; subi @0l0,byte1(@1) sbci @0l1,byte2(@1) sbci @0l2,byte3(@1) sbci @0l3,byte4(@1) .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro cpl ; ; Compares two 4-register blocks named as xxxl0/1/2/3 and yyyl0/1/2/3 ; Usage: cpl xxx,yyy ; cp @0l0,@1l0 cpc @0l1,@1l1 cpc @0l2,@1l2 cpc @0l3,@1l3 .endm ;----------------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------- .macro xchg ; Exchanges contents of two registers without affecting any other register. ; Usage: xchg REG1,REG2. eor @0,@1 eor @1,@0 eor @0,@1 .endm ;----------------------------------------------------------------------------------------- /* ;----------------------------------------------------------------------------------------- ; Usage examples: msg1: .db "This is a message" Code: clr nul ; Initialize zero (0x00) holding byte register clr nul ; Initialize constant (0x01) holder byte register ldiw z,msg1*2 ; Load a msg1 BYTE address to ZH:ZL outi UBRR,brrval ; Load a 8-bit i/o register with immediate 8-bit value outi ADMUX,(@ REFS0)|(@ ADLAR)|(4<<MUX0) ; Example: ADC setup: Vref = int, left adjust, ADC input = PINA4 outiw SP,RAMEND ; Load a 16-bit i/o register with immediate 16-bit value adi temp,0xAB ; Add 8-bit immediate to an 8-bit register adci temp2,0xCD ; Add 8-bit immediate to an 8-bit register with carry addiw x,0x1234 ; Add 16-bit immediate to a 16-bit register pair (XH:XL, YH:YL, ZH:ZL) add xl,temp ; Add 8-bit register to 16-bit register pair (XH:XL = XH:XL + temp) adc xh,nul ; cp r0,one ; Compare an 8-bit register to "1" ISRexample: in stsav,SR ; Save Status Register ; Your ISR code goes here out SR,stsav ; Restore Status Register reti ;----------------------------------------------------------------------------------------- */