'( Rechteck Frequencygenerator mit Atmega48 Von 0.15 Hz Bis 10 Mhz(20 Mhz Quarz) ') $regfile = "m48def.dat" $crystal = 20000000 '$baud = 9600 $hwstack = 40 $swstack = 32 $framesize = 60 '-------- Vars -------- Dim Timer2count As Word Dim Flags As Byte Dim Tastcount As Byte Dim Frequency As Single Dim Clock As Word Dim Overflow As Long Dim Fade As Byte Dim Freqstr As String * 8 '-------- Display initialisieren -------- Config Lcdpin = Pin , Rs = Portd.7 , E = Portd.4 , Db4 = Portd.3 , _ Db5 = Portd.2 , Db6 = Portd.1 , Db7 = Portd.0 Config Lcd = 16 * 2 Cursor Off '-------- Ports -------- Config Portb.1 = Output Config Pinc.3 = Input Config Pinc.4 = Input Config Pinc.5 = Input Portc.3 = 1 Portc.4 = 1 Portc.5 = 1 '-------- Timer0 als PWM einrichten -------- Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down , _ Compare B Pwm = Clear Down Enable Timer0 Start Timer0 '-------- Timer1 als Fast PWM einrichten -------- Tccr1a = &B01000011 Tccr1b = &B00011001 Ocr1bh = &B01111111 Ocr1bl = &B11111111 '-------- Timer2 als Timer einrichten -------- Config Timer2 = Timer , Prescale = 1024 Enable Timer2 On Timer2 Check_eeprom '-------- Eeprom aktivieren -------- $eeprom $eepromhex Eeclock: Data &HFFFF% Eeflags: Data 0 Eecontr: Data 50 $data '-------- Letzte Werte aus dem Eeprom holen -------- Readeeprom Clock , Eeclock Readeeprom Flags.0 , Eeflags Readeeprom Ocr0a , Eecontr '-------- Main -------- Locate 1 , 1 : Lcd "Display OK " Gosub Fade_up Gosub Disp_contr Waitms 2000 Enable Interrupts Config Debounce = 30 Gosub Result Timer2count = 767 Do Debounce Pinc.3 , 0 , Change_flags , Sub Debounce Pinc.4 , 0 , Clock_down , Sub Debounce Pinc.5 , 0 , Clock_up , Sub Tastcount = 0 Loop End '-------- Subs -------- Clock_down: Gosub Fade_up While Pinc.4 = 0 Gosub Count Overflow = Clock - Overflow If Overflow < 1 Then Clock = 1 Else Clock = Overflow End If Decr Clock Gosub Result Wend Return Clock_up: Gosub Fade_up While Pinc.5 = 0 Gosub Count Overflow = Clock + Overflow If 65534 < Overflow Then Clock = 65534 Else Clock = Overflow End If Incr Clock Gosub Result Wend Return Count: If Tastcount > 20 Then Overflow = Clock / 128 If Tastcount > 40 Then Overflow = Overflow * 2 If Tastcount > 60 Then Overflow = Overflow * 4 Return Change_flags: Gosub Fade_up Toggle Flags.0 Gosub Result Stop Timer2 While Pinc.3 = 0 If Pinc.5 = 0 Then If Ocr0a < 4 Then Ocr0a = 4 Ocr0a = Ocr0a - 4 Gosub Disp_contr End If If Pinc.4 = 0 Then Ocr0a = Ocr0a + 4 Gosub Disp_contr End If Wend Gosub Result Return Disp_contr: Locate 2 , 1 Lcd "Contrast: " ; Ocr0a ; " " Waitms 250 Return Result: Tccr1b.cs12 = Flags.0 Ocr1ah = High(clock) Ocr1al = Clock Frequency = Clock + 1 Frequency = 10000000 / Frequency Cls Locate 2 , 1 If Tccr1b.cs12 = 1 Then Frequency = Frequency / 1024 Lcd "Low" Else Lcd "High" End If Locate 1 , 14 If Frequency >= 1000000 Then Lcd "M" Frequency = Frequency / 1000000 Elseif Frequency >= 1000 Then Lcd "k" Frequency = Frequency / 1000 End If Locate 1 , 15 : Lcd "Hz" Locate 1 , 1 If Frequency < 10 Then Locate 1 , 3 Elseif Frequency < 100 Then Locate 1 , 2 End If Freqstr = Fusing(frequency , "#.&&&&&&") Lcd Freqstr Start Timer2 Incr Tastcount Overflow = 0 Timer2count = 0 Waitms 250 Return Check_eeprom: If Timer2count = 766 Then Writeeeprom Clock , Eeclock Writeeeprom Flags.0 , Eeflags Writeeeprom Ocr0a , Eecontr Locate 2 , 13 : Lcd "save" End If Gosub Backlight_fade Incr Timer2count Return Backlight_fade: If Timer2count = 1532 Then For Fade = 35 To 0 Step -1 Ocr0b = Lookup(fade , Fade_data) Waitms 50 Next Stop Timer2 End If Return Fade_up: If Ocr0b < 255 Then For Fade = 0 To 35 Ocr0b = Lookup(fade , Fade_data) Waitms 5 Next End If Return Fade_data: Data 0 , 1 , 1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 6 , 7 , 8 , _ 9 , 11 , 13 , 15 , 17 , 20 , 23 , 32 , 37 , 43 , 50 , 59 , _ 69 , 80 , 93 , 109 , 127 , 148 , 173 , 201 , 227 , 255