;************************************************************************************************** ; ; Einlesen eines Analog-Wertes und Umrechnen in eine 8-Bit Zahl ; -------> Ausgeben als 8-Bit PWM ; -------> Ausgeben als 10-Bit PWM ; ;************************************************************************************************** .device AT90S8535 .include "8535def.inc" ;************************************************************************************************** ; Variablen Deklaration ;************************************************************************************************** .def reh = r5 ;MSB Ergebnis .def hexl = r6 .def hexh = r7 .def int_serv = r16 .def temp = r19 ;Schmierregister 1 .def temp2 = r20 ;Schmierregister 2 .def ADCLow = r21 ;LSB ADC .def ADCHigh = r22 ;MSB ADC .def ADCLow2 = r23 ;LSB ADC2 .def ADCHigh2 = r24 ;MSB ADC2 .org 0x00 ;************************************************************************************************** ; Stackpointer initialiseren ;************************************************************************************************** ldi temp, LOW(RAMEND) out SPL, temp ldi temp, HIGH(RAMEND) out SPH, temp ;************************************************************************************************** ; Port C + D auf Ausgang schalten ;************************************************************************************************** ldi temp, 0xFF out DDRC, temp out DDRD, temp ;************************************************************************************************** ; PWM initialisieren ;************************************************************************************************** ldi temp, 0x83 ;PWM als 10-Bit konfigurieren out TCCR1A, temp ldi temp, 0 out OCR1AH, temp ldi temp, 1 out OCR1AL, temp sei main: ;10 Bit-Wert einlesen oder vogeben in temp und temp2 und dann läuft der PWM out OCR1AH, temp ;erst das ADCH-Byte schreiben. dann out OCR1AL, temp2 ;das Low Byte. Sonst funktioniert rjmp main