Bascom to Picaxe ?

1968neil

Senior Member
Hi All,

Need to convert the attached basic code for use with a picaxe.
Not familiar with some of the commands used, however most of the code makes sense. Once i can get it working i can alter it to suit my purpose.

It's a 5 tone selcall decoder for use with ham radio.
Im building a logger and the decoder needs to be my starting point.

Any help or pointers much appreciated
Regards
Neil

Code:
$regfile = "m8def.dat"
$crystal = 8000000
Ddrd = &B00010000
Portd.2 = 1
Config Timer1 = Timer , Prescale = 1 , Capture Edge = Rising , Noise Cancel = 1
Config Aci = On , Compare = On , Trigger = Rising
On Icp1 Oncapture
Enable Icp1
Cls
On Int0 Buttonpress
Config Int0 = Falling
Enable Int0
Enable Interrupts
Dim Countcycles As Word
Dim Icr_new As Word
Dim Icr_old As Word
Dim Frequlong As Long
Dim Freqcy As Word
Dim A(5) As Word
Dim Freqsum As Word
Dim Timesample As Integer
Dim Freqmeasure As Word
Dim Frequpper As Word
Dim Freqlow As Word
Dim Tone As String * 1
Dim Toneold As String * 1
Dim Sequence As String * 10
Dim Timeout As Word

Lcd "Stand by..."

Main:
Waitms 2
Frequlong = 8000000 / Icr_new
Icr_new = 1
Freqcy = Frequlong

Incr Timeout
If Timeout > 40 Then
   Sequence = ""
   Toneold = ""
   Timeout = 0
End If

A(5) = A(4)
A(4) = A(3)
A(3) = A(2)
A(2) = A(1)
A(1) = Freqcy
Freqsum = 0

For Timesample = 1 To 5
   Freqsum = Freqsum + A(timesample)
Next

Freqmeasure = Freqsum / 5
Frequpper = A(1) + 10
Freqlow = A(1) - 10

If Freqmeasure > Freqlow And Freqmeasure < Frequpper Then
   Select Case Freqmeasure
      Case 1114 To 1134 : Tone = "1"
      Case 1187 To 1207 : Tone = "2"
      Case 1265 To 1285 : Tone = "3"
      Case 1348 To 1368 : Tone = "4"
      Case 1436 To 1456 : Tone = "5"
      Case 1530 To 1550 : Tone = "6"
      Case 1630 To 1650 : Tone = "7"
      Case 1737 To 1757 : Tone = "8"
      Case 1850 To 1870 : Tone = "9"
      Case 1971 To 1991 : Tone = "0"
      Case 2390 To 2410 : Tone = "A"
      Case 920 To 940 : Tone = "B"
      Case 2237 To 2257 : Tone = "C"
      Case 981 To 1001 : Tone = "D"
      Case 2100 To 2120 : Tone = "E"
      Case Else
         Locate 1 , 1
         Lcd "notone"
         Goto Main
   End Select
Else : Goto Main
End If

If Tone = Toneold Then Goto Main
Locate 1 , 1
Lcd "1 tone"

Toneold = Tone
Sequence = Sequence + Tone
Timeout = 0

If Len(sequence) >= 5 Then
   Locate 1 , 1
   Lcd Sequence
Rem Sequence = "" let timeout take care of this
End If
Goto Main

Buttonpress:
   Portd.4 = 0
   Cls
Return

Oncapture:
   Countcycles = Timer1
   Icr_new = Countcycles - Icr_old
   Icr_old = Countcycles
Return
 

MartinM57

Moderator
So which bits don't make sense?

(blimey - two posts with AVR code examples in 5 minutes - one in C and the other in BASIC...watch out, the AVRFreaks are invading the forum :D)
 

1968neil

Senior Member
$regfile = "m8def.dat"
Ddrd = &B00010000 (poss let Pins = ?)
Dim

may just download the bascomm manual and read up, Dont worry Martin , ive never seen an AVR, prefer Pic and Picaxe ! ;)
 

MartinM57

Moderator
ive never seen an AVR, prefer Pic and Picaxe ! ;)
Don't worry, one day you will grow up and see the light :D

$regfile = "m8def.dat"
Ddrd = &B00010000 (poss let Pins = ?)
Dim

may just download the bascomm manual and read up, Dont worry Martin , ive never seen an AVR, prefer Pic and Picaxe ! ;)
$regfile is telling Bascom that the chip is a ATMega8 AVR so that it understands the variable names later on

DDRD is the Data Direction Register for Port D - so you are correct in that the equivalent PICAXE command is let pins=....

DIM is declaring variables (no real limit to number of variables - unlike the PICAXE b and w variables)

The code is quite advanced in that it uses two interrupts in an AVR running at 8Mhz so each Bascom command is running in a few microseconds (i.e. way faster than PICAXE BASIC command speeds) - I've zero idea what a "5 tone selcall decoder" is, but if time is of the essence, you might have trouble converting it to a PICAXE

Yes, the BASCOM manual sounds like a good place to start...
 

1968neil

Senior Member
Cheers Martin,

Looks like ill have to start from the beginning with a larger pic !!
haven't had anything to do with AVR.

http://en.wikipedia.org/wiki/Selcall

Selcall (selective calling) is used as a type of paging function for two way radio, you'll of heard the "tones" at the end or beginning of radio transmissions used by the fire/police and airports etc.
The 5 tones are sequential ie: 56001 could be an individual radios ID and when that number is sent the radio responds accordingly.
It's a bit more involved than that but the basic functions are as described.

Thanks for the input.

Regards
Neil
 

hippy

Technical Support
Staff member
You may be able to implement it all with a simple COUNT command and a SELECT CASE.
 

1968neil

Senior Member
@ Hippy,

You may have a point, all im trying to do is decode (read) the five tones and send them to my pc via serial.

Shouldnt be hard, ill have a play when i get in from work tonight and see whats what.
Thanks again

Regards
Neil
 
Top