'#! / usr / bin / perl - W
'# (C) 2012 Chris Ruvolo. Licensed under a 2-clause BSD license.
'If($ #argv < 1) {
'printf("Usage: $0 <lat> <long>\n");
'Exit(1);
'}
'my $lat = $ARGV[0];
'my $lon = $argv[1];
'my $grid = "";
'$lon = $lon + 180;
'$lat = $lat + 90;
'$grid .= chr(ord('A') + int($lon / 20));
'$grid .= chr(ord('A') + int($lat / 10));
'$grid .= chr(ord('0') + int(($lon % 20)/2));
'$grid .= chr(ord('0') + int(($lat % 10)/1));
'$grid .= chr(ord('a') + int(($lon - (int($lon/2)*2)) / (5/60)));
'$grid .= chr(ord('a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
'print "$grid\n";
'-------------------------------------------------
'Procedures
'-------------------------------------------------
Proc calc_loc(lat As Byte, lng As Byte)
If raw_data(30) = 0x57 Then 'in other words the value would be -1
lng = 179 'so -1 + 180 = 179
Else
lng = lng + 180
Endif
lat = lat + 90
loc(0) = 65 + (lng / 20) '65 = ascii A
loc(1) = 65 + (lat / 10)
loc(2) = 48 + ((lng Mod 20) / 2) '48 = Ascii zero
loc(3) = 48 + ((lat Mod 10) / 1)
'temp1 = lng / 2 '179/2=89
'temp2 = temp1 * 2 '89*2=178
'temp3 = lng - temp2 '179 - 178 = 1
'temp4 = (temp3 / (5 / 60)) + 97 '= 1/0.084 = 98 = b
'loc(4) = temp4
loc(4) = 97 + ((lng - ((lng / 2) * 2)) / (5 / 60)))
'$grid.= chr(ord( 'a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
End Proc
I'm not very good at maths but surely 5/60 is not the same as multiplying by 12. 60/5 would make sense.
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'Maidenhead locator - Written by Paul Swingewood
'13/10/2013 - PIC 16F628A
'--------------------------------------------------------------------------
Define SIMULATION_WAITMS_VALUE = 1
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 = 16
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
'--------------------------------------------------
'variables
'----------------------------------------------------
Dim lng As Byte
Dim lat As Byte
Dim i As Byte 'used as array element loop
Dim pos As Byte
Dim temp1 As Byte
Dim temp2 As Byte
Dim temp3 As Byte
Dim temp4 As Byte
Dim temp5 As Byte
Dim temp6 As Byte
Dim loc(5) As Byte
startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear
WaitMs 2000 'Give everything time to power up 2 seconds?
start:
'calcualte the locator
Call calc_loc(44, 1, 0)
'Display the locator
pos = 5
For i = 0 To 5
Lcdcmdout LcdLine4Pos(pos)
Lcdout loc(i)
pos = pos + 1
Next i
Goto start
End
'-------------------------------------------------
'Procedures
'-------------------------------------------------
Proc calc_loc(arglat As Byte, arglng As Byte, argew As Byte)
If argew = 0 Then
If arglng <= 0 Then
lng = 178
Else 'west
lng = 180 - arglng
Endif
Else
lng = arglng + 180
Endif
lat = arglat + 90
loc(0) = (lng / 20) + 65 '65 = ascii A
loc(1) = 65 + (lat / 10)
loc(2) = 48 + ((lng Mod 20) / 2) '48 = Ascii zero
loc(3) = 48 + ((lat Mod 10) / 1)
temp1 = lng / 2 '179/2=89
temp2 = temp1 * 2 '89*2=178
temp3 = lng - temp2 '179 - 178 = 1
temp4 = temp3 / (5 / 60)
loc(4) = temp4
'loc(4) = 97 + ((lng - ((lng / 2) * 2)) / (5 / 60)))
'$grid .= chr(ord('a') + int(($lon - (int($lon/2)*2)) / (5/60)));
'$grid.= chr(ord( 'a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
End Proc
'--------------------------- O R I G I N A L C O D E -----------------------------------
'#! / usr / bin / perl - W
'# (C) 2012 Chris Ruvolo. Licensed under a 2-clause BSD license.
'If($ #argv < 1) {
'printf("Usage: $0 <lat> <long>\n");
'Exit(1);
'}
'my $lat = $ARGV[0];
'my $lon = $argv[1];
'my $grid = "";
'$lon = $lon + 180;
'$lat = $lat + 90;
'$grid .= chr(ord('A') + int($lon / 20));
'$grid .= chr(ord('A') + int($lat / 10));
'$grid .= chr(ord('0') + int(($lon % 20)/2));
'$grid .= chr(ord('0') + int(($lat % 10)/1));
'$grid .= chr(ord('a') + int(($lon - (int($lon/2)*2)) / (5/60)));
'$grid .= chr(ord('a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
'print "$grid\n";
I have just purchased the floating point and 32bit add ons. I thought I already had. Now waiting for licences. I see now how the equation works having gone through it bit by bit on paper.
Will the floating point allow me to store the coordinates as 1.89698 and 52.56216 ( maybe a little shorter accuracy)? This would be really helpful
The co-ordinates come from a GPS receiver (Lassen SK8) I have all that bit of the code working fine having used it on another project. The maidenhead project serves no real purpose other than knowing how to do it.
The idea is to take the project outdoors with me when I operate my Ham Radio station portable and know the maidenhead square I am operating from. You can do it with a mobile phone app but where's the fun in that?
I'll let you know how I get on when I have the new licence(s).
I do have a further question but i'll start a new thread for that one.
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'Maidenhead locator - Written by Paul Swingewood
'13/10/2013 - PIC 16F628A
'--------------------------------------------------------------------------
Define SIMULATION_WAITMS_VALUE = 1
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 = 16
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
'--------------------------------------------------
'variables
'----------------------------------------------------
Dim lng As Single
Dim lat As Single
Dim i As Byte 'used as array element loop
Dim pos As Byte
Dim tmp As Byte
Dim tmp2 As Single
Dim loc(5) As Byte
startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear
WaitMs 2000 'Give everything time to power up 2 seconds?
start:
'calcualte the locator
Call calc_loc(60.17, 24.94, 1) 'Helsinki KP20le
'Display the locator
pos = 5
For i = 0 To 5
Lcdcmdout LcdLine4Pos(pos)
Lcdout loc(i)
pos = pos + 1
Next i
Break
'Goto start
End
'-------------------------------------------------
'Procedures
'-------------------------------------------------
Proc calc_loc(arglat As Single, arglng As Single, argew As Byte)
If argew = 0 Then
If arglng <= 0 Then
lng = 178
Else 'west
lng = 180 - arglng
Endif
Else
lng = arglng + 180
Endif
lat = arglat + 90
loc(0) = 65 + lng / 20 '65 = ascii A
loc(1) = 65 + lat / 10
loc(2) = 48 + modulus(lng, 20) / 2 '48 = Ascii zero
loc(3) = 48 + modulus(lat, 10) / 1
tmp = lng / 2
tmp = tmp * 2
tmp2 = lng - tmp
loc(4) = 97 + tmp2 * 12
tmp = lat / 1
tmp = tmp * 1
tmp2 = lat - tmp
loc(5) = 97 + tmp2 * 24
End Proc
Function modulus(arg1 As Single, arg2 As Single) As Single
Dim x As Byte
Dim y As Single
y = arg1 / arg2
x = y
modulus = (y - x) * arg2 + 0.001 '0.001 is for small errors in floating point math
End Function
'--------------------------- O R I G I N A L C O D E -----------------------------------
'#! / usr / bin / perl - W
'# (C) 2012 Chris Ruvolo. Licensed under a 2-clause BSD license.
'If($ #argv < 1) {
'printf("Usage: $0 <lat> <long>\n");
'Exit(1);
'}
'my $lat = $ARGV[0];
'my $lon = $argv[1];
'my $grid = "";
'$lon = $lon + 180;
'$lat = $lat + 90;
'$grid .= chr(ord('A') + int($lon / 20));
'$grid .= chr(ord('A') + int($lat / 10));
'$grid .= chr(ord('0') + int(($lon % 20)/2));
'$grid .= chr(ord('0') + int(($lat % 10)/1));
'$grid .= chr(ord('a') + int(($lon - (int($lon/2)*2)) / (5/60)));
'$grid .= chr(ord('a') + int(($lat - (int($lat/1)*1)) / (2.5/60)));
'print "$grid\n";
int($lat/1)*1
int($lat)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?