-
Notifications
You must be signed in to change notification settings - Fork 1
/
CPCTR.hp42s
117 lines (117 loc) · 1.52 KB
/
CPCTR.hp42s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@ Convert between capacitor codes and capacity values
LBL "CPCTR"
CLMENU
"→VAL"
KEY 1 XEQ 01
"→CODE"
KEY 2 XEQ 02
KEY 9 GTO 99
MENU
LBL 20 // menu loop
STOP
GTO 20
LBL 01 // convert from capacitor code to its value
10
÷
ENTER // duplicate value for later use
IP
10
÷
STO 01 // store fraction part in REG 01
R↓ // retrieve copy of original value
FP
10
× // ST X now contains exponent part
10↑X
10ᴇ-12 // base value is 10 pF
×
RCL× 01 // ST X now contain capacitor value
ENTER
CLA
XEQ 03
├"F"
AVIEW
R↓
R↓
R↓ // recover full capacitor value
GTO "CPCTR"
LBL 02 // convert from capacitor value to its code
10ᴇ-12 // base value is 10 pF
÷
ENTER // duplicate value for later use
LOG
IP
STO 01 // store exponent part in REG 01
10↑X
÷ // ST X now contains fraction part
10
×
IP
10
×
RCL+ 01
CLA
"Code: "
ARCL ST X
AVIEW
GTO "CPCTR"
LBL 03 // Pretty print number with unit prefix
ENTER
LOG
3
÷
0.5
-
IP
STO 01 // store prefix number in REG 01
-4
X>Y? // prefix < -4?
STO 01 // limit prefix to -4
R↓
3
X<Y? // prefix > 9?
STO 01 // limit prefix to 3
R↓
R↓ // recover original number
RCL 01
3
*
10↑X
÷ // have now fractional part
ARCL ST X // append fractional part to ALPHA register
RCL 01
-4
X=Y?
├" p"
R↓
-3
X=Y?
├" n"
R↓
-2
X=Y?
├" µ"
R↓
-1
X=Y?
├" m"
R↓
0
X=Y?
├" "
R↓
1
X=Y?
├" k"
R↓
2
X=Y?
├" M"
R↓
3
X=Y?
├" G"
RTN
LBL 99 // exit program
CLMENU
EXITALL