1 | ;----------------------------------------------------------------------
|
2 | ; Title : myAVR Beispiel "Signalton mit Timer0" für den ATmega8
|
3 | ;----------------------------------------------------------------------
|
4 | ; Funktion : Ausgabe des Kammertion A
|
5 | ; Schaltung : PORTB.0=Summer, PORTB.1=LED-Rot
|
6 | ;----------------------------------------------------------------------
|
7 | ; Prozessor : ATmega8
|
8 | ; Takt : 3,6864 MHz
|
9 | ; Sprache : Assembler
|
10 | ; Datum : 09.11.2007
|
11 | ; Version : 1.0
|
12 | ; Autor : Renaldo Badke
|
13 | ; Programmer :
|
14 | ; Port :
|
15 | ;----------------------------------------------------------------------
|
16 | .equ F_CPU, 1000000
|
17 | .include "avr.h"
|
18 | ;-----------------------------------------------------------------------
|
19 | ;Reset and Interruptvectoren ;VNr. Beschreibung
|
20 | begin:
|
21 | rjmp main ; 1 POWER ON RESET
|
22 | reti ; 2 Int0-Interrupt
|
23 | reti ; 3 Int1-Interrupt
|
24 | reti ; 4 TC2 Compare Match
|
25 | reti ; 5 TC2 Overflow
|
26 | reti ; 6 TC1 Capture
|
27 | reti ; 7 TC1 Compare Match A
|
28 | reti ; 8 TC1 Compare Match B
|
29 | reti ; 9 TC1 Overflow
|
30 | rjmp onTC0 ;10 TC0 Overflow
|
31 | reti ;11 SPI, STC Serial Transfer Complete
|
32 | reti ;12 UART Rx Complete
|
33 | reti ;13 UART Data Register Empty
|
34 | reti ;14 UART Tx Complete
|
35 | reti ;15 ADC Conversion Complete
|
36 | reti ;16 EEPROM Ready
|
37 | reti ;17 Analog Comperator
|
38 | reti ;18 TWI (I²C) Serial Interface
|
39 | reti ;19 Strore Program Memory Ready
|
40 | ;------------------------------------------------------------------------
|
41 | ;Start, Power ON, Reset
|
42 | main:
|
43 | ldi r16,lo8(RAMEND)
|
44 | out ioSPL,r16 ;Init Stackpointer LO
|
45 | ldi r16,hi8(RAMEND)
|
46 | out ioSPH,r16 ;Init Stackpointer HI
|
47 |
|
48 | sbi ioDDRB,0 ;OUT Summer
|
49 | sbi ioDDRB,1 ;OUT LED
|
50 | cbi ioDDRD,2 ;Taster als eingang
|
51 | sbi ioDDRC,0 ;Led
|
52 |
|
53 | ldi r16,0b0000101
|
54 | out ioTCCR0,r16 ;Timer0 setup 1/14 Sekunde 3686400/1024
|
55 | ldi r16,0b0000001
|
56 | out ioTIMSK,r16 ;Interrupt Timer0 bei overflow
|
57 |
|
58 | ldi r17,190 ;Timer0 Init
|
59 | out ioTCNT0,r17 ;ausgeben
|
60 | ldi r16,0 ;Ausgabewert LOW
|
61 | sei
|
62 | ;------------------------------------------------------------------------
|
63 | mainloop:
|
64 | wdr
|
65 | sbis ioPIND,2 ;Taster offen
|
66 | rjmp end
|
67 | cbi ioPORTC,0 ;Led aus
|
68 | rjmp raus
|
69 | end: sbi ioPORTC,0 ;Led an
|
70 | raus: rjmp mainloop
|
71 | ;------------------------------------------------------------------------
|
72 | onTC0:
|
73 | cli ;Interrupts sperren
|
74 | push r16
|
75 | push r17
|
76 | in r16,ioPORTB ;PORTB einlesen
|
77 | com r16 ;Einerkomplement, Bitweise Negation
|
78 | out ioPORTB,r16 ;PORTB umschalten (Signalwechsel)
|
79 | ldi r17,19 ;berechneter Reinit-Wert
|
80 | out ioTCNT0,r17 ;Timer Reinit
|
81 | pop r17
|
82 | pop r16
|
83 | sei ;Interrupt freigeben
|
84 | reti ;Rücksprung
|
85 | ;------------------------------------------------------------------------
|