$regfile = "ATtiny841.DAT"

$crystal = 8000000                                          'Internal RC
'Low fuse 11100010, 0xE2, Div8 disabled, internal 8MHz
'High Fuse 11011100, 0xDC BOD set to 4,3V

$hwstack = 100
$swstack = 16
$framesize = 16

'WDT off:
Reset Watchdog
Mcusr.wdrf = 0                                              'WD Reset flag
Ccp = &HD8                                                  'Enable protected registers
Wdtcsr.wde = 0                                              'WD Enable off

'Timer0 in PWM-Mode 1, Phase Correct PWM:
Tccr0b.wgm02 = 0
Tccr0a.wgm01 = 0
Tccr0a.wgm00 = 1

'OC0A and B Clear OC0X on Compare Match when up-counting. Set OC0B on Compare Match
'when down-counting.
'This gives a PWM with the half frequency of the Timer0
Tccr0a.com0a1 = 0
Tccr0a.com0a0 = 1
Tccr0a.com0b1 = 0
Tccr0a.com0b0 = 1

'Clock prescaler 8. This gives a Timer frequency of 8,000,000/256/8 = 3906Hz.
'PWM Frequency 1953Hz Phase Correct
Tccr0b.cs02 = 0
Tccr0b.cs01 = 1
Tccr0b.cs00 = 0

'For OC0A Pin5 PB.2 TOCC7, OC01 Pin6 PA.7 TOCC6, this is the default mapping
'To Be sure:
Tocpmsa1.tocc7s1 = 0
Tocpmsa1.tocc7s0 = 0
Tocpmsa1.tocc6s1 = 0
Tocpmsa1.tocc6s0 = 0

'Enable Channels:
Tocpmcoe.tocc7oe = 1
Tocpmcoe.tocc6oe = 1
Ddrb.2 = 1
Ddra.7 = 1

'Pin 11 PortA.2 for LED
Ddra.2 = 1
Led Alias Porta.2

On Timer0 T0int
Enable Timer0
Enable Interrupts

Do
   Ocr0a = 50
   Ocr0b = 150

   Waitms 2000

   Ocr0a = 100
   Ocr0b = 200

   Waitms 2000
Loop

T0int:
   Led = 1
   Waitus 50
   Led = 0
Return