
Y el codigo es y no he movido nada....como estas.

'******************************************************
'Projekt: Atmel-Programmierung für Einsteiger
'
'Prozessor: ATMega 8-16
'Bascom-Version: 1.11.8.1
'
'Programm 10: PWM-Erzeugung
'
'Hardware:
'UDN2981 mit MosFet IRF540
'Schalter an Port C.0
'10k-Poti an Port C.1
'PWM-Ausgang an Port B.3 (OC2)
'
'26.02.2006 T. Gietenbruch
'
'******************************************************
'======================================================
'System-Einstellungen
'======================================================
'Definition für Mega 8
$regfile "m8def.dat"
'Angabe der Taktfrequenz (8Mhz)
$crystal = 8000000
'Konfiguration der Analogeingänge
Config Adc = Single , Prescaler = Auto , Reference = Avcc
'Konfiguration Timer 2 für Hardware-PWM an OC2 (B.3)
Config Timer2 = Pwm , Prescale = 128 , Compare = Clear
'Konfiguration der Ports
Config Portb = Output
Config Portc = Input
Config Portd = Output
'======================================================
'Deklarationen
'======================================================
Dim Analogwert As Word
Dim Pwmwert As Byte
'======================================================
'Initialisierungen
'======================================================
'Anschaltung der Analogwert-Verarbeitung
Start Adc
Portb = &B00000000
Portd = &B00000000
'Start des PWM-Timers
Enable Timer2
Timer2 = 0
Start Timer2
'======================================================
'Hauptprogramm-Schleife
'======================================================
Do
'Analogwert vom Poti einlesen, umrechnen und formieren
Analogwert = Getadc(1)
Analogwert = Analogwert / 4
If Analogwert > 255 Then Analogwert = 255
'Erzeugung des PWM-Signals
If Pinc.0 = 0 Then
Ocr2 = Analogwert
Else
Ocr2 = 0
End If
Loop