Download avr-libc-user-manual..
Transcript
7.2 avr-libc and assembler programs 7.2.3 60 Example program The following annotated example features a simple 100 kHz square wave generator using an AT90S1200 clocked with a 10.7 MHz crystal. Pin PD6 will be used for the square wave output. #include <avr/io.h> ; Note [1] work tmp = = 16 17 ; Note [2] inttmp = 19 intsav = 0 SQUARE = PD6 tmconst= 10700000 / 200000 fuzz= 8 ; Note [3] ; Note [4]: ; 100 kHz => 200000 edges/s ; # clocks in ISR until TCNT0 is set .section .text .global main ; Note [5] main: rcall ioinit rjmp 1b 1: .global SIG_OVERFLOW0 SIG_OVERFLOW0: ldi inttmp, 256 - tmconst + fuzz out _SFR_IO_ADDR(TCNT0), inttmp 1: 2: in intsav, _SFR_IO_ADDR(SREG) sbic rjmp sbi rjmp cbi _SFR_IO_ADDR(PORTD), SQUARE 1f _SFR_IO_ADDR(PORTD), SQUARE 2f _SFR_IO_ADDR(PORTD), SQUARE out reti _SFR_IO_ADDR(SREG), intsav sbi _SFR_IO_ADDR(DDRD), SQUARE ldi out work, _BV(TOIE0) _SFR_IO_ADDR(TIMSK), work ldi out work, _BV(CS00) ; tmr0: _SFR_IO_ADDR(TCCR0), work ; Note [6] ; Note [7] ; Note [8] ; Note [9] ioinit: Generated on Mon Dec 9 22:14:31 2002 for avr-libc by Doxygen CK/1