Created
February 16, 2013 13:36
-
-
Save lotka/4966960 to your computer and use it in GitHub Desktop.
mbed rtty test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define RADIOPIN p23 | |
void rtty_txstring (char * string); | |
void rtty_txbyte (char c); | |
void rtty_txbit (int bit); | |
DigitalOut outputPin(RADIOPIN); | |
char datastring[80]; | |
int main() | |
{ | |
sprintf(datastring,"Hello World"); // Puts the text in the datastring | |
rtty_txstring (datastring); | |
} | |
void rtty_txstring (char * string) | |
{ | |
/* Simple function to sent a char at a time to | |
** rtty_txbyte function. | |
** NB Each char is one byte (8 Bits) | |
*/ | |
char c; | |
c = *string++; | |
while ( c != '\0') | |
{ | |
rtty_txbyte (c); | |
c = *string++; | |
} | |
} | |
void rtty_txbyte (char c) | |
{ | |
/* Simple function to sent each bit of a char to | |
** rtty_txbit function. | |
** NB The bits are sent Least Significant Bit first | |
** | |
** All chars should be preceded with a 0 and | |
** proceded with a 1. 0 = Start bit; 1 = Stop bit | |
** | |
*/ | |
int i; | |
rtty_txbit (0); // Start bit | |
// Send bits for for char LSB first | |
for (i=0;i<7;i++) // Change this here 7 or 8 for ASCII-7 / ASCII-8 | |
{ | |
if (c & 1) rtty_txbit(1); | |
else rtty_txbit(0); | |
c = c >> 1; | |
} | |
rtty_txbit (1); // Stop bit | |
rtty_txbit (1); // Stop bit | |
} | |
void rtty_txbit (int bit) | |
{ | |
if (bit) | |
{ | |
// high | |
outPin.write = 1; | |
} | |
else | |
{ | |
// low | |
outPin.write = 0; | |
} | |
// delayMicroseconds(3370); // 300 baud | |
// For 50 Baud uncomment this and the line below. | |
wait(0.00020150); // You can't do 20150 it just doesn't work as the | |
// largest value that will produce an accurate delay is 16383 | |
// See : http://arduino.cc/en/Reference/DelayMicroseconds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment