Ich lese den Wert den an PortA und die ersten 3 von PortC ein und
erzeuge damit ein PWM Signal. Sobald der 3 te Pin von PortC logisch 1
ist sollte der PWM Ausgang abschalten und der Controller ist in einer
endlosschleife gefangen. (ganz unten)
; Programm:PWM Signal mit 10Bit Eingang
.nolist
.include "m16def.inc" ;Include Datei
.list
.org 0x000
rjmp init ; Falls Reset
.org 0x008
rjmp T2_OVF ;Timer2 Over Flow
.org 0x00C
rjmp T1_CMPA ;Timer 1 CMP A
.org 0x00E
rjmp T1_CMPB ;Timer 1 CMPB
;Register Definition
.def temp=r16
.def spswertl=r17
.def spswerth=r18
.def startwertl=r19
.def startwerth=r20
.def ausgang = r24
init:
ldi temp, HIGH(RAMEND)
out SPH, temp ; High s-ram Stapel (16bit)
ldi temp, LOW(RAMEND) ; LOW s-ram Stapel(8bit)
out SPL, temp
ldi ausgang,0
ldi temp,0
ldi spswertl,0
ldi spswerth,0
ldi startwertl,0
ldi startwerth,0 ;Alle register auf 0
ldi temp,255
out ddrb,temp ;PortB= ausgänge
ldi temp,0
out ddra,temp
ldi temp,0
out ddrc,temp
ldi temp,4
ldi startwertl,0
out OCR1BH,temp ;Pulslänge
out OCR1BL,startwertl
ldi spswertl,50
ldi spswerth,0
out OCR1AL,spswertl ;Pulsbreite
out OCR1AH,spswerth
ldi temp,0b01011000 ;Innterrupt CMPB CMPA Timer1 erlauben und
timer 2 overflow
out timsk,temp
ldi temp,0b00000010 ;Setze Prescaller 1 Timer1
out TCCR1B,temp ;Starte Timer1
ldi temp,0b00000101 ;Setze Prescaler 1024 Timer2
out tccr2,temp
sei
main:
rjmp main ;Leere schleife
T1_CMPA: ;Schalte PWM aus
andi ausgang,0b11111110
out portb,ausgang
reti
T1_CMPB: ;Schalte PWM ein
ori ausgang,0b00000001 ;setze PWM ausgang auf 1
out portb,ausgang
ldi temp,0
out TCNT1H,temp ;Setze Timer1 auf 0
out TCNT1L,temp
reti
T2_OVF:
in spswertl,pina
in spswerth,pinc
andi spswerth,0b00000111
out OCR1AH,spswerth
out OCR1AL,spswertl
in temp,pinc
andi temp,0b00000100
cpi temp,0b00000100
breq fehler
reti
fehler: ;Prüfe ob PinC2 überhaupt als eingang angenommen wird
ldi temp,0
out portb,temp
rjmp fehler