Programm 5 (Atmega32 Hardware PWM)

$regfile = "m32def.dat"
$framesize = 20
$swstack = 20
$hwstack = 20

$crystal = 16000000                                         'Quarzfrequenz

Dim I As Integer
Dim I1 As Integer
Dim Taste1 As Bit
Dim Taste2 As Bit

Config Pind.4 = Output                                      'PWM  oc1b
Config Pind.5 = Output                                      'PWM  oc1a
Config Pind.2 = Input                                       'Taste1
Config Pind.3 = Input                                       'Taste2

Declare Sub Tastenabfrage()

Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 1
Pwm1a = 0
Pwm1b = 0

Do

Call Tastenabfrage

If Taste2 = 0 Then

For I1 = 1 To 10
For I = 0 To 256
Pwm1a = I
Pwm1b = I
Waitms 2
Next I

For I = 256 To 0 Step -1
Pwm1a = I
Pwm1b = I
Waitms 2
Next I
Next I1

End If

Loop
End

Sub Tastenabfrage()                                         'Diese Unterfunktion fragt die 2 Tasten An D3&D4 ab

Taste1 = 1
Taste2 = 1

Taste1 = Pind.2
Taste2 = Pind.3

End Sub

 

Die Robotik & Arduino Seite