Rev 542 |
Rev 723 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
// ********************************************************
// ** Spektrum DX7(se) Expander for 10 Channels at large **
// ********************************************************
// ** Target: Atmel ATtiny2313 with delivered standard **
// ** Fuses (internal RC-Oscillator @ 1 MHz) **
// ********************************************************
// ** It sends data from 4 additionally switches over **
// ** the tripole "FLAP" channel which the FlightControl **
// ** can decode "on the fly" :) **
// ********************************************************
// ** (c) 2009-0xFFFF Stefan Pendsa **
// ** License: don't know - use it and have fun **
// ********************************************************
#include <avr/io.h>
#define TX_High PORTA |= 1 << PORTA0 // Set TX-Pin High
#define TX_Low PORTA &= ~(1 << PORTA0) // Set TX-Pin Low
#define SYNC_High PORTA |= 1 << PORTA1 // Set Sync-Pin High
#define SYNC_Low PORTA &= ~(1 << PORTA1) // Set Sync-Pin Low
void Send(char sync, char data)
{
if (sync == 0) SYNC_High; else SYNC_Low; // Send Sync
if (data == 0) TX_High; else TX_Low; // Send Data
while ( PIND & (1<<PD5) ); // Wait for DX7-Sync goes low
while ( !(PIND & (1 << PD5)) ); // Wait for DX7-Sync goes high
}
int main(void)
{
char i,Parity; // Bit-Counter and Parity Bit
DDRA = 0b011; // PORT A INPUT: /RESET; OUTPUT: Sync+Data
DDRD = 0b0000000; // PORT D INPUT: Switches + DX7-Sync
PORTA = 0b111; // Pull-Up for /RESET; High for Sync+Data
PORTD = 0b0011111; // Pull-Up for Switches
while(1) // Main-Loop (Sending data all the time)
{
Parity = 0; // Reset Parity Bit
Send(1,0); // Send SYNC Pulse
for (i=0;i<5;i++) // Encode the first five Port Pins
{
if (PIND & (1<<i)) // Check Pin #i
{
Send(0,0); // When High, Send Low (Switched to "0")
Parity = ~Parity; // and invert Parity Bit
}
else
{
Send(0,1); // When Low, Send High (Switched to "1")
}
}
Send(0,Parity); // Send Parity Bit
}
}