dmx.c


1
/////////////////////////////////////////////////////////////////////////////
2
//  Modul  : dmx.c
3
/////////////////////////////////////////////////////////////////////////////
4
//  Version : 1.0
5
//  Date  : 12.01.2014
6
//  Comment  : First Version 
7
///////////////////////////////////////////////////////////////////////////// 
8
9
#include <inttypes.h>
10
#include <avr/io.h>
11
#include <avr/interrupt.h>
12
#include <avr/signal.h>
13
#include "dmx.h"
14
#include "Basis_DMX.h"
15
#include <util/delay.h> //muß nach F_CPU definiert werden !!!
16
17
18
#define       DMX_Channels    512    //Anzahl der zu empfangenden DMX Kanäle
19
20
//Variablen
21
uint8_t  DMX_State_RX;        //DMX Empfangsstaus: 0=Leerlauf, 1=Break Empfangen, 2=Startbyte Empfangen, 3=Startadresse erreicht
22
uint16_t DMX_RX_Bytecounter;      //Variable für DMX Byte Counter (gezählt von Paket 1) für empfangen
23
uint16_t k=0;
24
//============================================================================================
25
//DMX Inizialisierung
26
//Es wird UART 1 verwendet (Txd1)
27
//Clock 16 MHZ
28
//DMX : 250KHZ,1 Start,8Byte,2Stopp
29
//============================================================================================
30
void init_DMX(void)
31
{
32
  UBRR1H  = 0;
33
  UBRR1L  = 3;
34
  UCSR1C  |= (1<<UCSZ11) | (1<<UCSZ10) | (1<<USBS1);          //250kBaud, 2 Stopbits
35
  UCSR1B  = (1<<TXEN1);     //Enable Data Register Interrupt,Enable Transmitter 1  
36
  DDRD  |= (1<<PD3); //TxD = Output
37
  
38
}
39
//============================================================================================
40
void transmit_DMX(void)
41
{
42
 uint16_t i;
43
 UBRR1H  = 0;
44
 UBRR1L  = 12;  //set 115.2K Baudrate
45
 while (!(UCSR1A & (1<<UDRE1)))  //any data in UDR1?
46
 ;
47
 UDR1 = 0; //RESET Frame 
48
while (!(UCSR1A & (1<<UDRE1)))  
49
;
50
   UBRR1L  = 3;              //Baud Rate Register = 250KHZ  
51
   UDR1 = 0; //Start
52
 
53
 for (i=0;i<512;i++)
54
{
55
 while (!(UCSR1A & (1<<UDRE1))) 
56
 ;     
57
  UDR1 = dmx_buffer[i];
58
 }
59
}
60
//============================================================================================