📄 fuzzy.prn
字号:
1 * Fuzzy Logic Inference Engine
2 *
3 *** Data structures and variables
4 *
5 0000 ORG $0000 Beginning of HC11 RAM
6 0000 CURRENT_INS RMB 8 Storage for 8 8-bit inputs
7 0008 FUZ_OUTS RMB 32 Storage for fuzzy outputs
8 0028 COG_OUTS RMB 4 Defuzzified outputs
9 002C LOWEST_IF RMB 1 Holds min grade of IF parts
10 002D SUM_OF_FUZ RMB 2 11-bit sum of fuzzy outs
11 002F SUM_OF_PROD RMB 3 19-bit sum of products
12 0032 COGDEX RMB 1 Current out # for COG loop 0->4
13 0033 SUMDEX RMB 1 Index for sum loop 8->0
14
15 B600 ORG $B600 Beginning of HC11 EEPROM
16 B600 B610 IN_MF_PTRS FDB IN0MF Addr of MF data for input 0
17 B602 B618 FDB IN1MF Addr of MF data for input 1
18 B604 B61C FDB IN2MF Addr of MF data for input 2
19 B606 B630 FDB IN3MF Addr of MF data for input 3
20 B608 B644 FDB IN4MF Addr of MF data for input 4
21 B60A B644 FDB IN5MF Addr of MF data for input 5
22 B60C B644 FDB IN6MF Addr of MF data for input 6
23 B60E B644 FDB IN7MF Addr of MF data for input 7
24 *
25 * Input membership functions are defined by four 8-bit values per
26 * input label. Up to 8 labels per input so max size of MF data
27 * structure is 8*8*4=256 bytes. Unused labels take no space.
28 * Membership functions are trapezoids with the base greater than or
29 * equal to the top. Values are entered into this program as the
30 * X coordinates of 4 points but are stored as 2 points and 2 slopes.
31 *
32 ***** MACRO Definition for input membership functions
33 *
34 M INMF MACRO For input membership functions
35 M FCB :0 First inflection point
36 M IF :1-:0 Check for divide by zero
37 M FCB ($FF+((:1-:0)/2))/(:1-:0) If not, calc slope
38 M ELSE
39 M FCB $00 Indicates vertical slope
40 M ENDIF
41 M FCB :2 Third inflection point
42 M IF :3-:2 Check for divide by zero
43 M FCB ($FF+((:3-:2)/2))/(:3-:2) If not, calc slope
44 M ELSE
45 M FCB $00 Indicates vertical slope
46 M ENDIF
47 M ENDM
48 *
49 *****
50 B610 INPUT_MFS EQU * Input membership functions
52 B610 IN0MF EQU * (0) ROTATION
53 B610 00 00 00 08 INMF 0,0,0,8*4 (0) STOPPED
66 B614 00 08 FF 00 INMF 0,8*4,$FF,$FF (1) NOT_STOPPED
79
80 B618 IN1MF EQU * (1) EXAMPLE1
81 B618 20 08 60 04 INMF $20,$40,$60,$A0 (0) TEST1
94
95 B61C IN2MF EQU * (2) TEMPERATURE
96 B61C 00 00 50 0D INMF 2*0,2*0,2*40,2*50 (0) COLD
109 B620 50 0D 78 0D INMF 2*40,2*50,2*60,2*70 (1) COOL
122 B624 78 0D A0 0D INMF 2*60,2*70,2*80,2*90 (2) WARM
135 B628 A0 0D BE 09 INMF 2*80,2*90,2*95,2*110 (3) HOT
148 B62C B4 06 FF 00 INMF 2*90,2*110,$FF,$FF (4) VERY_HOT
161
162 B630 IN3MF EQU * (3) DAYS_SINCE_RAIN
163 B630 00 00 00 20 INMF $00,$00,$00,$08 (0) NONE
176 B634 00 10 10 20 INMF $00,$10,$10,$18 (1) SHORT
189 B638 10 10 28 0B INMF $10,$20,$28,$40 (2) MEDIUM
202 B63C 30 10 50 10 INMF $30,$40,$50,$60 (3) LONG
215 B640 50 08 FF 00 INMF $50,$70,$FF,$FF (4) VERY_LONG
228
229 B644 IN4MF EQU * Not used
230 B644 IN5MF EQU * Not used
231 B644 IN6MF EQU * Not used
232 B644 IN7MF EQU * Not used
233
234 B644 SGLTN_POS EQU * Output singleton positions
235 B644 OUT0MF EQU * (0) WATERING_TIME
236 B644 00 FCB $00 (0) CUT_OFF
237 B645 10 FCB $10 (1) DECREASE_GREATLY
238 B646 40 FCB $40 (2) DECREASE
239 B647 80 FCB $80 (3) NORMAL
240 B648 B0 FCB $B0 (4) INCREASE
241 B649 F0 FCB $F0 (5) INCREASE_GREATLY
242 B64A 00 00 FCB 0,0 Unused; Fill 8 per output
243 B64C 00 00 00 00 OUT1MF FCB 0,0,0,0,0,0,0,0 Not used
00 00 00 00
244 B654 00 00 00 00 OUT2MF FCB 0,0,0,0,0,0,0,0 Not used
00 00 00 00
245 B65C 00 00 00 00 OUT3MF FCB 0,0,0,0,0,0,0,0 Not used
00 00 00 00
246 *
247 * Each If part is of the form 00AA AXXX where AAA is a label (0-7)
248 * and XXX is an input (0-7). If parts are connected by ANDs. A rule
249 * may have any number of if parts (usually 2-8). Then parts are of
250 * the form 100Y YCCC where the MSB set indicates a then part, YY is
251 * the output number (0-3), and CCC is the output label (singleton
252 * 0-7). A rule may have any number of then parts (usually 1 or 2).
253 * A $FF indicates the end of a series of rules (number not limited).
254 *
255 * FCB INx + 8*LABa If input XXX is label AAA
256 * FCB $80+8*OUTy+LABc Then output YY is label CCC
257
258 B664 RULE_START EQU * Start of first rule
259 * Example rule: If TEMPERATURE is VERY_HOT and DAYS_SINCE_RAIN is LONG
260 * Then WATERING_TIME is INCREASE_GREATLY
261 B664 221B85 RULE_1 FCB 2+(8*4),3+(8*3),$80+(8*0)+5
262 B667 FF END_OF_RULE FCB $FF
263
264 ***** Fuzzy Inferrence Engine Starts Here
265 *
266 B668 CE0008 [ 3] INFER_TOP LDX #FUZ_OUTS Point at first fuzzy output
267 B66B 8620 [ 2] LDAA #32 32 fuzzy outputs
268 B66D 6F00 [ 6] CLR_OUTS CLR 0,X Clear a fuzzy output
269 B66F 08 [ 3] INX Point at next
270 B670 4A [ 2] DECA Loop index
271 B671 26FA [ 3] BNE CLR_OUTS Continue till all fuzzy outs 0
272 B673 18CEB664 [ 4] LDY #RULE_START Point to start of 1st rule
273 B677 86FF [ 2] RULE_TOP LDAA #$FF Begin processing rule string
274 B679 972C [ 3] STAA LOWEST_IF Will hold grade of min if part
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -