hi przyjaciel, oczywiście przykro, wulgaryzmy google tłumacz, dobry ciekawy projekt, chciałbym, aby przynieść wam po najpierw sugerujemy dodać bibliotekę do TX-out napędu DIP10 dźwięku, http: // www ..... .hoelscher-hi.de / Hendrik / światło / Zasoby /
http://www.hoelscher-hi.de/hendrik/light/ressources/AN013.pdf txd.zip i to nawet jest funkcjonalnie podobny do oryginalnego ..aporto biblioteka w C, który przynosi Strobe i przyciemnić mistrza., aby można było się z partii, jeśli służyć., także bibliotekę wskaźników., bardzo przydatne w przypadku DMX. Mam nadzieję, że swoje komentarze., a mam nadzieję, że był pomocny i nadal Twój zespół. i reformy kopalni
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>
#define F_CPU 12000000
#define LED_R_PIN_OUT DDRD |= (1<<PD5);
#define LED_G_PIN_OUT DDRD |= (1<<PD4);
#define LED_B_PIN_OUT DDRD |= (1<<PD3);
#define LED_R_ON PORTD |= (1<<PD4);
#define LED_R_OFF PORTD &= ~(1<<PD4);
#define LED_B_ON PORTD |= (1<<PD5);
#define LED_B_OFF PORTD &= ~(1<<PD5);
#define LED_G_ON PORTD |= (1<<PD3);
#define LED_G_OFF PORTD &= ~(1<<PD3);
#define DMX_BAUD 250000
#define DMX_LOST_TIMEOUT 8000
volatile unsigned int dmx_lost = DMX_LOST_TIMEOUT;
volatile unsigned int dmx_adresse = 0;
volatile unsigned char dmx_buffer[6];
volatile unsigned char led_kanal[3];
//############################################################################
//DMX Senderoutine
ISR (USART_RX_vect)
//############################################################################
{
static unsigned int dmx_channel_rx_count = 0;
static unsigned char dmx_valid = 0;
unsigned char tmp = 0;
tmp = UDR;
if(UCSRA&(1<<FE))
{
if(dmx_channel_rx_count > 1)
{
dmx_lost = 0;
}
dmx_channel_rx_count = 0;
dmx_buffer[0] = tmp;
if(dmx_buffer[0] == 0)
{
dmx_valid = 1;
dmx_channel_rx_count++;
}
else
{
dmx_valid = 0;
}
return;
}
if(dmx_valid)
{
if(dmx_channel_rx_count == dmx_adresse) dmx_buffer[1] = tmp;
if(dmx_channel_rx_count == dmx_adresse+1) dmx_buffer[2] = tmp;
if(dmx_channel_rx_count == dmx_adresse+2) dmx_buffer[3] = tmp;
if(dmx_channel_rx_count == dmx_adresse+3) dmx_buffer[4] = tmp;
if(dmx_channel_rx_count == dmx_adresse+4) dmx_buffer[5] = tmp;
if(dmx_channel_rx_count < 514)
{
dmx_channel_rx_count++;
}
return;
}
}
//############################################################################
//Hier wird die Zeit gezählt (Tick 1ms)
ISR (TIMER0_COMPA_vect)
//############################################################################
{
static unsigned char pwm_counter = 0;
pwm_counter++;
if(pwm_counter == 255)
{
pwm_counter = 0;
}
if(pwm_counter >= led_kanal[0])
{
LED_R_OFF;
}
else
{
LED_R_ON;
}
if(pwm_counter >= led_kanal[1])
{
LED_G_OFF;
}
else
{
LED_G_ON;
}
if(pwm_counter >= led_kanal[2])
{
LED_B_OFF;
}
else
{
LED_B_ON;
}
if(dmx_lost<DMX_LOST_TIMEOUT)
{
dmx_lost++;
}
}
//############################################################################
//Hauptprogramm
int main (void)
//############################################################################
{
unsigned int dmx_adresse_tmp;
unsigned long strobe_counter = 0;
unsigned char tmp1,tmp2,tmp3;
//Init usart DMX-BUS
UBRRH = (unsigned char)(F_CPU / (DMX_BAUD * 16L) - 1)>>8;
UBRRL = (unsigned char)(F_CPU / (DMX_BAUD * 16L) - 1);
UCSRB|=(1 << RXEN | 1<< RXCIE);
UCSRC|=(1<<USBS); //USBS0 2 Stop bits
//Timer0 Timecounter für DMX Ausfall und PWM
TCCR0A |= (1<<WGM01);
TCCR0B |= (1<<CS00);
TIMSK |= (1<<OCIE0A);
OCR0A = F_CPU/1024/100 - 1; //Tick 1ms
PORTB |= 0xFF;
PORTD |= (1<<PD6);
DDRD |=(1<<PD2);
PORTD &=~(1<<PD2);
LED_R_PIN_OUT;
LED_G_PIN_OUT;
LED_B_PIN_OUT;
LED_R_ON;
for(unsigned long tmp = 0;tmp<500000;tmp++)asm("nop");
LED_R_OFF;
LED_G_ON;
for(unsigned long tmp = 0;tmp<500000;tmp++)asm("nop");
LED_G_OFF;
LED_B_ON;
for(unsigned long tmp = 0;tmp<500000;tmp++)asm("nop");
LED_B_OFF;
sei();//Globale Interrupts Enable
//Endlosschleife
while(1)
{
dmx_adresse_tmp = 0;
if(!(PIND&(1<<PD6))) dmx_adresse_tmp |= 0x01;
if(!(PINB&(1<<PB0))) dmx_adresse_tmp |= 0x02;
if(!(PINB&(1<<PB1))) dmx_adresse_tmp |= 0x04;
if(!(PINB&(1<<PB2))) dmx_adresse_tmp |= 0x08;
if(!(PINB&(1<<PB3))) dmx_adresse_tmp |= 0x10;
if(!(PINB&(1<<PB4))) dmx_adresse_tmp |= 0x20;
if(!(PINB&(1<<PB5))) dmx_adresse_tmp |= 0x40;
if(!(PINB&(1<<PB6))) dmx_adresse_tmp |= 0x80;
if(!(PINB&(1<<PB7))) dmx_adresse_tmp |= 0x0100;
if(dmx_adresse != dmx_adresse_tmp) dmx_adresse = dmx_adresse_tmp;
if(dmx_lost==DMX_LOST_TIMEOUT)
{
dmx_buffer[1] = 0;
dmx_buffer[2] = 0;
dmx_buffer[3] = 0;
dmx_buffer[4] = 0;
}
tmp1 = dmx_buffer[1]*dmx_buffer[4]/255;
tmp2 = dmx_buffer[2]*dmx_buffer[4]/255;
tmp3 = dmx_buffer[3]*dmx_buffer[4]/255;
if(dmx_buffer[5]<10)
{
led_kanal[0] = tmp1;
led_kanal[1] = tmp2;
led_kanal[2] = tmp3;
}
else
{
strobe_counter++;
if(strobe_counter > (256 - dmx_buffer[5]))
{
led_kanal[0] = tmp1;
led_kanal[1] = tmp2;
led_kanal[2] = tmp3;
}
else
{
led_kanal[0] = 0;
led_kanal[1] = 0;
led_kanal[2] = 0;
}
if(strobe_counter > (2 * (256 - dmx_buffer[5])))
{
strobe_counter = 0;
led_kanal[0] = 0;
led_kanal[1] = 0;
led_kanal[2] = 0;
}
}
}
}
/**** A P P L I C A T I O N N O T E ************************************
*
* Title : Error Indication Library
* Version : v1.0
* Last updated : 09.09.07
* Target : Transceiver Rev.3.01 [ATmega8515]
* Clock : 8MHz, 16MHz
*
* written by
***************************************************************************
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version2 of
the License, or (at your option) any later version.
;***************************************************************************/
#include "lib_indicator.h"
#define NO_DMX_PAT (0b10000010)
#define NOT_HOT_PAT (0b10101010)
#define COLD_PAT (0b11111111)
uint8_t Blink;
// ******************** initialize indicator *****************************
void init_ind(void)
{
DDRD |= (1<<PD7); //LED1
PORTD |= (1<<PD7);
DDRE |= (1<<PE0); //LED2
PORTE |= (1<<PE0);
Blink= 0xFF;
IndFlags= 0;
}
// ******************** LED indicator *****************************
void indicate(void)
{
if (IndFlags &(1<<DATA_REFRESHED))
{
IndFlags &= ~(1<<DATA_REFRESHED);
PORTE ^= (1<<PE0); //change green LED state
}
else PORTE &= ~(1<<PE0); //enable LED if nothing's changed
if (Blink &(1<<0))
{
PORTD &= ~(1<<PD7); //enable red LED if 1st bit is set
PORTA |= (1<<PA7); //same pattern at remote control
}
else
{
PORTD |= (1<<PD7);
PORTA &= ~(1<<PA7);
}
Blink= (Blink>>1); //shift pattern
if (Blink == 1)
{
IndFlags &= ~(1<<DMX_ERR);
if (!(IndFlags &(1<<VALID_DMX)))
{
Blink= NO_DMX_PAT;
IndFlags |=(1<<DMX_ERR);
}
else if (IndFlags &(1<<COLD)) Blink= COLD_PAT;
else if (!(IndFlags &(1<<HOT))) Blink= NOT_HOT_PAT;
else
{
Blink= 0b10000000;
}
IndFlags &= ~(1<<VALID_DMX); //clear IndFlags
}
}
[code] #include <avr/io.h>
#include <stdint.h>
volatile uint8_t IndFlags;
enum {VALID_DMX, DMX_ERR, DATA_REFRESHED, COLD, HOT};
extern void indicate(void);
extern void init_ind(void);