initial version
This commit is contained in:
commit
4d6f3bfec9
|
@ -0,0 +1,71 @@
|
|||
PRG = dmx3chan
|
||||
OBJ = dmx3chan.o
|
||||
MCU_TARGET = at90s2313
|
||||
OPTIMIZE = -Os
|
||||
|
||||
DEFS =
|
||||
LIBS =
|
||||
|
||||
# You should not have to change anything below here.
|
||||
|
||||
CC = avr-gcc
|
||||
|
||||
# Override is only needed by avr-lib build system.
|
||||
|
||||
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
|
||||
override LDFLAGS = -Wl,-Map,$(PRG).map
|
||||
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
SIZE = avr-size
|
||||
|
||||
all: $(PRG).elf lst text eeprom
|
||||
$(SIZE) -x -A $(PRG).elf
|
||||
|
||||
$(PRG).elf: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -rf *.o *.lst *.map $(PRG).elf *.hex *.bin *.srec
|
||||
|
||||
lst: $(PRG).lst
|
||||
|
||||
%.lst: %.elf
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
# Rules for building the .text rom images
|
||||
|
||||
text: hex bin srec
|
||||
|
||||
hex: $(PRG).hex
|
||||
bin: $(PRG).bin
|
||||
srec: $(PRG).srec
|
||||
|
||||
%.hex: %.elf
|
||||
$(OBJCOPY) -j .text -j .data -O ihex $< $@
|
||||
|
||||
%.srec: %.elf
|
||||
$(OBJCOPY) -j .text -j .data -O srec $< $@
|
||||
|
||||
%.bin: %.elf
|
||||
$(OBJCOPY) -j .text -j .data -O binary $< $@
|
||||
|
||||
# Rules for building the .eeprom rom images
|
||||
|
||||
eeprom: ehex ebin esrec
|
||||
|
||||
ehex: $(PRG)_eeprom.hex
|
||||
ebin: $(PRG)_eeprom.bin
|
||||
esrec: $(PRG)_eeprom.srec
|
||||
|
||||
%_eeprom.hex: %.elf
|
||||
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
|
||||
|
||||
%_eeprom.srec: %.elf
|
||||
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
|
||||
|
||||
%_eeprom.bin: %.elf
|
||||
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
|
||||
|
||||
install: text
|
||||
avrdude -p m16 -c butterfly -b 19200 -U flash:w:$(PRG).srec
|
|
@ -0,0 +1,134 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 05/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#define TIMER1_STEP 40
|
||||
#define TIMER1_RELOAD (0xFFFF - (256 * TIMER1_STEP))
|
||||
|
||||
// rx variables
|
||||
static uint16_t rx_chan;
|
||||
static uint16_t my_base;
|
||||
|
||||
// channel values
|
||||
static uint8_t chan[8] = { 0xFF, 0xC0, 0xB0, 0x80, 0x40, 0x20, 0x10, 0x00 };
|
||||
|
||||
// next OCR1 value
|
||||
static uint8_t cnt;
|
||||
static uint16_t pwm_load;
|
||||
|
||||
/*
|
||||
* Timer 1 Overflow (every 10ms)
|
||||
* - reload 10ms
|
||||
* - schedule compare match in 40us
|
||||
*/
|
||||
ISR(SIG_OVERFLOW1)
|
||||
{
|
||||
TCNT1 = TIMER1_RELOAD;
|
||||
OCR1 = (TIMER1_RELOAD + TIMER1_STEP);
|
||||
pwm_load = (TIMER1_RELOAD + (TIMER1_STEP * 2));
|
||||
cnt = 0x00;
|
||||
}
|
||||
|
||||
/*
|
||||
* Timer 1 Compare Match (every 40us)
|
||||
* - schedule next compare match in 40us
|
||||
*/
|
||||
ISR(SIG_OUTPUT_COMPARE1A)
|
||||
{
|
||||
OCR1 = pwm_load;
|
||||
pwm_load += TIMER1_STEP;
|
||||
|
||||
uint8_t *tmp = chan;
|
||||
|
||||
cnt--;
|
||||
|
||||
if (cnt == 0xFF)
|
||||
PORTB = 0x00;
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB0);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB1);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB2);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB3);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB4);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB5);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB6);
|
||||
|
||||
if (*tmp++ >= cnt)
|
||||
PORTB |= (1<<PORTB7);
|
||||
}
|
||||
|
||||
/*
|
||||
* DMX Receive (every 44us)
|
||||
* - count received bytes
|
||||
*/
|
||||
ISR(SIG_UART_RECV)
|
||||
{
|
||||
// FrameError & Data 0x00 -> Reset
|
||||
if (USR & (1<<FE)) {
|
||||
if (UDR == 0)
|
||||
rx_chan = 0;
|
||||
|
||||
// Our 8 channels?
|
||||
} else if ((rx_chan & 0x1F8) == my_base) {
|
||||
chan[(rx_chan++ & 0x07)] = UDR;
|
||||
|
||||
} else {
|
||||
uint8_t tmp = UDR;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* PortB as outputs */
|
||||
DDRB = 0xFF;
|
||||
PORTB = 0x00;
|
||||
|
||||
/* Uart-Init: 250kBaud, 8n2, receive only */
|
||||
UBRR = 0x01;
|
||||
UCR = (1<<RXCIE) | (1<<RXEN) | (1<<CHR9);
|
||||
|
||||
/* Timer Init: F_OSC/8, overflow & compare Int */
|
||||
TCCR1A = 0x00;
|
||||
TCCR1B = (1<<CS11);
|
||||
TIMSK = (1<<TOIE1) | (1<<OCIE1A);
|
||||
TCNT1 = TIMER1_RELOAD;
|
||||
|
||||
/* Enable Interrupts */
|
||||
sei();
|
||||
|
||||
while (1);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue