GAS LISTING /tmp/ccuqzYdS.s page 1 1 .file "test.c" 2 __SP_H__ = 0x3e 3 __SP_L__ = 0x3d 4 __SREG__ = 0x3f 5 __tmp_reg__ = 0 6 __zero_reg__ = 1 9 .text 10 .Ltext0: 104 .global delay_ms 106 delay_ms: 107 .stabd 46,0,0 1:test.c **** #include 2:test.c **** #include 3:test.c **** #include 4:test.c **** #include 5:test.c **** #include 6:test.c **** 7:test.c **** void delay_ms(uint32_t time) { 109 .LM0: 110 .LFBB1: 111 0000 0F93 push r16 112 0002 1F93 push r17 113 /* prologue: function */ 114 /* frame size = 0 */ 115 /* stack size = 2 */ 116 .L__stack_usage = 2 8:test.c **** uint32_t i; 9:test.c **** for (i = 0; i < time; i++) { 118 .LM1: 119 0004 00E0 ldi r16,0 120 0006 10E0 ldi r17,0 121 0008 9801 movw r18,r16 122 .L2: 124 .LM2: 125 000a 0617 cp r16,r22 126 000c 1707 cpc r17,r23 127 000e 2807 cpc r18,r24 128 0010 3907 cpc r19,r25 129 0012 01F0 breq .L5 130 .LBB7: 131 .LBB8: 133 .Ltext1: 1:/usr/lib/avr/include/util/delay.h **** /* Copyright (c) 2002, Marek Michalkiewicz 2:/usr/lib/avr/include/util/delay.h **** Copyright (c) 2004,2005,2007 Joerg Wunsch 3:/usr/lib/avr/include/util/delay.h **** Copyright (c) 2007 Florin-Viorel Petrov 4:/usr/lib/avr/include/util/delay.h **** All rights reserved. 5:/usr/lib/avr/include/util/delay.h **** 6:/usr/lib/avr/include/util/delay.h **** Redistribution and use in source and binary forms, with or without 7:/usr/lib/avr/include/util/delay.h **** modification, are permitted provided that the following conditions are met: 8:/usr/lib/avr/include/util/delay.h **** 9:/usr/lib/avr/include/util/delay.h **** * Redistributions of source code must retain the above copyright 10:/usr/lib/avr/include/util/delay.h **** notice, this list of conditions and the following disclaimer. 11:/usr/lib/avr/include/util/delay.h **** 12:/usr/lib/avr/include/util/delay.h **** * Redistributions in binary form must reproduce the above copyright 13:/usr/lib/avr/include/util/delay.h **** notice, this list of conditions and the following disclaimer in 14:/usr/lib/avr/include/util/delay.h **** the documentation and/or other materials provided with the 15:/usr/lib/avr/include/util/delay.h **** distribution. GAS LISTING /tmp/ccuqzYdS.s page 2 16:/usr/lib/avr/include/util/delay.h **** 17:/usr/lib/avr/include/util/delay.h **** * Neither the name of the copyright holders nor the names of 18:/usr/lib/avr/include/util/delay.h **** contributors may be used to endorse or promote products derived 19:/usr/lib/avr/include/util/delay.h **** from this software without specific prior written permission. 20:/usr/lib/avr/include/util/delay.h **** 21:/usr/lib/avr/include/util/delay.h **** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22:/usr/lib/avr/include/util/delay.h **** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23:/usr/lib/avr/include/util/delay.h **** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24:/usr/lib/avr/include/util/delay.h **** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25:/usr/lib/avr/include/util/delay.h **** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26:/usr/lib/avr/include/util/delay.h **** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27:/usr/lib/avr/include/util/delay.h **** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28:/usr/lib/avr/include/util/delay.h **** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29:/usr/lib/avr/include/util/delay.h **** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30:/usr/lib/avr/include/util/delay.h **** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31:/usr/lib/avr/include/util/delay.h **** POSSIBILITY OF SUCH DAMAGE. */ 32:/usr/lib/avr/include/util/delay.h **** 33:/usr/lib/avr/include/util/delay.h **** /* $Id$ */ 34:/usr/lib/avr/include/util/delay.h **** 35:/usr/lib/avr/include/util/delay.h **** #ifndef _UTIL_DELAY_H_ 36:/usr/lib/avr/include/util/delay.h **** #define _UTIL_DELAY_H_ 1 37:/usr/lib/avr/include/util/delay.h **** 38:/usr/lib/avr/include/util/delay.h **** #ifndef __HAS_DELAY_CYCLES 39:/usr/lib/avr/include/util/delay.h **** #define __HAS_DELAY_CYCLES 1 40:/usr/lib/avr/include/util/delay.h **** #endif 41:/usr/lib/avr/include/util/delay.h **** 42:/usr/lib/avr/include/util/delay.h **** #include 43:/usr/lib/avr/include/util/delay.h **** #include 44:/usr/lib/avr/include/util/delay.h **** #include 45:/usr/lib/avr/include/util/delay.h **** 46:/usr/lib/avr/include/util/delay.h **** /** \file */ 47:/usr/lib/avr/include/util/delay.h **** /** \defgroup util_delay : Convenience functions for busy-wait delay loops 48:/usr/lib/avr/include/util/delay.h **** \code 49:/usr/lib/avr/include/util/delay.h **** #define F_CPU 1000000UL // 1 MHz 50:/usr/lib/avr/include/util/delay.h **** //#define F_CPU 14.7456E6 51:/usr/lib/avr/include/util/delay.h **** #include 52:/usr/lib/avr/include/util/delay.h **** \endcode 53:/usr/lib/avr/include/util/delay.h **** 54:/usr/lib/avr/include/util/delay.h **** \note As an alternative method, it is possible to pass the 55:/usr/lib/avr/include/util/delay.h **** F_CPU macro down to the compiler from the Makefile. 56:/usr/lib/avr/include/util/delay.h **** Obviously, in that case, no \c \#define statement should be 57:/usr/lib/avr/include/util/delay.h **** used. 58:/usr/lib/avr/include/util/delay.h **** 59:/usr/lib/avr/include/util/delay.h **** The functions in this header file are wrappers around the basic 60:/usr/lib/avr/include/util/delay.h **** busy-wait functions from . They are meant as 61:/usr/lib/avr/include/util/delay.h **** convenience functions where actual time values can be specified 62:/usr/lib/avr/include/util/delay.h **** rather than a number of cycles to wait for. The idea behind is 63:/usr/lib/avr/include/util/delay.h **** that compile-time constant expressions will be eliminated by 64:/usr/lib/avr/include/util/delay.h **** compiler optimization so floating-point expressions can be used 65:/usr/lib/avr/include/util/delay.h **** to calculate the number of delay cycles needed based on the CPU 66:/usr/lib/avr/include/util/delay.h **** frequency passed by the macro F_CPU. 67:/usr/lib/avr/include/util/delay.h **** 68:/usr/lib/avr/include/util/delay.h **** \note In order for these functions to work as intended, compiler 69:/usr/lib/avr/include/util/delay.h **** optimizations must be enabled, and the delay time 70:/usr/lib/avr/include/util/delay.h **** must be an expression that is a known constant at 71:/usr/lib/avr/include/util/delay.h **** compile-time. If these requirements are not met, the resulting 72:/usr/lib/avr/include/util/delay.h **** delay will be much longer (and basically unpredictable), and GAS LISTING /tmp/ccuqzYdS.s page 3 73:/usr/lib/avr/include/util/delay.h **** applications that otherwise do not use floating-point calculations 74:/usr/lib/avr/include/util/delay.h **** will experience severe code bloat by the floating-point library 75:/usr/lib/avr/include/util/delay.h **** routines linked into the application. 76:/usr/lib/avr/include/util/delay.h **** 77:/usr/lib/avr/include/util/delay.h **** The functions available allow the specification of microsecond, and 78:/usr/lib/avr/include/util/delay.h **** millisecond delays directly, using the application-supplied macro 79:/usr/lib/avr/include/util/delay.h **** F_CPU as the CPU clock frequency (in Hertz). 80:/usr/lib/avr/include/util/delay.h **** 81:/usr/lib/avr/include/util/delay.h **** */ 82:/usr/lib/avr/include/util/delay.h **** 83:/usr/lib/avr/include/util/delay.h **** #if !defined(__DOXYGEN__) 84:/usr/lib/avr/include/util/delay.h **** static inline void _delay_us(double __us) __attribute__((always_inline)); 85:/usr/lib/avr/include/util/delay.h **** static inline void _delay_ms(double __ms) __attribute__((always_inline)); 86:/usr/lib/avr/include/util/delay.h **** #endif 87:/usr/lib/avr/include/util/delay.h **** 88:/usr/lib/avr/include/util/delay.h **** #ifndef F_CPU 89:/usr/lib/avr/include/util/delay.h **** /* prevent compiler error by supplying a default */ 90:/usr/lib/avr/include/util/delay.h **** # warning "F_CPU not defined for " 91:/usr/lib/avr/include/util/delay.h **** # define F_CPU 1000000UL 92:/usr/lib/avr/include/util/delay.h **** #endif 93:/usr/lib/avr/include/util/delay.h **** 94:/usr/lib/avr/include/util/delay.h **** #ifndef __OPTIMIZE__ 95:/usr/lib/avr/include/util/delay.h **** # warning "Compiler optimizations disabled; functions from won't work as designed" 96:/usr/lib/avr/include/util/delay.h **** #endif 97:/usr/lib/avr/include/util/delay.h **** 98:/usr/lib/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \ 99:/usr/lib/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \ 100:/usr/lib/avr/include/util/delay.h **** __STDC_HOSTED__ 101:/usr/lib/avr/include/util/delay.h **** # include 102:/usr/lib/avr/include/util/delay.h **** #endif 103:/usr/lib/avr/include/util/delay.h **** 104:/usr/lib/avr/include/util/delay.h **** /** 105:/usr/lib/avr/include/util/delay.h **** \ingroup util_delay 106:/usr/lib/avr/include/util/delay.h **** 107:/usr/lib/avr/include/util/delay.h **** Perform a delay of \c __ms milliseconds, using _delay_loop_2(). 108:/usr/lib/avr/include/util/delay.h **** 109:/usr/lib/avr/include/util/delay.h **** The macro F_CPU is supposed to be defined to a 110:/usr/lib/avr/include/util/delay.h **** constant defining the CPU clock frequency (in Hertz). 111:/usr/lib/avr/include/util/delay.h **** 112:/usr/lib/avr/include/util/delay.h **** The maximal possible delay is 262.14 ms / F_CPU in MHz. 113:/usr/lib/avr/include/util/delay.h **** 114:/usr/lib/avr/include/util/delay.h **** When the user request delay which exceed the maximum possible one, 115:/usr/lib/avr/include/util/delay.h **** _delay_ms() provides a decreased resolution functionality. In this 116:/usr/lib/avr/include/util/delay.h **** mode _delay_ms() will work with a resolution of 1/10 ms, providing 117:/usr/lib/avr/include/util/delay.h **** delays up to 6.5535 seconds (independent from CPU frequency). The 118:/usr/lib/avr/include/util/delay.h **** user will not be informed about decreased resolution. 119:/usr/lib/avr/include/util/delay.h **** 120:/usr/lib/avr/include/util/delay.h **** If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) 121:/usr/lib/avr/include/util/delay.h **** support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For 122:/usr/lib/avr/include/util/delay.h **** values greater than the maximal possible delay, overflows results in 123:/usr/lib/avr/include/util/delay.h **** no delay i.e., 0ms. 124:/usr/lib/avr/include/util/delay.h **** 125:/usr/lib/avr/include/util/delay.h **** Conversion of __us into clock cycles may not always result in integer. 126:/usr/lib/avr/include/util/delay.h **** By default, the clock cycles rounded up to next integer. This ensures that 127:/usr/lib/avr/include/util/delay.h **** the user gets atleast __us microseconds of delay. 128:/usr/lib/avr/include/util/delay.h **** 129:/usr/lib/avr/include/util/delay.h **** Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__ GAS LISTING /tmp/ccuqzYdS.s page 4 130:/usr/lib/avr/include/util/delay.h **** to round down and round to closest integer. 131:/usr/lib/avr/include/util/delay.h **** 132:/usr/lib/avr/include/util/delay.h **** Note: The new implementation of _delay_ms(double __ms) with 133:/usr/lib/avr/include/util/delay.h **** __builtin_avr_delay_cycles(unsigned long) support is not backward compatible. 134:/usr/lib/avr/include/util/delay.h **** User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay. 135:/usr/lib/avr/include/util/delay.h **** Also, the backward compatible 136:/usr/lib/avr/include/util/delay.h **** algorithm will be chosen if the code is compiled in a freestanding 137:/usr/lib/avr/include/util/delay.h **** environment (GCC option \c -ffreestanding), as the math functions 138:/usr/lib/avr/include/util/delay.h **** required for rounding are not available to the compiler then. 139:/usr/lib/avr/include/util/delay.h **** 140:/usr/lib/avr/include/util/delay.h **** */ 141:/usr/lib/avr/include/util/delay.h **** void 142:/usr/lib/avr/include/util/delay.h **** _delay_ms(double __ms) 143:/usr/lib/avr/include/util/delay.h **** { 144:/usr/lib/avr/include/util/delay.h **** double __tmp ; 145:/usr/lib/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \ 146:/usr/lib/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \ 147:/usr/lib/avr/include/util/delay.h **** __STDC_HOSTED__ 148:/usr/lib/avr/include/util/delay.h **** uint32_t __ticks_dc; 149:/usr/lib/avr/include/util/delay.h **** extern void __builtin_avr_delay_cycles(unsigned long); 150:/usr/lib/avr/include/util/delay.h **** __tmp = ((F_CPU) / 1e3) * __ms; 151:/usr/lib/avr/include/util/delay.h **** 152:/usr/lib/avr/include/util/delay.h **** #if defined(__DELAY_ROUND_DOWN__) 153:/usr/lib/avr/include/util/delay.h **** __ticks_dc = (uint32_t)fabs(__tmp); 154:/usr/lib/avr/include/util/delay.h **** 155:/usr/lib/avr/include/util/delay.h **** #elif defined(__DELAY_ROUND_CLOSEST__) 156:/usr/lib/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(fabs(__tmp)+0.5); 157:/usr/lib/avr/include/util/delay.h **** 158:/usr/lib/avr/include/util/delay.h **** #else 159:/usr/lib/avr/include/util/delay.h **** //round up by default 160:/usr/lib/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(ceil(fabs(__tmp))); 161:/usr/lib/avr/include/util/delay.h **** #endif 162:/usr/lib/avr/include/util/delay.h **** 163:/usr/lib/avr/include/util/delay.h **** __builtin_avr_delay_cycles(__ticks_dc); 135 .LM3: 136 0014 E7E8 ldi r30,lo8(4999) 137 0016 F3E1 ldi r31,hi8(4999) 138 0018 3197 1: sbiw r30,1 139 001a 01F4 brne 1b 140 001c 00C0 rjmp . 141 001e 0000 nop 142 .LBE8: 143 .LBE7: 145 .Ltext2: 147 .LM4: 148 0020 0F5F subi r16,-1 149 0022 1F4F sbci r17,-1 150 0024 2F4F sbci r18,-1 151 0026 3F4F sbci r19,-1 152 0028 00C0 rjmp .L2 153 .L5: 154 /* epilogue start */ 10:test.c **** _delay_ms(1); 11:test.c **** } 12:test.c **** } 156 .LM5: 157 002a 1F91 pop r17 GAS LISTING /tmp/ccuqzYdS.s page 5 158 002c 0F91 pop r16 159 002e 0895 ret 164 .Lscope1: 166 .stabd 78,0,0 168 .global GetADC 170 GetADC: 171 .stabd 46,0,0 13:test.c **** 14:test.c **** #define NOOP asm volatile("nop" ::) 15:test.c **** 16:test.c **** int GetADC() 17:test.c **** { 173 .LM6: 174 .LFBB2: 175 /* prologue: function */ 176 /* frame size = 0 */ 177 /* stack size = 0 */ 178 .L__stack_usage = 0 18:test.c **** int ra = ADC; 180 .LM7: 181 0030 86B1 in r24,0x6 182 0032 97B1 in r25,0x6+1 19:test.c **** // if( ra > 512 ) ra = 1024 - ra; 20:test.c **** if( ra > 512 ) ra = 0; 184 .LM8: 185 0034 8130 cpi r24,1 186 0036 22E0 ldi r18,2 187 0038 9207 cpc r25,r18 188 003a 04F0 brlt .L7 189 003c 80E0 ldi r24,0 190 003e 90E0 ldi r25,0 191 .L7: 21:test.c **** return ra; 22:test.c **** } 193 .LM9: 194 0040 0895 ret 199 .Lscope2: 201 .stabd 78,0,0 202 .section .text.startup,"ax",@progbits 204 .global main 206 main: 207 .stabd 46,0,0 23:test.c **** 24:test.c **** int main( ) 25:test.c **** { 209 .LM10: 210 .LFBB3: 211 /* prologue: function */ 212 /* frame size = 0 */ 213 /* stack size = 0 */ 214 .L__stack_usage = 0 26:test.c **** setup_spi(); 216 .LM11: 217 0000 00D0 rcall setup_spi 27:test.c **** OSCCAL0 = 0xf0; 219 .LM12: 220 0002 80EF ldi r24,lo8(-16) GAS LISTING /tmp/ccuqzYdS.s page 6 221 0004 8093 7400 sts 116,r24 28:test.c **** 29:test.c **** ADMUXA = 0x10; //ADC0 vs ADC1 223 .LM13: 224 0008 80E1 ldi r24,lo8(16) 225 000a 89B9 out 0x9,r24 30:test.c **** ADMUXB = 0x22; //100 gain, 1.1v. 227 .LM14: 228 000c 82E2 ldi r24,lo8(34) 229 000e 88B9 out 0x8,r24 31:test.c **** 32:test.c **** ADCSRB = 0; 231 .LM15: 232 0010 14B8 out 0x4,__zero_reg__ 33:test.c **** ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADPS2);// | _BV(ADPS0); 234 .LM16: 235 0012 84EE ldi r24,lo8(-28) 236 0014 85B9 out 0x5,r24 34:test.c **** 35:test.c **** DIDR0 = 3; 238 .LM17: 239 0016 83E0 ldi r24,lo8(3) 240 0018 8093 6000 sts 96,r24 241 .L13: 242 .LBB9: 36:test.c **** uint16_t radc = 0; 37:test.c **** while(1) 38:test.c **** { 39:test.c **** int i; 40:test.c **** for( i = 0; i < 32; i++ ) 244 .LM18: 245 001c 00E0 ldi r16,0 246 001e 10E0 ldi r17,0 247 .LBE9: 41:test.c **** { 42:test.c **** radc += GetADC(); _delay_us(10); 43:test.c **** } 44:test.c **** sendchr( 0 ); sendhex4(radc>>2); sendchr( '\n' ); 45:test.c **** radc = 0; 46:test.c **** //sendstr("Hello!\n"); 47:test.c **** } 249 .LM19: 250 0020 C0E0 ldi r28,0 251 0022 D0E0 ldi r29,0 252 .L10: 253 .LBB12: 40:test.c **** { 255 .LM20: 256 0024 0032 cpi r16,32 257 0026 1105 cpc r17,__zero_reg__ 258 0028 04F4 brge .L14 42:test.c **** } 260 .LM21: 261 002a 00D0 rcall GetADC 262 002c C80F add r28,r24 263 002e D91F adc r29,r25 264 .LBB10: GAS LISTING /tmp/ccuqzYdS.s page 7 265 .LBB11: 267 .Ltext3: 164:/usr/lib/avr/include/util/delay.h **** 165:/usr/lib/avr/include/util/delay.h **** #else 166:/usr/lib/avr/include/util/delay.h **** uint16_t __ticks; 167:/usr/lib/avr/include/util/delay.h **** __tmp = ((F_CPU) / 4e3) * __ms; 168:/usr/lib/avr/include/util/delay.h **** if (__tmp < 1.0) 169:/usr/lib/avr/include/util/delay.h **** __ticks = 1; 170:/usr/lib/avr/include/util/delay.h **** else if (__tmp > 65535) 171:/usr/lib/avr/include/util/delay.h **** { 172:/usr/lib/avr/include/util/delay.h **** // __ticks = requested delay in 1/10 ms 173:/usr/lib/avr/include/util/delay.h **** __ticks = (uint16_t) (__ms * 10.0); 174:/usr/lib/avr/include/util/delay.h **** while(__ticks) 175:/usr/lib/avr/include/util/delay.h **** { 176:/usr/lib/avr/include/util/delay.h **** // wait 1/10 ms 177:/usr/lib/avr/include/util/delay.h **** _delay_loop_2(((F_CPU) / 4e3) / 10); 178:/usr/lib/avr/include/util/delay.h **** __ticks --; 179:/usr/lib/avr/include/util/delay.h **** } 180:/usr/lib/avr/include/util/delay.h **** return; 181:/usr/lib/avr/include/util/delay.h **** } 182:/usr/lib/avr/include/util/delay.h **** else 183:/usr/lib/avr/include/util/delay.h **** __ticks = (uint16_t)__tmp; 184:/usr/lib/avr/include/util/delay.h **** _delay_loop_2(__ticks); 185:/usr/lib/avr/include/util/delay.h **** #endif 186:/usr/lib/avr/include/util/delay.h **** } 187:/usr/lib/avr/include/util/delay.h **** 188:/usr/lib/avr/include/util/delay.h **** /** 189:/usr/lib/avr/include/util/delay.h **** \ingroup util_delay 190:/usr/lib/avr/include/util/delay.h **** 191:/usr/lib/avr/include/util/delay.h **** Perform a delay of \c __us microseconds, using _delay_loop_1(). 192:/usr/lib/avr/include/util/delay.h **** 193:/usr/lib/avr/include/util/delay.h **** The macro F_CPU is supposed to be defined to a 194:/usr/lib/avr/include/util/delay.h **** constant defining the CPU clock frequency (in Hertz). 195:/usr/lib/avr/include/util/delay.h **** 196:/usr/lib/avr/include/util/delay.h **** The maximal possible delay is 768 us / F_CPU in MHz. 197:/usr/lib/avr/include/util/delay.h **** 198:/usr/lib/avr/include/util/delay.h **** If the user requests a delay greater than the maximal possible one, 199:/usr/lib/avr/include/util/delay.h **** _delay_us() will automatically call _delay_ms() instead. The user 200:/usr/lib/avr/include/util/delay.h **** will not be informed about this case. 201:/usr/lib/avr/include/util/delay.h **** 202:/usr/lib/avr/include/util/delay.h **** If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) 203:/usr/lib/avr/include/util/delay.h **** support, maximal possible delay is 4294967.295 us/ F_CPU in MHz. For 204:/usr/lib/avr/include/util/delay.h **** values greater than the maximal possible delay, overflow results in 205:/usr/lib/avr/include/util/delay.h **** no delay i.e., 0us. 206:/usr/lib/avr/include/util/delay.h **** 207:/usr/lib/avr/include/util/delay.h **** Conversion of __us into clock cycles may not always result in integer. 208:/usr/lib/avr/include/util/delay.h **** By default, the clock cycles rounded up to next integer. This ensures that 209:/usr/lib/avr/include/util/delay.h **** the user gets atleast __us microseconds of delay. 210:/usr/lib/avr/include/util/delay.h **** 211:/usr/lib/avr/include/util/delay.h **** Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__ 212:/usr/lib/avr/include/util/delay.h **** to round down and round to closest integer. 213:/usr/lib/avr/include/util/delay.h **** 214:/usr/lib/avr/include/util/delay.h **** Note: The new implementation of _delay_us(double __us) with 215:/usr/lib/avr/include/util/delay.h **** __builtin_avr_delay_cycles(unsigned long) support is not backward compatible. 216:/usr/lib/avr/include/util/delay.h **** User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay. 217:/usr/lib/avr/include/util/delay.h **** Also, the backward compatible 218:/usr/lib/avr/include/util/delay.h **** algorithm will be chosen if the code is compiled in a freestanding GAS LISTING /tmp/ccuqzYdS.s page 8 219:/usr/lib/avr/include/util/delay.h **** environment (GCC option \c -ffreestanding), as the math functions 220:/usr/lib/avr/include/util/delay.h **** required for rounding are not available to the compiler then. 221:/usr/lib/avr/include/util/delay.h **** 222:/usr/lib/avr/include/util/delay.h **** */ 223:/usr/lib/avr/include/util/delay.h **** void 224:/usr/lib/avr/include/util/delay.h **** _delay_us(double __us) 225:/usr/lib/avr/include/util/delay.h **** { 226:/usr/lib/avr/include/util/delay.h **** double __tmp ; 227:/usr/lib/avr/include/util/delay.h **** #if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \ 228:/usr/lib/avr/include/util/delay.h **** !defined(__DELAY_BACKWARD_COMPATIBLE__) && \ 229:/usr/lib/avr/include/util/delay.h **** __STDC_HOSTED__ 230:/usr/lib/avr/include/util/delay.h **** uint32_t __ticks_dc; 231:/usr/lib/avr/include/util/delay.h **** extern void __builtin_avr_delay_cycles(unsigned long); 232:/usr/lib/avr/include/util/delay.h **** __tmp = ((F_CPU) / 1e6) * __us; 233:/usr/lib/avr/include/util/delay.h **** 234:/usr/lib/avr/include/util/delay.h **** #if defined(__DELAY_ROUND_DOWN__) 235:/usr/lib/avr/include/util/delay.h **** __ticks_dc = (uint32_t)fabs(__tmp); 236:/usr/lib/avr/include/util/delay.h **** 237:/usr/lib/avr/include/util/delay.h **** #elif defined(__DELAY_ROUND_CLOSEST__) 238:/usr/lib/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(fabs(__tmp)+0.5); 239:/usr/lib/avr/include/util/delay.h **** 240:/usr/lib/avr/include/util/delay.h **** #else 241:/usr/lib/avr/include/util/delay.h **** //round up by default 242:/usr/lib/avr/include/util/delay.h **** __ticks_dc = (uint32_t)(ceil(fabs(__tmp))); 243:/usr/lib/avr/include/util/delay.h **** #endif 244:/usr/lib/avr/include/util/delay.h **** 245:/usr/lib/avr/include/util/delay.h **** __builtin_avr_delay_cycles(__ticks_dc); 269 .LM22: 270 0030 82E4 ldi r24,lo8(66) 271 0032 8A95 1: dec r24 272 0034 01F4 brne 1b 273 0036 00C0 rjmp . 274 .LBE11: 275 .LBE10: 277 .Ltext4: 40:test.c **** { 279 .LM23: 280 0038 0F5F subi r16,-1 281 003a 1F4F sbci r17,-1 282 003c 00C0 rjmp .L10 283 .L14: 44:test.c **** radc = 0; 285 .LM24: 286 003e 80E0 ldi r24,0 287 0040 00D0 rcall sendchr 288 0042 CE01 movw r24,r28 289 0044 9695 lsr r25 290 0046 8795 ror r24 291 0048 9695 lsr r25 292 004a 8795 ror r24 293 004c 00D0 rcall sendhex4 294 004e 8AE0 ldi r24,lo8(10) 295 0050 00D0 rcall sendchr 296 0052 00C0 rjmp .L13 297 .LBE12: 308 .Lscope3: 310 .stabd 78,0,0 GAS LISTING /tmp/ccuqzYdS.s page 9 311 .text 313 .Letext0: 314 .ident "GCC: (GNU) 4.8.1" GAS LISTING /tmp/ccuqzYdS.s page 10 DEFINED SYMBOLS *ABS*:0000000000000000 test.c /tmp/ccuqzYdS.s:2 *ABS*:000000000000003e __SP_H__ /tmp/ccuqzYdS.s:3 *ABS*:000000000000003d __SP_L__ /tmp/ccuqzYdS.s:4 *ABS*:000000000000003f __SREG__ /tmp/ccuqzYdS.s:5 *ABS*:0000000000000000 __tmp_reg__ /tmp/ccuqzYdS.s:6 *ABS*:0000000000000001 __zero_reg__ /tmp/ccuqzYdS.s:106 .text:0000000000000000 delay_ms /tmp/ccuqzYdS.s:170 .text:0000000000000030 GetADC /tmp/ccuqzYdS.s:206 .text.startup:0000000000000000 main UNDEFINED SYMBOLS setup_spi sendchr sendhex4