Here is what the piece of code below does:
- it initializes the hardware
- it establishes a USB connection
- in an endless loop ... the code decodes the drums and sends the data via USB to the computer
The drums are encoded as follows:
#define digZero 0b00001011 // 0x0b
#define digOne 0b00000011 // 0x03
#define digTwo 0b00000101 // 0x05
#define digThree 0b00001001 // 0x09
#define digFour 0b00001010 // 0x0a
#define digFive 0b00001100 // 0x0c
#define digSix 0b00001101 // 0x0d
#define digSeven 0b00001110 // 0x0e
#define digEight 0b00000110 // 0x06
#define digNine 0b00000111 // 0x07
So below is the code. See the screen shots below for the test output. Tomorrow, we will connect the radio head to X-Plane.

/* *****************************************
*
* The L-1011 Project
*
* Radio Head Firmware
*
* Hardware: Teensy++ AT90USB1286
*
* Author: Curd Zechmeister
*
* Function : Read the radio head input and
* send it via USB to the
* computer.
*
* Revision History
*
* 2010-03-27 Initial Creation
* 2010
*
*******************************************/
#include
#include
#include
#include "usb_rawhid.h"
#include "print.h"
#include "VHFCOM.h"
/* ****************************************
* * Constant Definitons *
* ****************************************/
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define BUSY_LED_ON (PORTD = _BV(PD6))
#define BUSY_LED_OFF (PORTD = !_BV(PD6));
/* ****************************************
* * Prototyping *
* ****************************************/
int teensyInit();
int USBlink();
uint8_t decodeNybbleFront(unsigned int region, unsigned char nybble);
uint8_t decodeNybbleBack(unsigned int region, unsigned char nybble);
/* ****************************************
* * Global Variable Definitons *
* ****************************************/
uint8_t usbBuffer[64];
/* ****************************************
* ****************************************
* * Main Program Logic *
* ****************************************
* ****************************************/
int main() {
// Variables
unsigned char val1; // Read input value 1
unsigned char val2; // Read input value 2
unsigned char saveVal1; // Save input value 1
unsigned char saveVal2; // Save input value 2
uint8_t i; // Loop counter
// Vaiable init
val1 = 0x00;
val2 = 0x00;
saveVal1 = 0xff;
saveVal2 = 0xff;
i = 0;
// Initialize the Device
teensyInit();
// Initizlize USB Connection
USBlink();
// This is a VHF COM Radio
usbBuffer[0] = COMRADIO; // Device is a VHF communications radio
usbBuffer[1] = COM1; // Device is COM Radio 1
// Input Loop
while( 1 ) {
// Read the 2 input bytes
val1 = PINA;
val2 = PINB;
// Determine if processing necessary
if ( val1 != saveVal1 || val2 != saveVal2 ) {
// Clear the buffer
for (i=2; i<64; saveval1 =" val1;" saveval2 =" val2;" porta =" 0x00;" ddra =" 0x00;" portb =" 0x00;" ddrb =" 0x00;" portc =" 0x00;" ddrc =" 0x00;" ddrd =" 0xFF;" region ="=" nybanalysis =" (nybble" nybanalysis =" (nybble">>4);
nybAnalysis &= 0b00001111;
}
switch( nybAnalysis ) {
case digOne:
return(0x01);
break;
case digTwo:
return(0x02);
break;
case digThree:
return(0x03);
break;
case digFour:
return(0x04);
break;
case digFive:
return(0x05);
break;
case digSix:
return(0x06);
break;
case digSeven:
return(0x07);
break;
case digEight:
return(0x08);
break;
case digNine:
return(0x09);
break;
default:
return(0x00);
}
}
/*
* Nybble Decoder for left hand side of decimal point
*/
uint8_t decodeNybbleFront(unsigned int region, unsigned char nybble) {
unsigned char nybAnalysis;
if ( region == 0 ) {
nybAnalysis = (nybble & 0b00001111);
} else {
nybAnalysis = (nybble>>4);
nybAnalysis &= 0b00001111;
}
switch( nybAnalysis ) {
case digOne:
return(0x01);
break;
case digTwo:
return(0x02);
break;
case digThree:
return(0x03);
break;
case digFour:
return(0x04);
break;
case digFive:
return(0x05);
break;
case digSix:
return(0x06);
break;
case digSeven:
return(0x07);
break;
case digEight:
return(0x08);
break;
case digNine:
return(0x09);
break;
default:
return(0x00);
}
}
// END
No comments:
Post a Comment