1 | ; AVRStudio 4.08 Simulator error demo
|
2 |
|
3 | .include "tn15def.inc"
|
4 |
|
5 | .equ N = 31 ; 1.6MHz / (31+1) = 50kHz; T=20µs
|
6 | .def temp = r16 ; temporary storage register
|
7 | .def temp2 = r17 ; another temporary storage register
|
8 |
|
9 | .CSEG
|
10 | .org 0x000
|
11 | rjmp init ; jump to initialisation routine
|
12 | .org T1CPaddr
|
13 | rjmp pic ; jump to periodic interrupt service routine
|
14 |
|
15 | ;------------------------------------------------------------------------------------------------
|
16 | init:
|
17 | ldi ZH, 0x03
|
18 | ldi ZL, 0xFF
|
19 | lpm
|
20 | out OSCCAL, r0 ; calibrate internal RC Oscillator
|
21 |
|
22 | ldi temp, N
|
23 | out OCR1A, temp ; output compare interrupt after N clock cycles
|
24 |
|
25 | ldi temp, 0x40 ; OCIE1A = 1
|
26 | out TIMSK, temp ; enable Timer/Counter 1 compare interrupt
|
27 | sbi DDRB, 1 ; PB1 = OC1A (pin 6) is output
|
28 | ldi temp, 0xB5 ; clear counter on compare match, no PWM
|
29 | ; set OC1A = 1 on first compare match, prescaler = 1
|
30 | out TCCR1, temp ; start timer/counter 1
|
31 |
|
32 | sei
|
33 |
|
34 | ;------------------------------------------------------------------------------------------------
|
35 | main:
|
36 | rjmp main ; loop while waiting for interrupt
|
37 |
|
38 | ;------------------------------------------------------------------------------------------------
|
39 | pic:
|
40 | ; ldi temp, 0x40 ; AVR Studio 4.08 Simulator does not clear OCF1A in TIFR
|
41 | ; out TIFR, temp ; automatically upon executing interrupt.
|
42 | ; clear flag by writing a "1" to it!
|
43 |
|
44 | ldi temp, 0x10
|
45 | in temp2, TCCR1
|
46 | eor temp2, temp ; toggle OC1A at next Timer/Counter 1 compare match
|
47 | out TCCR1, temp2
|
48 | reti
|
49 |
|
50 | ;------------------------------------------------------------------------------------------------
|
51 | .org 0x01FF ; Atmel seems to store the default RC calibration value
|
52 | .dw 0x6868 ; at the last addresses of FLASH and EEPROM
|
53 |
|
54 | ; remarks
|
55 | ; Simulator shows timer/counter 1 compare match output changes to PB1 (OC1A)
|
56 | ; output pin even if PB1 (OC1A) is not explicitly configured as output.
|
57 | ; The actual device ATtiny15 requires BP1 to be explicitly defined as output.
|