Armins AVR-Buch - Programm_Leuchtturmfeuer

⇑Programm_Leuchtturmfeuer


(armin77, 02.01.2013, 15:52:05)

Hier ein Beispielprogramm für ein Leuchtturmfeuer.
Eine LED mit Vorwiderstand wird an Portb.1 angeschlossen.

$regfile = "m8def.dat"
$crystal = 1000000
$hwstack = 40
$swstack = 16
$framesize = 32

Config Portb.1 = Output
Dim A as Byte

Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1

Do

For A = 1 To 150 Step 2
Pwm1a = A
Waitms 30
Next

Pwm1a = 255
Waitms 100

For A = 150 To 1 Step -2
Pwm1a = A
Waitms 30
Next

Loop
End


Timer1 wird für 8 bit PWM deklariert.
Die Led wird langsam heller, blitzt kurz auf und wird langsam wieder dunkel.

Viel Spaß beim ausprobieren.