> unless you'd show me how There are examples in many places, including AVR Freaks, but it is pretty simple in concept. It gets a little messier if you want to ensure portability to other devices. I've shown some code below than can all be put in a .S file (note that it must be upper case S not lower case s). If you don't care about portability you can delete the macros and their usage, replacing them with the normal assembler instructions. The documentation for the gnu assembler, including the macro syntax, can be found on the Internet. You'll need to add an include file for the value of sInByte1 and you may have to modify that include file to keep the assembler from seeing parts that it doesn't know how to handle. This can be done with a conditional like #if !defined(__ASSEMBLER__). Don Kinzer ZBasic Microcontrollers http://www.zbasic.net // what follows is AVR assembly language code for avr-as #include <avr/io.h> // these definitions should go in a .h file #define IO(x) (_SFR_IO_ADDR(x)) // macro to input from an I/O port to a register .macro inPort _reg, _port .if (IO(\_port) < 64) in \_reg, IO(\_port) .else lds \_reg, \_port .endif .endm // macro to output from a register to an I/O port .macro outPort _port, _reg .if (IO(\_port) < 64) out IO(\_port), \_reg .else sts \_port, \_reg .endif .endm // macro to skip the next instruction if a bit in an I/O port is set .macro skbs _port, _bit, _reg .if (IO(\_port) < 32) sbis IO(\_port), \_bit .else inPort \_reg, \_port sbrs \_reg, \_bit .endif .endm // end of definitions that should go in a .h file .section .text .global PCINT0_vect PCINT0_vect: push r24 inPort r24, SREG push r24 skbs PINB, PORTB2, r24 rjmp 1f ldi r24, _BV(SPIE) |_BV(SPE) | _BV(CPOL) outPort SPCR, r24 ldi r24, sInByte1 outPort GPIOR0, r24 1: pop r24 outPort SREG, r24 pop r24 reti .end
Message
Re: Any way to make interrupts faster, please?
2010-01-20 by Don Kinzer
Attachments
- No local attachments were found for this message.