Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to write this in OSHON?

Status
Not open for further replies.

SwingeyP

Member
Can anyone help me produce this in OSHON please.

I assume this function takes a string and puts it character at a time in the variable C.

C = *string++; ------ How do I do this?

Then the string is looped over and sent to another function until a special character is found.

Here's the code can anyone re-create it in OSHON?

Code:
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++;
  }
}
 
This is just a fancy way to access an array (and move to the next position).
C = *string++;

You can do the same thing using index variable:

char i=0;
C = string;
i++;

Sorry that I'm not a Basic programmer and don't use Oshonsoft, but here is the function modified to a much simpler form:

Code:
void rtty_txstring (char * string)
{ 
  char i=0;

  While ( string[i] != '\0' )
  {
    rtty_txbyte(string[i]);
    i++;
  }
}
 
Last edited:
Thanks guys. I understand what the function does but writing it in OSHON is a different matter.

Does OSHON have string functions? - I can't find them in the help. - I'll give this code a go.

Code:
for x = 0 to stringlength
   C= lookup("the string you need to send"),x
   sendbyte C
next x
[/QUOTE]
 
Hi again - another question ....

How do I do this?

Code:
  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;
 
  }
I have ....

Code:
For i = 0 To 7  'change this here 7 Or 8 For ascii-7 / ascii-8
	If(chr & 1) Then
		Call rtty_txbit(1)
	Else
		rtty_txbit(0)
	Endif
Next i
 
In C, strings are single dimensional arrays where the character '\0' indicates the end of the string. I think you have to use single dimensional arrays in Oshonsoft also, if you want to pass the string to a function.
 
I think that should be close to:

Code:
For i = 0 To 7  'change this here 7 Or 8 For ascii-7 / ascii-8
	If chr.0 Then
		Call rtty_txbit(1)
	Else
		Call rtty_txbit(0)
	Endif
        chr = ShiftRight(chr, 1)
Next i
 
Last edited:
Hi thanks again. I now have code that does somethingin simulation. I can see porta.7 toggling anyway?

The original code looked like this ... from an article here --- > https://ukhas.org.uk/guides:linkingarduinotontx2

Code:
/*  NTX2 Radio Test Part 2
 
    Transmits data via RTTY with a checksum.
 
    Created 2012 by M0UPU as part of a UKHAS Guide on linking NTX2 Modules to Arduino.
    RTTY code from Rob Harrison Icarus Project. 
    http://ukhas.org.uk
*/ 
 
#define RADIOPIN 13
 
#include <string.h>
#include <util/crc16.h>
 
char datastring[80];
 
void setup() {                
  pinMode(RADIOPIN,OUTPUT);
}
 
void loop() {
 
 
  sprintf(datastring,"RTTY TEST BEACON RTTY TEST BEACON"); // Puts the text in the datastring
  unsigned int CHECKSUM = gps_CRC16_checksum(datastring);  // Calculates the checksum for this datastring
  char checksum_str[6];
  sprintf(checksum_str, "*%04X\n", CHECKSUM);
  strcat(datastring,checksum_str);
 
  rtty_txstring (datastring);
  delay(2000);
}
 
 
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
    digitalWrite(RADIOPIN, HIGH);
  }
  else
  {
    // low
    digitalWrite(RADIOPIN, LOW);
 
  }
 
  //                  delayMicroseconds(3370); // 300 baud
  delayMicroseconds(10000); // For 50 Baud uncomment this and the line below. 
  delayMicroseconds(10150); // 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
 
}
 
uint16_t gps_CRC16_checksum (char *string)
{
  size_t i;
  uint16_t crc;
  uint8_t c;
 
  crc = 0xFFFF;
 
  // Calculate checksum ignoring the first two $s
  for (i = 2; i < strlen(string); i++)
  {
    c = string[i];
    crc = _crc_xmodem_update (crc, c);
  }
 
  return crc;
}

I now have this ...

Code:
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'RTTY with NTX2 Test written by paul swingewood
'March 2013   - PIC 16F628A
'--------------------------------------------------------------------------

'Define SIMULATION_WAITMS_VALUE = 2


Define CONF_WORD = 0x3f50  'Internal Oscillator'
Define CLOCK_FREQUENCY = 4
AllDigital

'Define the comms for the LCD display.
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4  'Use the high order bits'
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 0
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1


Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20


Define SEROUT_DELAYUS = 1000

Symbol txcr_pin = PORTA.7
Dim i As Byte  'used for loops
Dim ch As Byte  'used to hold individual character
Dim chr As Byte

startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear
WaitMs 500

loop:
For i = 0 To 15
ch = LookUp("RTTY TEST BEACON"), i
Call rtty_txtbyte(ch)
Next i

Goto loop
End                                               

Function rtty_txtbyte(chr As Byte) As Byte

'simple function to send 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


Call rtty_txbit(0)  'start Bit

'send bits For For char lsb first

For i = 0 To 7  'change this here 7 Or 8 For ascii-7 / ascii-8
	chr = chr And 1
	If chr = 1 Then
		Call rtty_txbit(1)
	Else
		Call rtty_txbit(0)
	Endif
Next i

Call rtty_txbit(1)  'stop Bit
Call rtty_txbit(1)  'stop Bit

End Function                                      

Function rtty_txbit(b As Bit) As Bit

If b = 1 Then
'High
	High txcr_pin
Else
'Low
	Low txcr_pin
Endif
End Function

I still have no idea how the string is actually output. I haven't done the crc check. - About to program the pic and see what happens.
 
You are missing the "ShiftRight(chr, 1)" from the "rtty_txtbyte" functions for-loop. That is important... actually the line should probably be:
chr = ShiftRight(chr, 1)

EDIT:
You cant say this in the "rtty_txtbyte" function:
chr = chr And 1

that replaces the chr variable with something wrong (something other than the data you want to send).
You can use a temporary variable:
tmp = chr And 1
If tmp = 1 Then ...
 
Last edited:
I rewrote my code in post #7, take a look at that. The idea of the "If" statement is to test is the first bit of chr zero or one.
If you can really access single bits that way, you could maybe replace the whole If-Else structure with just single call:
Call rtty_txbit(chr.0)

.. but this is getting out of my skills in Basic, so I hope somebody else can help you further.
 
Hi MisterT - Can you just tell me what does this line do ?

If chr.0 Then

If bit 0 of chr =1? is that it?

Regards - Paul
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top