Last active
February 2, 2020 20:49
-
-
Save ytjohn/719504772237953eb28d to your computer and use it in GitHub Desktop.
Uniden/Force AMH 350 Frequency programming
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Pin Number: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18\n", | |
"Designation - N8 N7 N6 N5 N4 N3 N2 N1 N0 A5 A4 A3 A2 A1 A0 K Common\n", | |
"Value - 256 128 64 32 16 8 4 2 1 32 16 8 4 2 1 - - \n", | |
"155.995: 1 1 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0\n", | |
"150.010: 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 1 0\n", | |
"150.025: 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 1 0 0\n", | |
"155.995: 1 1 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0\n", | |
"146.520: 1 1 0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0\n", | |
"145.050: 1 1 0 1 1 0 1 0 1 0 0 1 1 0 0 1 1 0\n", | |
"145.050: 1 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 1 0\n", | |
"144.390: 1 1 0 1 1 0 1 0 0 0 1 0 0 1 1 1 1 0\n", | |
"144.390: 1 1 0 0 1 1 0 0 1 1 0 1 0 0 1 1 1 0\n", | |
"144.392: ERROR\n", | |
"145.047: ERROR\n", | |
"145.049: ERROR\n" | |
] | |
} | |
], | |
"source": [ | |
"import math\n", | |
"\n", | |
"def workdiodes(freq, recv=False):\n", | |
" \"\"\"\n", | |
" Formulas for calculating the frequency:\n", | |
" \n", | |
" Fc = freq For transmitting frequency.\n", | |
" Fc = freq For receiving fequency.\n", | |
" N = Fc/0.4 Disregarding any fractional part.\n", | |
" A = (Fc - 0.4 * N)/0.01 Rounding up any fractional part.\n", | |
" K = 0 If the frequency ends in 5 Khz\n", | |
" K = 1 If the frequency ends in 0 Khz\n", | |
" \n", | |
" Example:\n", | |
" Calculating for 155.995 Mhz.\n", | |
" \n", | |
" N = 155.995/0.4 = 389.9875\n", | |
" \n", | |
" Therefore, N = 389\n", | |
" \n", | |
" A = (155.995 - 0.4 * 389)/0.1 = .395/0.01 = 39.5\n", | |
" \n", | |
" Therefore, A = 40\n", | |
" \n", | |
" The freqency ends in 5 kHz. Therefore K = 0\n", | |
" \n", | |
" Finally, convert the N and A to binary. N = 110000101, A = 101000\n", | |
" \n", | |
" In the pinout below, pin 1 is always \"1\", and 18 \n", | |
" is always 0.\n", | |
" \n", | |
" Pin Number: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18\n", | |
" Designation N8 N7 N6 N5 N4 N3 N2 N1 N0 A5 A4 A3 A2 A1 A0 K Common\n", | |
" Decimal Value 256 128 64 32 16 8 4 2 1 32 16 8 4 2 1 \n", | |
" Binary Code 1 1 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0\n", | |
" \n", | |
" This is a common cathode array, so the diode's cathode (black band side) are all joined together \n", | |
" and connected to pin 18. When connecting diodes, you leave binary \"1\" disconnected (or cut), and\n", | |
" only connect \"0\". \n", | |
" \"\"\"\n", | |
" if recv:\n", | |
" Fc = freq - 21.4\n", | |
" else:\n", | |
" Fc = freq\n", | |
"\n", | |
" # Pad the frequency for display\n", | |
" freq_fmt = \"{:.3f}\" # 3 decimals\n", | |
" freq = freq_fmt.format(freq)\n", | |
" \n", | |
" # if freq ends in 5, K=0, else K =1\n", | |
"\n", | |
" if freq[6:] == \"0\":\n", | |
" K = 1\n", | |
" elif freq[6:] == \"5\":\n", | |
" K = 0\n", | |
" else:\n", | |
" return \"{0}: ERROR\".format(freq)\n", | |
" \n", | |
" N = int(Fc/0.4) # Disrearding any fractional part\n", | |
" A = int(math.ceil((Fc - 0.4 * N)/0.01)) # Rounding UP any fractional part\n", | |
"\n", | |
" # N binary will always be 9 characters, A binary will be 6\n", | |
" # http://stackoverflow.com/a/21732313/895866 \n", | |
" get_bin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or \"-\" + str(bin(x))[3:].zfill(n)\n", | |
" \n", | |
" Nb = get_bin(N, 9)\n", | |
" Ab = get_bin(A, 6)\n", | |
" \n", | |
" return \"{0}: {1}{2}{3}\".format(freq, Nb, Ab, K)\n", | |
"\n", | |
"def pinline(line):\n", | |
" \n", | |
" # Binary Code 1 1 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0\n", | |
" if len(line) != 25:\n", | |
" return line\n", | |
" \n", | |
" outline = []\n", | |
" for x in range(0, len(line)):\n", | |
" if x < 8:\n", | |
" outline.append(line[x])\n", | |
" elif x == 8:\n", | |
" outline.append(' 1 ')\n", | |
" else:\n", | |
" outline.append('{0} '.format(line[x]))\n", | |
"\n", | |
" # Now add the common 0\n", | |
" outline.append('0')\n", | |
" return ''.join(outline)\n", | |
"# return \"\"\"{0[0:9]} 1 {0[0]} {0[1]} {0[2]} {0[3]} {0[4]} {0[5]} {0[6]} {0[7]}\n", | |
"# {0[8]} {0[9]} {0[10]} {0[11]} {0[12]} {0[13]} {0[14]} {0[15]} {0[16]}\n", | |
"# {0[17]}\"\"\".format(line)\n", | |
" \n", | |
"print(\"\"\"\n", | |
"Pin Number: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18\n", | |
"Designation - N8 N7 N6 N5 N4 N3 N2 N1 N0 A5 A4 A3 A2 A1 A0 K Common\n", | |
"Value - 256 128 64 32 16 8 4 2 1 32 16 8 4 2 1 - - \"\"\")\n", | |
"\n", | |
"print(pinline(workdiodes(155.995)))\n", | |
"print(pinline(workdiodes(150.010)))\n", | |
"print(pinline(workdiodes(150.025)))\n", | |
"print(pinline(workdiodes(155.995)))\n", | |
"print(pinline(workdiodes(146.520)))\n", | |
"print(pinline(workdiodes(145.050)))\n", | |
"print(pinline(workdiodes(145.050, True)))\n", | |
"print(pinline(workdiodes(144.390)))\n", | |
"print(pinline(workdiodes(144.390, True)))\n", | |
"print(pinline(workdiodes(144.392)))\n", | |
"print(pinline(workdiodes(145.047)))\n", | |
"print(pinline(workdiodes(145.049)))" | |
] | |
} | |
], | |
"metadata": { | |
"celltoolbar": "Raw Cell Format", | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment