共3条
1/1 1 跳转至页
iccavr 怎样c语言中调用汇编程序,我用的iccavr
问
最好能举个例子,或提供个例子资料什么的
答 1:
谁有这方面的例子
答 2:
like this onevoid AssemProgram()
{
asm("string of assemble \n"
"another string of assemble \n"
...
);
}
ok you CAN use this function now. 答 3: 我需要调用整个程序的,因为汇编程序很长 答 4: 你在汇编之前用asm,然后把汇编程序用括号括起来! 答 5: 汇编代码很长我不会要一句一句括吧 答 6: 看过来将你的汇编文件改名字为*.S,然后和C的主程序一起加入工程,在C中要调用的汇编函数在C中声明成外部函数,在汇编文件函数名前面加上下划线,后面是两个冒号,其他的不用改,编译就好了 答 7: 可是在汇编中不能写portd等的寄存器,只能用单片地址来表示吗也不能用equ等伪指令
有没有办法,能使这个汇编能像纯汇编那样运用自如 答 8: 可以的我的做法是将汇编文件包含的头文件中的.equ去掉,只留下UDR1 = $9C,这样的语句,就可以编译通过了,这样c调用的汇编文件就和纯汇编一模一样了(指的是语法,格式当然稍有不同) 答 9: iccAVR库中有aiom128.s这是汇编头文件iccAVR库中有aiom128.s等等。这是汇编头文件 答 10: 这样的话就会出现新的问题:因为必须去掉相应的.def指令,那么
XL =r26
XH =r27
YL =r28
YH =r29
ZL =r30
ZH =r31
就会出现r26..r31等等出错,因此在汇编中无法使用x、y、z
这该怎么办 答 11: .def指令不要去掉下面是我改的128的头文件,你要是用128的话,可以直接考过去用,不是的话就仿照改吧
m128def.inc
/**********************************************/
;***************************************************************************
;* A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y
;*
;* Number : AVR000
;* File Name : "m128def.inc"
;* Title : Register/Bit Definitions for the ATmega128
;* Date : 07.09.2001
;* Version : 1.0
;* Support telephone : +47 72 88 43 88 (ATMEL Norway)
;* Support fax : +47 72 88 43 99 (ATMEL Norway)
;* Support E-mail : AVR@atmel.no
;* Target MCU : ATmega128
;*
;* DESCRIPTION
;* When including this file in the assembly program file, all I/O register
;* names and I/O register bit names appearing in the data book CAN be used.
;* In addition, the six registers forming the three data pointers X, Y and
;* Z have been assigned names XL - ZH. Highest RAM address for Internal
;* SRAM is also defined
;*
;* The Register names are represented by their hexadecimal address.
;*
;* The Register Bit names are represented by their bit number (0-7).
;*
;* Please observe the difference in using the bit names with instructions
;* such as "sbr"/"cbr" (set/clear bit in register) and "sbrs"/"sbrc"
;* (skip if bit in register set/cleared). The following example illustrates
;* this:
;*
;* in r16,PORTB ;read PORTB latch
;* sbr r16,(1<<PB6)+(1<<PB5) ;set PB6 and PB5 (use masks, not bit#)
;* out PORTB,r16 ;output to PORTB
;*
;* in r16,TIFR ;read the Timer Interrupt Flag Register
;* sbrc r16,TOV0 ;test the overflow flag (use bit#)
;* rjmp TOV0_is_set ;jump if set
;* ... ;otherwise do something else
;***************************************************************************
;**** Specify Device ****
;.device ATmega128
;*****************************************************************************
; I/O Register Definitions
;*****************************************************************************
;**** Memory Mapped I/O Register Definitions ($FF-$60) ****
UCSR1C = $9D
UDR1 = $9C
UCSR1A = $9B
UCSR1B = $9A
UBRR1L = $99
UBRR1H = $98
UCSR0C = $95
UBRR0H = $90
TCCR3C = $8C
TCCR3A = $8B
TCCR3B = $8A
TCNT3H = $89
TCNT3L = $88
OCR3AH = $87
OCR3AL = $86
OCR3BH = $85
OCR3BL = $84
OCR3CH = $83
OCR3CL = $82
ICR3H = $81
ICR3L = $80
ETIMSK = $7D
ETIFR = $7C
TCCR1C = $7A
OCR1CH = $79
OCR1CL = $78
TWCR = $74
TWDR = $73
TWAR = $72
TWSR = $71
TWBR = $70
OSCCAL = $6F
XMCRA = $6D
XMCRB = $6C
EICRA = $6A
SPMCSR = $68
SPMCR = $68 ; old name for SPMCSR
PORTG = $65
DDRG = $64
PING = $63
PORTF = $62
DDRF = $61
;**** I/O Register Definitions ($3F-$00) ****
SREG = $3F
SPH = $3E
SPL = $3D
XDIV = $3C
RAMPZ = $3B
EICRB = $3A
EIMSK = $39
GIMSK = $39 ; old name for EIMSK
GICR = $39 ; old name for EIMSK
EIFR = $38
GIFR = $38 ; old name for EIFR
TIMSK = $37
TIFR = $36
MCUCR = $35
MCUCSR = $34
TCCR0 = $33
TCNT0 = $32
OCR0 = $31
ASSR = $30
TCCR1A = $2F
TCCR1B = $2E
TCNT1H = $2D
TCNT1L = $2C
OCR1AH = $2B
OCR1AL = $2A
OCR1BH = $29
OCR1BL = $28
ICR1H = $27
ICR1L = $26
TCCR2 = $25
TCNT2 = $24
OCR2 = $23
OCDR = $22 ; New
WDTCR = $21
SFIOR = $20 ; New
EEARH = $1F
EEARL = $1E
EEDR = $1D
EECR = $1C
PORTA = $1B
DDRA = $1A
PINA = $19
PORTB = $18
DDRB = $17
PINB = $16
PORTC = $15
DDRC = $14 ; New
PINC = $13 ; New
PORTD = $12
DDRD = $11
PIND = $10
SPDR = $0F
SPSR = $0E
SPCR = $0D
UDR0 = $0C
UCSR0A = $0B
UCSR0B = $0A
UBRR0L = $09
ACSR = $08
ADMUX = $07
ADCSR = $06
ADCH = $05
ADCL = $04
PORTE = $03
DDRE = $02
PINE = $01
PINF = $00
;*****************************************************************************
; Bit Definitions
;*****************************************************************************
;**** MCU Control ****
SRE = 7 ; MCUCR
SRW10 = 6
SE = 5
SM1 = 4
SM0 = 3
SM2 = 2
IVSEL = 1
IVCE = 0
JTD = 7 ; MCUCSR
JTRF = 4
WDRF = 3
BORF = 2
EXTRF = 1
PORF = 0
SRL2 =6 ; XMCRA
SRL1 =5
SRL0 =4
SRW01 =3
SRW00 =2
SRW11 =1
XMBK = 7 ; XMCRB
XMM2 = 2
XMM1 = 1
XMM0 = 0
SPMIE =7 ; SPMCSR
ASB =6 ; backwards compatiblity
ASRE =4 ; backwards compatiblity
RWWSB =6
RWWSRE =4
BLBSET =3
PGWRT =2
PGERS =1
SPMEN =0
IDRD = 7 ; OCDR
OCDR6 = 6
OCDR5 = 5
OCDR4 = 4
OCDR3 = 3
OCDR2 = 2
OCDR1 = 1
OCDR0 = 0
XDIVEN = 7 ; XDIV
XDIV6 = 6
XDIV5 = 5
XDIV4 = 4
XDIV3 = 3
XDIV2 = 2
XDIV1 = 1
XDIV0 = 0
TSM = 7 ; SFIOR
ADHSM = 4
ACME = 3
PUD = 2
PSR0 = 1
PSR1 = 0
PSR2 = 0
PSR3 = 0
PSR321 = 0
;**** Analog to Digital Converter ****
ADEN = 7 ; ADCSR
ADSC = 6
ADFR = 5
ADIF = 4
ADIE = 3
ADPS2 = 2
ADPS1 = 1
ADPS0 = 0
REFS1 =7 ; ADMUX
REFS0 =6
ADLAR =5
MUX4 =4
MUX3 =3
MUX2 =2
MUX1 =1
MUX0 =0
;**** Analog Comparator ****
ACD = 7 ; ACSR
ACBG = 6
ACO = 5
ACI = 4
ACIE = 3
ACIC = 2
ACIS1 = 1
ACIS0 = 0
;**** External Interrupts ****
INT7 = 7 ; EIMSK
INT6 = 6
INT5 = 5
INT4 = 4
INT3 = 3
INT2 = 2
INT1 = 1
INT0 = 0
INTF7 = 7 ; EIFR
INTF6 = 6
INTF5 = 5
INTF4 = 4
INTF3 = 3
INTF2 = 2
INTF1 = 1
INTF0 = 0
ISC71 = 7 ; EICRB
ISC70 = 6
ISC61 = 5
ISC60 = 4
ISC51 = 3
ISC50 = 2
ISC41 = 1
ISC40 = 0
ISC31 = 7 ; EICRA
ISC30 = 6
ISC21 = 5
ISC20 = 4
ISC11 = 3
ISC10 = 2
ISC01 = 1
ISC00 = 0
;**** Timer Interrupts ****
OCIE2 = 7 ; TIMSK
TOIE2 = 6
TICIE1 = 5
OCIE1A = 4
OCIE1B = 3
TOIE1 = 2
OCIE0 = 1
TOIE0 = 0
TICIE3 = 5 ; ETIMSK
OCIE3A = 4
OCIE3B = 3
TOIE3 = 2
OCIE3C = 1
OCIE1C = 0
OCF2 = 7 ; TIFR
TOV2 = 6
ICF1 = 5
OCF1A = 4
OCF1B = 3
TOV1 = 2
OCF0 = 1
TOV0 = 0
ICF3 = 5 ; ETIFR
OCF3A = 4
OCF3B = 3
TOV3 = 2
OCF3C = 1
OCF1C = 0
;**** Asynchronous Timer ****
AS0 = 3 ; ASSR
TCN0UB = 2
OCR0UB = 1
TCR0UB = 0
;**** Timer 0 ****
FOC0 = 7 ; TCCR0
WGM00 = 6
COM01 = 5
COM00 = 4
WGM01 = 3
CS02 = 2
CS01 = 1
CS00 = 0
;**** Timer 1 ****
COM1A1 = 7 ; TCCR1A
COM1A0 = 6
COM1B1 = 5
COM1B0 = 4
COM1C1 = 3
COM1C0 = 2
PWM11 = 1 ; OBSOLETE! Use WGM11
PWM10 = 0 ; OBSOLETE! Use WGM10
WGM11 = 1
WGM10 = 0
ICNC1 = 7 ; TCCR1B
ICES1 = 6
CTC11 = 4 ; OBSOLETE! Use WGM13
CTC10 = 3 ; OBSOLETE! Use WGM12
WGM13 = 4
WGM12 = 3
CS12 = 2
CS11 = 1
CS10 = 0
FOC1A = 7 ; TCCR1C
FOC1B = 6
FOC1C = 5
;**** Timer 2 ****
FOC2 = 7 ; TCCR2
WGM20 = 6
COM21 = 5
COM20 = 4
WGM21 = 3
CS22 = 2
CS21 = 1
CS20 = 0
;**** Timer 3 ****
COM3A1 = 7 ; TCCR3A
COM3A0 = 6
COM3B1 = 5
COM3B0 = 4
COM3C1 = 3
COM3C0 = 2
PWM31 = 1 ; OBSOLETE! Use WGM31
PWM30 = 0 ; OBSOLETE! Use WGM30
WGM31 = 1
WGM30 = 0
ICNC3 = 7 ; TCCR3B
ICES3 = 6
CTC31 = 4 ; OBSOLETE! Use WGM33
CTC30 = 3 ; OBSOLETE! Use WGM32
WGM33 = 4
WGM32 = 3
CS32 = 2
CS31 = 1
CS30 = 0
FOC3A = 7 ; TCCR3C
FOC3B = 6
FOC3C = 5
;**** Watchdog Timer ****
WDCE = 4 ; WDTCR
WDTOE = 4 ; For Mega103 compability
WDE = 3
WDP2 = 2
WDP1 = 1
WDP0 = 0
;**** EEPROM Control Register ****
EERIE = 3 ; EECR
EEMWE = 2
EEWE = 1
EERE = 0
;**** USART 0 and USART 1 ****
RXC = 7 ; (UCSRA0/1)
TXC = 6
UDRE = 5
FE = 4
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DDG0 = 0
PING4 = 4 ; PING
PING3 = 3
PING2 = 2
PING1 = 1
PING0 = 0
;*****************************************************************************
; CPU Register Declarations
;*****************************************************************************
.define XL r26 ; X pointer low
.define XH r27 ; X pointer high
.define YL r28 ; Y pointer low
.define YH r29 ; Y pointer high
.define ZL r30 ; Z pointer low
.define ZH r31 ; Z pointer high
;*****************************************************************************
; Data Memory Declarations
;*****************************************************************************
RAMEND = $10ff ; Highest internal data memory (SRAM) address.
EEPROMEND = $0fff ; Highest EEPROM address.
;*****************************************************************************
; Program Memory Declarations
;*****************************************************************************
FLASHEND = $FFFF ; Highest program memory (flash) address
; (When addressed as 16 bit words)
;**** Boot Vectors ****
; byte groups
; /--\/--\/--\/--\
SMALLBOOTSTART = 0b1111111000000000 ; ($FE00) Smallest boot block is 512W
SECONDBOOTSTART = 0b1111110000000000 ; ($FC00) 2'nd boot block size is 1KW
THIRDBOOTSTART = 0b1111100000000000 ; ($F800) Third boot block size is 2KW
LARGEBOOTSTART = 0b1111000000000000 ; ($F000) Largest boot block is 4KW
;**** Page Size ****
PAGESIZE = 128 ; Number of WORDS in a page
;**** Interrupt Vectors ****
INT0addr = $002 ; External Interrupt0 Vector Address
INT1addr = $004 ; External Interrupt1 Vector Address
INT2addr = $006 ; External Interrupt2 Vector Address
INT3addr = $008 ; External Interrupt3 Vector Address
INT4addr = $00a ; External Interrupt4 Vector Address
INT5addr = $00c ; External Interrupt5 Vector Address
INT6addr = $00e ; External Interrupt6 Vector Address
INT7addr = $010 ; External Interrupt7 Vector Address
OC2addr = $012 ; Output Compare2 Interrupt Vector Address
OVF2addr = $014 ; Overflow2 Interrupt Vector Address
ICP1addr = $016 ; Input Capture1 Interrupt Vector Address
OC1Aaddr = $018 ; Output Compare1A Interrupt Vector Address
OC1Baddr = $01a ; Output Compare1B Interrupt Vector Address
OVF1addr = $01c ; Overflow1 Interrupt Vector Address
OC0addr = $01e ; Output Compare0 Interrupt Vector Address
OVF0addr = $020 ; Overflow0 Interrupt Vector Address
SPIaddr = $022 ; SPI Interrupt Vector Address
URXC0addr = $024 ; USART0 Receive Complete Interrupt Vector Address
UDRE0addr = $026 ; USART0 Data Register Empty Interrupt Vector Address
UTXC0addr = $028 ; USART0 Transmit Complete Interrupt Vector Address
ADCCaddr = $02a ; ADC Conversion Complete Handle
ERDYaddr = $02c ; EEPROM Write Complete Handle
ACIaddr = $02e ; Analog Comparator Interrupt Vector Address
OC1Caddr = $030 ; Output Compare1C Interrupt Vector Address
ICP3addr = $032 ; Input Capture3 Interrupt Vector Address
OC3Aaddr = $034 ; Output Compare3A Interrupt Vector Address
OC3Baddr = $036 ; Output Compare3B Interrupt Vector Address
OC3Caddr = $038 ; Output Compare3C Interrupt Vector Address
OVF3addr = $03A ; Overflow3 Interrupt Vector Address
URXC1addr = $03C ; USART1 Receive Complete Interrupt Vector Address
UDRE1addr = $03E ; USART1 Data Register Empty Interrupt Vector Address
UTXC1addr = $040 ; USART1 Transmit Complete Interrupt Vector Address
TWIaddr = $042 ; TWI Interrupt Vector Address
SPMRaddr = $044 ; Store Program Memory Ready Interrupt Vector Address
;**** End of File ****
答 12: 是在iccAVR中编吗?aiom128.s不是汇编的头文件吗?
怎么不用这个呢?
问一下
是不是这样调用
;;;void testasm(void);
_testasm::
.....///
这是(*.s)
void main(viod)
{
;;;;
testasm();
;;;;;;;
}
两个文件在一个工程里。。
这样调用可以吗?
我模拟一下,怎么没有反应呢??? 答 13: 这样:extern void testasm(void);//in C
void main(void)
{
testasm();
}
//以下在in testasm.s
_testasm::
....
ret
{
asm("string of assemble \n"
"another string of assemble \n"
...
);
}
ok you CAN use this function now. 答 3: 我需要调用整个程序的,因为汇编程序很长 答 4: 你在汇编之前用asm,然后把汇编程序用括号括起来! 答 5: 汇编代码很长我不会要一句一句括吧 答 6: 看过来将你的汇编文件改名字为*.S,然后和C的主程序一起加入工程,在C中要调用的汇编函数在C中声明成外部函数,在汇编文件函数名前面加上下划线,后面是两个冒号,其他的不用改,编译就好了 答 7: 可是在汇编中不能写portd等的寄存器,只能用单片地址来表示吗也不能用equ等伪指令
有没有办法,能使这个汇编能像纯汇编那样运用自如 答 8: 可以的我的做法是将汇编文件包含的头文件中的.equ去掉,只留下UDR1 = $9C,这样的语句,就可以编译通过了,这样c调用的汇编文件就和纯汇编一模一样了(指的是语法,格式当然稍有不同) 答 9: iccAVR库中有aiom128.s这是汇编头文件iccAVR库中有aiom128.s等等。这是汇编头文件 答 10: 这样的话就会出现新的问题:因为必须去掉相应的.def指令,那么
XL =r26
XH =r27
YL =r28
YH =r29
ZL =r30
ZH =r31
就会出现r26..r31等等出错,因此在汇编中无法使用x、y、z
这该怎么办 答 11: .def指令不要去掉下面是我改的128的头文件,你要是用128的话,可以直接考过去用,不是的话就仿照改吧
m128def.inc
/**********************************************/
;***************************************************************************
;* A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y
;*
;* Number : AVR000
;* File Name : "m128def.inc"
;* Title : Register/Bit Definitions for the ATmega128
;* Date : 07.09.2001
;* Version : 1.0
;* Support telephone : +47 72 88 43 88 (ATMEL Norway)
;* Support fax : +47 72 88 43 99 (ATMEL Norway)
;* Support E-mail : AVR@atmel.no
;* Target MCU : ATmega128
;*
;* DESCRIPTION
;* When including this file in the assembly program file, all I/O register
;* names and I/O register bit names appearing in the data book CAN be used.
;* In addition, the six registers forming the three data pointers X, Y and
;* Z have been assigned names XL - ZH. Highest RAM address for Internal
;* SRAM is also defined
;*
;* The Register names are represented by their hexadecimal address.
;*
;* The Register Bit names are represented by their bit number (0-7).
;*
;* Please observe the difference in using the bit names with instructions
;* such as "sbr"/"cbr" (set/clear bit in register) and "sbrs"/"sbrc"
;* (skip if bit in register set/cleared). The following example illustrates
;* this:
;*
;* in r16,PORTB ;read PORTB latch
;* sbr r16,(1<<PB6)+(1<<PB5) ;set PB6 and PB5 (use masks, not bit#)
;* out PORTB,r16 ;output to PORTB
;*
;* in r16,TIFR ;read the Timer Interrupt Flag Register
;* sbrc r16,TOV0 ;test the overflow flag (use bit#)
;* rjmp TOV0_is_set ;jump if set
;* ... ;otherwise do something else
;***************************************************************************
;**** Specify Device ****
;.device ATmega128
;*****************************************************************************
; I/O Register Definitions
;*****************************************************************************
;**** Memory Mapped I/O Register Definitions ($FF-$60) ****
UCSR1C = $9D
UDR1 = $9C
UCSR1A = $9B
UCSR1B = $9A
UBRR1L = $99
UBRR1H = $98
UCSR0C = $95
UBRR0H = $90
TCCR3C = $8C
TCCR3A = $8B
TCCR3B = $8A
TCNT3H = $89
TCNT3L = $88
OCR3AH = $87
OCR3AL = $86
OCR3BH = $85
OCR3BL = $84
OCR3CH = $83
OCR3CL = $82
ICR3H = $81
ICR3L = $80
ETIMSK = $7D
ETIFR = $7C
TCCR1C = $7A
OCR1CH = $79
OCR1CL = $78
TWCR = $74
TWDR = $73
TWAR = $72
TWSR = $71
TWBR = $70
OSCCAL = $6F
XMCRA = $6D
XMCRB = $6C
EICRA = $6A
SPMCSR = $68
SPMCR = $68 ; old name for SPMCSR
PORTG = $65
DDRG = $64
PING = $63
PORTF = $62
DDRF = $61
;**** I/O Register Definitions ($3F-$00) ****
SREG = $3F
SPH = $3E
SPL = $3D
XDIV = $3C
RAMPZ = $3B
EICRB = $3A
EIMSK = $39
GIMSK = $39 ; old name for EIMSK
GICR = $39 ; old name for EIMSK
EIFR = $38
GIFR = $38 ; old name for EIFR
TIMSK = $37
TIFR = $36
MCUCR = $35
MCUCSR = $34
TCCR0 = $33
TCNT0 = $32
OCR0 = $31
ASSR = $30
TCCR1A = $2F
TCCR1B = $2E
TCNT1H = $2D
TCNT1L = $2C
OCR1AH = $2B
OCR1AL = $2A
OCR1BH = $29
OCR1BL = $28
ICR1H = $27
ICR1L = $26
TCCR2 = $25
TCNT2 = $24
OCR2 = $23
OCDR = $22 ; New
WDTCR = $21
SFIOR = $20 ; New
EEARH = $1F
EEARL = $1E
EEDR = $1D
EECR = $1C
PORTA = $1B
DDRA = $1A
PINA = $19
PORTB = $18
DDRB = $17
PINB = $16
PORTC = $15
DDRC = $14 ; New
PINC = $13 ; New
PORTD = $12
DDRD = $11
PIND = $10
SPDR = $0F
SPSR = $0E
SPCR = $0D
UDR0 = $0C
UCSR0A = $0B
UCSR0B = $0A
UBRR0L = $09
ACSR = $08
ADMUX = $07
ADCSR = $06
ADCH = $05
ADCL = $04
PORTE = $03
DDRE = $02
PINE = $01
PINF = $00
;*****************************************************************************
; Bit Definitions
;*****************************************************************************
;**** MCU Control ****
SRE = 7 ; MCUCR
SRW10 = 6
SE = 5
SM1 = 4
SM0 = 3
SM2 = 2
IVSEL = 1
IVCE = 0
JTD = 7 ; MCUCSR
JTRF = 4
WDRF = 3
BORF = 2
EXTRF = 1
PORF = 0
SRL2 =6 ; XMCRA
SRL1 =5
SRL0 =4
SRW01 =3
SRW00 =2
SRW11 =1
XMBK = 7 ; XMCRB
XMM2 = 2
XMM1 = 1
XMM0 = 0
SPMIE =7 ; SPMCSR
ASB =6 ; backwards compatiblity
ASRE =4 ; backwards compatiblity
RWWSB =6
RWWSRE =4
BLBSET =3
PGWRT =2
PGERS =1
SPMEN =0
IDRD = 7 ; OCDR
OCDR6 = 6
OCDR5 = 5
OCDR4 = 4
OCDR3 = 3
OCDR2 = 2
OCDR1 = 1
OCDR0 = 0
XDIVEN = 7 ; XDIV
XDIV6 = 6
XDIV5 = 5
XDIV4 = 4
XDIV3 = 3
XDIV2 = 2
XDIV1 = 1
XDIV0 = 0
TSM = 7 ; SFIOR
ADHSM = 4
ACME = 3
PUD = 2
PSR0 = 1
PSR1 = 0
PSR2 = 0
PSR3 = 0
PSR321 = 0
;**** Analog to Digital Converter ****
ADEN = 7 ; ADCSR
ADSC = 6
ADFR = 5
ADIF = 4
ADIE = 3
ADPS2 = 2
ADPS1 = 1
ADPS0 = 0
REFS1 =7 ; ADMUX
REFS0 =6
ADLAR =5
MUX4 =4
MUX3 =3
MUX2 =2
MUX1 =1
MUX0 =0
;**** Analog Comparator ****
ACD = 7 ; ACSR
ACBG = 6
ACO = 5
ACI = 4
ACIE = 3
ACIC = 2
ACIS1 = 1
ACIS0 = 0
;**** External Interrupts ****
INT7 = 7 ; EIMSK
INT6 = 6
INT5 = 5
INT4 = 4
INT3 = 3
INT2 = 2
INT1 = 1
INT0 = 0
INTF7 = 7 ; EIFR
INTF6 = 6
INTF5 = 5
INTF4 = 4
INTF3 = 3
INTF2 = 2
INTF1 = 1
INTF0 = 0
ISC71 = 7 ; EICRB
ISC70 = 6
ISC61 = 5
ISC60 = 4
ISC51 = 3
ISC50 = 2
ISC41 = 1
ISC40 = 0
ISC31 = 7 ; EICRA
ISC30 = 6
ISC21 = 5
ISC20 = 4
ISC11 = 3
ISC10 = 2
ISC01 = 1
ISC00 = 0
;**** Timer Interrupts ****
OCIE2 = 7 ; TIMSK
TOIE2 = 6
TICIE1 = 5
OCIE1A = 4
OCIE1B = 3
TOIE1 = 2
OCIE0 = 1
TOIE0 = 0
TICIE3 = 5 ; ETIMSK
OCIE3A = 4
OCIE3B = 3
TOIE3 = 2
OCIE3C = 1
OCIE1C = 0
OCF2 = 7 ; TIFR
TOV2 = 6
ICF1 = 5
OCF1A = 4
OCF1B = 3
TOV1 = 2
OCF0 = 1
TOV0 = 0
ICF3 = 5 ; ETIFR
OCF3A = 4
OCF3B = 3
TOV3 = 2
OCF3C = 1
OCF1C = 0
;**** Asynchronous Timer ****
AS0 = 3 ; ASSR
TCN0UB = 2
OCR0UB = 1
TCR0UB = 0
;**** Timer 0 ****
FOC0 = 7 ; TCCR0
WGM00 = 6
COM01 = 5
COM00 = 4
WGM01 = 3
CS02 = 2
CS01 = 1
CS00 = 0
;**** Timer 1 ****
COM1A1 = 7 ; TCCR1A
COM1A0 = 6
COM1B1 = 5
COM1B0 = 4
COM1C1 = 3
COM1C0 = 2
PWM11 = 1 ; OBSOLETE! Use WGM11
PWM10 = 0 ; OBSOLETE! Use WGM10
WGM11 = 1
WGM10 = 0
ICNC1 = 7 ; TCCR1B
ICES1 = 6
CTC11 = 4 ; OBSOLETE! Use WGM13
CTC10 = 3 ; OBSOLETE! Use WGM12
WGM13 = 4
WGM12 = 3
CS12 = 2
CS11 = 1
CS10 = 0
FOC1A = 7 ; TCCR1C
FOC1B = 6
FOC1C = 5
;**** Timer 2 ****
FOC2 = 7 ; TCCR2
WGM20 = 6
COM21 = 5
COM20 = 4
WGM21 = 3
CS22 = 2
CS21 = 1
CS20 = 0
;**** Timer 3 ****
COM3A1 = 7 ; TCCR3A
COM3A0 = 6
COM3B1 = 5
COM3B0 = 4
COM3C1 = 3
COM3C0 = 2
PWM31 = 1 ; OBSOLETE! Use WGM31
PWM30 = 0 ; OBSOLETE! Use WGM30
WGM31 = 1
WGM30 = 0
ICNC3 = 7 ; TCCR3B
ICES3 = 6
CTC31 = 4 ; OBSOLETE! Use WGM33
CTC30 = 3 ; OBSOLETE! Use WGM32
WGM33 = 4
WGM32 = 3
CS32 = 2
CS31 = 1
CS30 = 0
FOC3A = 7 ; TCCR3C
FOC3B = 6
FOC3C = 5
;**** Watchdog Timer ****
WDCE = 4 ; WDTCR
WDTOE = 4 ; For Mega103 compability
WDE = 3
WDP2 = 2
WDP1 = 1
WDP0 = 0
;**** EEPROM Control Register ****
EERIE = 3 ; EECR
EEMWE = 2
EEWE = 1
EERE = 0
;**** USART 0 and USART 1 ****
RXC = 7 ; (UCSRA0/1)
TXC = 6
UDRE = 5
FE = 4
DOR = 3
PE = 2 ; OBSOLETED!
U2X = 1
MPCM = 0
RXC0 = 7 ; (UCSR0A)
TXC0 = 6
UDRE0 = 5
FE0 = 4
DOR0 = 3
UPE0 = 2
U2X0 = 1
MPCM0 = 0
RXC1 = 7 ; (UCSR1A)
TXC1 = 6
UDRE1 = 5
FE1 = 4
DOR1 = 3
UPE1 = 2
U2X1 = 1
MPCM1 = 0
RXCIE = 7 ; (UCSRB0/1)
TXCIE = 6
UDRIE = 5
RXEN = 4
TXEN = 3
UCSZ2 = 2
RXB8 = 1
TXB8 = 0
RXCIE0 = 7 ; (UCSR0B)
TXCIE0 = 6
UDRIE0 = 5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 3
PE2 = 2
PE1 = 1
PE0 = 0
PORTE7 = 7 ; PORTE
PORTE6 = 6
PORTE5 = 5
PORTE4 = 4
PORTE3 = 3
PORTE2 = 2
PORTE1 = 1
PORTE0 = 0
DDE7 = 7 ; DDRE
DDE6 = 6
DDE5 = 5
DDE4 = 4
DDE3 = 3
DDE2 = 2
DDE1 = 1
DDE0 = 0
PINE7 = 7 ; PINE
PINE6 = 6
PINE5 = 5
PINE4 = 4
PINE3 = 3
PINE2 = 2
PINE1 = 1
PINE0 = 0
;**** PORT F ****
PF7 = 7 ; PORTF
PF6 = 6
PF5 = 5
PF4 = 4
PF3 = 3
PF2 = 2
PF1 = 1
PF0 = 0
PORTF7 = 7
PORTF6 = 6
PORTF5 = 5
PORTF4 = 4
PORTF3 = 3
PORTF2 = 2
PORTF1 = 1
PORTF0 = 0
DDF7 = 7 ; DDRF
DDF6 = 6
DDF5 = 5
DDF4 = 4
DDF3 = 3
DDF2 = 2
DDF1 = 1
DDF0 = 0
PINF7 = 7 ; PINF
PINF6 = 6
PINF5 = 5
PINF4 = 4
PINF3 = 3
PINF2 = 2
PINF1 = 1
PINF0 = 0
;**** PORT G ****
PG4 = 4 ; PORTG
PG3 = 3
PG2 = 2
PG1 = 1
PG0 = 0
DDG4 = 4 ; DDRG
DDG3 = 3
DDG2 = 2
DDG1 = 1
DDG0 = 0
PING4 = 4 ; PING
PING3 = 3
PING2 = 2
PING1 = 1
PING0 = 0
;*****************************************************************************
; CPU Register Declarations
;*****************************************************************************
.define XL r26 ; X pointer low
.define XH r27 ; X pointer high
.define YL r28 ; Y pointer low
.define YH r29 ; Y pointer high
.define ZL r30 ; Z pointer low
.define ZH r31 ; Z pointer high
;*****************************************************************************
; Data Memory Declarations
;*****************************************************************************
RAMEND = $10ff ; Highest internal data memory (SRAM) address.
EEPROMEND = $0fff ; Highest EEPROM address.
;*****************************************************************************
; Program Memory Declarations
;*****************************************************************************
FLASHEND = $FFFF ; Highest program memory (flash) address
; (When addressed as 16 bit words)
;**** Boot Vectors ****
; byte groups
; /--\/--\/--\/--\
SMALLBOOTSTART = 0b1111111000000000 ; ($FE00) Smallest boot block is 512W
SECONDBOOTSTART = 0b1111110000000000 ; ($FC00) 2'nd boot block size is 1KW
THIRDBOOTSTART = 0b1111100000000000 ; ($F800) Third boot block size is 2KW
LARGEBOOTSTART = 0b1111000000000000 ; ($F000) Largest boot block is 4KW
;**** Page Size ****
PAGESIZE = 128 ; Number of WORDS in a page
;**** Interrupt Vectors ****
INT0addr = $002 ; External Interrupt0 Vector Address
INT1addr = $004 ; External Interrupt1 Vector Address
INT2addr = $006 ; External Interrupt2 Vector Address
INT3addr = $008 ; External Interrupt3 Vector Address
INT4addr = $00a ; External Interrupt4 Vector Address
INT5addr = $00c ; External Interrupt5 Vector Address
INT6addr = $00e ; External Interrupt6 Vector Address
INT7addr = $010 ; External Interrupt7 Vector Address
OC2addr = $012 ; Output Compare2 Interrupt Vector Address
OVF2addr = $014 ; Overflow2 Interrupt Vector Address
ICP1addr = $016 ; Input Capture1 Interrupt Vector Address
OC1Aaddr = $018 ; Output Compare1A Interrupt Vector Address
OC1Baddr = $01a ; Output Compare1B Interrupt Vector Address
OVF1addr = $01c ; Overflow1 Interrupt Vector Address
OC0addr = $01e ; Output Compare0 Interrupt Vector Address
OVF0addr = $020 ; Overflow0 Interrupt Vector Address
SPIaddr = $022 ; SPI Interrupt Vector Address
URXC0addr = $024 ; USART0 Receive Complete Interrupt Vector Address
UDRE0addr = $026 ; USART0 Data Register Empty Interrupt Vector Address
UTXC0addr = $028 ; USART0 Transmit Complete Interrupt Vector Address
ADCCaddr = $02a ; ADC Conversion Complete Handle
ERDYaddr = $02c ; EEPROM Write Complete Handle
ACIaddr = $02e ; Analog Comparator Interrupt Vector Address
OC1Caddr = $030 ; Output Compare1C Interrupt Vector Address
ICP3addr = $032 ; Input Capture3 Interrupt Vector Address
OC3Aaddr = $034 ; Output Compare3A Interrupt Vector Address
OC3Baddr = $036 ; Output Compare3B Interrupt Vector Address
OC3Caddr = $038 ; Output Compare3C Interrupt Vector Address
OVF3addr = $03A ; Overflow3 Interrupt Vector Address
URXC1addr = $03C ; USART1 Receive Complete Interrupt Vector Address
UDRE1addr = $03E ; USART1 Data Register Empty Interrupt Vector Address
UTXC1addr = $040 ; USART1 Transmit Complete Interrupt Vector Address
TWIaddr = $042 ; TWI Interrupt Vector Address
SPMRaddr = $044 ; Store Program Memory Ready Interrupt Vector Address
;**** End of File ****
答 12: 是在iccAVR中编吗?aiom128.s不是汇编的头文件吗?
怎么不用这个呢?
问一下
是不是这样调用
;;;void testasm(void);
_testasm::
.....///
这是(*.s)
void main(viod)
{
;;;;
testasm();
;;;;;;;
}
两个文件在一个工程里。。
这样调用可以吗?
我模拟一下,怎么没有反应呢??? 答 13: 这样:extern void testasm(void);//in C
void main(void)
{
testasm();
}
//以下在in testasm.s
_testasm::
....
ret
共3条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 | |
【分享评测,赢取加热台】使用8051单片机驱动WS2812被打赏40分 |