'-------------------------------------------------------------------- ' DMX - Dimmer 512 / by DW-Soft ' Dirk Wegener - 2004 - the_clown@web.de ' AVR-Bascom '-------------------------------------------------------------------- $regfile = "m8def.dat" $crystal = 16000000 $baud = 250000 Config Timer0 = Timer , Prescale = 64 Dim Dmx_count As Word Dim Dmx_count_temp As Byte Dim Dmx_byte As Byte Dim Dmx_pulse As Byte Dim Dmx_out As Byte Dim Dmx_clock As Byte Dim Netz_pulse As Byte Dim Dmx_adr As Word Dim Dmx_adr_temp As Byte Dim Dmx_adr_c As Word Dim Dmx_off As Byte Dim Temp1 As Byte Dim Dmx_buf(8) As Byte Print "Start" On Urxc Rec_isr Enable Urxc Enable Int0 On Int0 Int0_int Config Int0 = Rising Enable Timer0 On Timer0 Dimmer_output_sample Timer0 = 0 Start Timer0 Config Portc = Output Config Portb = Output Set Portc.5 Set Portc.4 Dmx_count = 0 Dmx_clock = 32 Dmx_adr = 2 Enable Interrupts ' ****************************************************************************** ' Hauptschleife ' ****************************************************************************** Do Waitms 10 Decr Dmx_off If Dmx_off = 0 Then Set Portc.4 For Temp1 = 1 To 8 Dmx_buf(temp1) = 0 Next Temp1 End If Loop ' ****************************************************************************** Rec_isr: 'DMX-Werte einlesen und ablegen $asm .def Uart_status = R16 .def Uart_byte = R17 .def Uart_temp1 = R18 IN Uart_status,USR IN Uart_byte,UDR SBRC Uart_status,FE RJMP Asm_reset RJMP Asm_Loop1 Asm_reset: LDI Uart_temp1,$00 STS {Dmx_count_temp} , Uart_temp1 STS {Dmx_byte} , Uart_byte RJMP Asm_exit Asm_loop1: STS {Dmx_byte} , Uart_byte Asm_exit: $end Asm If Dmx_count_temp <> 0 Then Incr Dmx_count If Dmx_adr_c = Dmx_count Then If Dmx_adr_temp < 9 Then Dmx_buf(dmx_adr_temp) = Dmx_byte Incr Dmx_adr_temp Incr Dmx_adr_c End If End If Else Dmx_count = 0 : Dmx_count_temp = 1 Dmx_adr_c = Dmx_adr : Dmx_adr_temp = 1 Decr Dmx_clock If Dmx_clock = 0 Then : Toggle Portc.4 : Dmx_clock = 32 : End If End If Dmx_off = 64 Return ' ****************************************************************************** Dimmer_output_sample: ' Dimmerwerte ausgeben Tcnt0 = 247 If Netz_pulse = 0 Then : Goto Timer_loop1 : End If Decr Netz_pulse Timer_loop1: Dmx_out = Dmx_buf(1) If Netz_pulse <= Dmx_out Then : Reset Portb.0 : Else : Set Portb.0 : End If Dmx_out = Dmx_buf(2) If Netz_pulse <= Dmx_out Then : Reset Portb.1 : Else : Set Portb.1 : End If Dmx_out = Dmx_buf(3) If Netz_pulse <= Dmx_out Then : Reset Portb.2 : Else : Set Portb.2 : End If Dmx_out = Dmx_buf(4) If Netz_pulse <= Dmx_out Then : Reset Portb.3 : Else : Set Portb.3 : End If Dmx_out = Dmx_buf(5) If Netz_pulse <= Dmx_out Then : Reset Portb.4 : Else : Set Portb.4 : End If Dmx_out = Dmx_buf(6) If Netz_pulse <= Dmx_out Then : Reset Portb.5 : Else : Set Portb.5 : End If Dmx_out = Dmx_buf(7) If Netz_pulse <= Dmx_out Then : Reset Portc.0 : Else : Set Portc.0 : End If Dmx_out = Dmx_buf(8) If Netz_pulse <= Dmx_out Then : Reset Portc.1 : Else : Set Portc.1 : End If Return ' ****************************************************************************** Int0_int: ' Phasensyncronisierung Netz_pulse = 255 Return ' ******************************************************************************