avr

Add numbers in AVR assembly

霸气de小男生 提交于 2019-12-08 09:25:45
问题 How can I do this in AVR assembly? I have 2 numbers (Little endian) in different reg. # Number 1 LDI R16 0x… LDI R17 0x… LDI R18 0x… LDI R19 0x… # Number 2 LDI R20 0x… LDI R21 0x… LDI R22 0x… LDI R23 0x… I want to add them together and save the result to R20 - R23. 回答1: Regarding the "math" behind it: It's just the same as in the decimal system: When adding two single digit numbers, two cases have to be considered. Either the sum of the two is a new single digit number (5+4 = 9), or an

ATMEGA32 UART Communication

别说谁变了你拦得住时间么 提交于 2019-12-08 03:50:51
问题 I am trying to do serial communication in ATMEGA32 and I have a question: In asynchronous serial communication both UBRRH and UCSRC registers have same location. I don't know which conditions that location will act as UBRRH and for which conditions, it will act as UCSRC . I need different values for each register according to the work assigned to those registers In the datasheet, they have mentioned the use of URSEL bit for selection betweem two registers but somehow I am not getting that.

Using Visual Studio to code for AVR

孤者浪人 提交于 2019-12-08 02:51:44
问题 I am using Visual Studio 2013 to write code for AVR. I have been following this tutorial. Whilst writing the code, I noticed that Visual Studio kept on underlining things like DDRB or PORTB and I keep on getting errors like Error: identifier "PORTB" is undefined , however, the program compiles correctly. Interestingly enough, upon pressing alt - F12 Visual finds numerous files where they are defined. 回答1: Your Makefile runs compiler with an option -mmcu=YOURCHIP. This implicitly defines macro

Basic high performance data authenticity

a 夏天 提交于 2019-12-07 19:46:33
问题 (I am not a native speaker and might not be correct in terms of terminology. Sorry about that.) I am transmitting data via radio between AVR microcontrollers for personal use and would like for clients to demonstrate the authenticity of transmitted data in that it originates from one of the authorized clients. This means I am not requiring non-repudiation and would be able to pre-define a shared key. I have done some research on different approaches and found that I need some assistance on

GCC generating useless code in ISR

好久不见. 提交于 2019-12-07 01:55:21
问题 I have a very simple Interrupt Service Routine(ISR) written for the atmega328 and compiled with avrgcc (using -Os) using AVR studio. ISR (TIMER0_OVF_vect) { txofcnt++; //count overflows and store in uint16_t } If you note the assembly generated (below), it uses r24, r25 to get the job incrementing the volatile uint16_t txofcnt, but it also push-write-pop r1, r28, r29 without ever reading them. It also has an extra push/pop of r0 without ever using it in between. I flat out don't understand

Avr asm label*2

青春壹個敷衍的年華 提交于 2019-12-06 16:00:02
Hi i am new in avr asm programming,in the example below, i have few questions: 1) Is it label: 8 bit or 16bit long? 2) Why multiplication label with 2 is needed? 3) Instruction LPM is placing their result in register R0? If so, what does that have to do with Z? 4) Can you explaine the quoted text from the provided link: "If the address is not multiplied by two and label is at byte address 0x60 (word address 0x30), Z will point at the code stored there. I hope this clarified the addressing problem. Other versions are" ldi ZL, low(2*label) ldi ZH, high(2*label) label: .db "Hello world", 0 lpm

ATMEGA32 UART Communication

房东的猫 提交于 2019-12-06 14:51:54
I am trying to do serial communication in ATMEGA32 and I have a question: In asynchronous serial communication both UBRRH and UCSRC registers have same location. I don't know which conditions that location will act as UBRRH and for which conditions, it will act as UCSRC . I need different values for each register according to the work assigned to those registers In the datasheet, they have mentioned the use of URSEL bit for selection betweem two registers but somehow I am not getting that. The answer is: Yes, the URSEL bit. According to the datasheet: When doing a write access of this I/O

AVR-GCC: Error: garbage at end of line

北慕城南 提交于 2019-12-06 09:03:47
问题 I have problem with stack init lines because avr-gcc returns LED_Blink.asm:10: Error: garbage at end of line On lines: ldi r17, low(RAMEND) ldi r17, high(RAMEND) And I am confused. I have already defined RAMEND. I used avr-gcc with this command: avr-gcc -x assembler -mmcu=atmega328p LED_Blink.asm My assembly code: .equ SPL, 0x3d .equ SPH, 0x3e .equ RAMEND, 0x8ff .equ PORTB, 0x05 .equ DDRB, 0x04 .org 0x000000 rjmp main main: ldi r17, low(RAMEND) out SPL, r17 ldi r17, high(RAMEND) out SPH, r17

Why doesn't this compiler barrier enforce ordering?

帅比萌擦擦* 提交于 2019-12-05 19:58:44
I was looking at the documentation on the Atmel website and I came across this example where they explain some issues with reordering. Here's the example code: #define cli() __asm volatile( "cli" ::: "memory" ) #define sei() __asm volatile( "sei" ::: "memory" ) unsigned int ivar; void test2( unsigned int val ) { val = 65535U / val; cli(); ivar = val; sei(); } In this example, they're implementing a critical region-like mechanism. The cli instruction disables interrupts and the sei instruction enables them. Normally, I would save the interrupt state and restore to that state, but I digress...

Optimising this C (AVR) code

这一生的挚爱 提交于 2019-12-05 01:58:29
I have an interrupt handler that just isn't running fast enough for what I want to do. Basically I'm using it to generate sine waves by outputting a value from a look up table to a PORT on an AVR microncontroller but, unfortunately, this isn't happening fast enough for me to get the frequency of the wave that I want. I was told that I should look at implementing it in assembly as the compiler generated assembly might be slightly inefficient and may be able to be optimised but after looking at the assembly code I really can't see what I could do any better. This is the C code: const uint8_t