Форум программистов, компьютерный форум, киберфорум
Измерительная техника
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск  
 
 
Рейтинг 4.56/117: Рейтинг темы: голосов - 117, средняя оценка - 4.56
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536

Замена микросхемы 1827ВЕ1-0000000 в Г4-164 на AVR -МК

31.08.2019, 07:43. Показов 30842. Ответов 229
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Как заменить 1827ВЕ1-0000000 (аналог 586ВЕ1, система команд в книжке Гамкрелидзе, кажется, отрицательная логика на мультиплексированной шине адреса-данных , нестандартный UART ) в Г4-164 на AVR -МК ATMEGA8A, ATMEGA48, ATMEGA8535, используя , например, маскированные прерывания от одного из портов, битвайсовую эмуляцию пинов (шину ПЗУ можно не использовать ), подпрограммы задержки , используя С++, ассемблерные вставки ? Предусмотреть частоты , а которых переключаются фильтры, увеличение девиации в n раз в коэффициентах АЦП при включении делителей на n, таблицу коэффициентов в ЦАП в децибелах (с учетом , например, того , что 31,7-100 мВ , на 31,6 переключается аттенюатор и включается верх напряжения ЦАП ОН ), обработку прерывания от КОП и другие функции , как по инструкции (https://www.astena.ru/teh_3.html ) ?
Миниатюры
Замена  микросхемы 1827ВЕ1-0000000 в Г4-164 на AVR -МК  
Вложения
Тип файла: zip img012.zip (1.35 Мб, 38 просмотров)
Тип файла: zip g4-164_shems.zip (5.48 Мб, 35 просмотров)
Тип файла: zip g4-164_teh.zip (5.28 Мб, 35 просмотров)
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
31.08.2019, 07:43
Ответы с готовыми решениями:

Замена микросборок 2.030.036 ,2.030.034 в Г4-164, Г4-176
Замена микросборок 2.030.036 в Г4-164, 2.030.034 в Г4-176 : на какие транзисторы в современных условиях лучше заменить...

замена микросхемы
Нужно заменить микросхему драйвер двигателя на HDD Smooth 100369972 . На али есть такие схемки но смущает то что цифробуквы на моей схемке...

Замена микросхемы AT49F002NT
Господа! Если кто знает ,какая микросхема может заменить AT49F002NT?

229
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
17.03.2020, 02:18  [ТС]
Студворк — интернет-сервис помощи студентам
Assembler
1
2
3
4
5
6
7
8
9
SendBitInform:  ; value in tmpreg
 
call SetPinsDefault1;
call SetAddrInform ;
SetPin34Out ;
 
 
call SendPin34LowIfDataIsZero
ret
Добавлено через 39 секунд
Assembler
1
2
3
4
5
6
.macro Send_nInformBit_0_ifbitis1
mov tmp2, @0
call Send_nInformBit_0_IfFirtstBitTrue ;  
ldi  tmp1, @1
call SendStrobeSync; 
.endmacro

Assembler
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
; if bit is false,  send 1 
; Send_nInformBit_0_IfFirtstBitTrue
;  count=0; 
; label1: 
;  { count++;   if (CheckFirstBit( db1)) { SendBitInform(0);  }  else { SendBitInform(1); }     }
;  if (count>=numbits)   return 
;  goto label1
 
 
.macro Send_n_bits_nInform_0_If_Bits_are1 
clr r19 
 
LabelNextByte:
mov r18, @0 ; byte to send  
 
call SetPinsDefault1;
call SetAddrInform ;
SetPin34Out ;
andi r18, 0x01 ;  Send_nInformBit_0_If_FirtstBitTrue:
cpi   r18, 0x00  ; Send_nInformBit_1_IfByteFalse
breq  label_sendbit_ninform1_if_bytefalse ;    fix
SetPin34Low;
label_sendbit_ninform1_if_bytefalse :
SetPin34High 
 
ldi  r17, @1 ; Addr of SYNC
call SendStrobeSync; 
 
inc r19 
cpi r19, @2  ; nbytes 0x08
brge LabelExitSend
lsr reg_data
jmp LabelNextByte
 
LabelExitSend:
clc  
.endmacro
Добавлено через 1 минуту
Assembler
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
.macro Send_n_bits_nInform_1_If_Bits_are1 
clr r19 
 
LabelNextByte:
mov r18, @0 ; byte to send  
 
call SetPinsDefault1;
call SetAddrInform ;
SetPin34Out ;
andi r18, 0x01 ;  Send_nInformBit_0_If_FirtstBitTrue:
cpi   r18, 0x00  ; Send_nInformBit_1_IfByteFalse
brne  label_sendbit_ninform0_if_bytefalse ;    fix
SetPin34Low;
label_sendbit_ninform0_if_bytefalse :
SetPin34High 
 
ldi  r17, @1 ; Addr of SYNC
call SendStrobeSync; 
 
inc r19 
cpi r19, @2  ; nbytes 0x08
brge LabelExitSend
lsr reg_data
jmp LabelNextByte
 
LabelExitSend:
clc  
.endmacro
Добавлено через 58 минут
Assembler
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
.macro Send_n_bits_nInform_0_If_Bits_are1 
clr r19 
 
LabelNextByte:
mov r18, @0 ; byte to send  
 
call SetPinsDefault1;
call SetAddrInform ;
SetPin34Out ;
andi r18, 0x01 ;  Send_nInformBit_0_If_FirtstBitTrue:
cpi   r18, 0x00  ; Send_nInformBit_1_IfByteFalse
breq  label_sendbit_ninform1_if_bytefalse ;    fix
SetPin34Low;
label_sendbit_ninform1_if_bytefalse :
SetPin34High 
 
ldi  r17, @1 ; Addr of SYNC
call SendStrobeSync; 
 
inc r19 
cpi r19, @2  ; nbytes 0x08
brge LabelExitSend
lsr r18
jmp LabelNextByte
 
LabelExitSend:
clc  
.endmacro
 
 
.macro Send_n_bits_nInform_1_If_Bits_are1 
clr r19 
 
LabelNextByte:
mov r18, @0 ; byte to send  
 
call SetPinsDefault1;
call SetAddrInform ;
SetPin34Out ;
andi r18, 0x01 ;  Send_nInformBit_0_If_FirtstBitTrue:
cpi   r18, 0x00  ; Send_nInformBit_1_IfByteFalse
brne  label_sendbit_ninform0_if_bytefalse ;    fix
SetPin34Low;
label_sendbit_ninform0_if_bytefalse :
SetPin34High 
 
ldi  r17, @1 ; Addr of SYNC
call SendStrobeSync; 
 
inc r19 
cpi r19, @2  ; nbytes 0x08
brge LabelExitSend
lsr r18
jmp LabelNextByte
 
LabelExitSend:
clc  
.endmacro
 
 
 
 
/*************************************/
 
 
 
 
 
 
 
 
 
 
 SendDivCoefDPKD: ;   reg_byte0, reg_byte1,reg_byte2,reg_byte3, reg_byte4, reg_byte5;    digits_f[6] 
 
 
; for bit=1 in the register set 0  on the pin34 as output , 1-st bit of the LSB digit of the dividing coeff.  first 
;  bit 0  digit1  , LSB  Send_nInformBit_0_IfFirtstBitTrue 
;  bit 1  digit1
;  bit 2  digit1
;  bit 3  digit1
;  bit 0  digit2  digits_f[1];  , for D26
;  bit 1  digit2
;  bit 2  digit2
;  bit 3  digit2
;  bit 0  digit3  digits_f[2];  , for D7
;  bit 1  digit3
;  bit 2  digit3
;  bit 3  digit3
;  bit 0  digit4   ;  digits_f[3];//9, for D10
;  bit 1  digit4
;  bit 2  digit4
;  bit 3  digit4
;  bit 0  digit5   digits_f[4];//7,for D16
;  bit 1  digit5
;  bit 2  digit5
;  bit 3  digit5
;  bit 0  digit6   ; digits_f[5];//12, for D20
;  bit 1  digit6
;  bit 2  digit6
;  bit 3  digit6
 
; mov reg_data, reg_byte0 ; digits_f[0];   8, for D24
 
 
 
Send_n_bits_nInform_0_If_Bits_are1  reg_byte0, ADDR_DPKD, 0x04
Send_n_bits_nInform_0_If_Bits_are1  reg_byte1, ADDR_DPKD, 0x04
Send_n_bits_nInform_0_If_Bits_are1  reg_byte2, ADDR_DPKD, 0x04 
Send_n_bits_nInform_0_If_Bits_are1  reg_byte3, ADDR_DPKD, 0x04
Send_n_bits_nInform_0_If_Bits_are1  reg_byte4, ADDR_DPKD, 0x04
Send_n_bits_nInform_0_If_Bits_are1  reg_byte5, ADDR_DPKD, 0x04 
    
;SendMemWrPulse(); 
ret
 
 
 
SendDAC_FM_DAC: ;  DACFM reg_digit1 ,    DACAt    reg_byte0
 
; for send 1  to the trigger FM/At  set 0   on the pin 34 and send SyncFM pulse 
 
 ; bit '8' DAC at, no data
 ; bit '4' DAC at
 ; bit '2' DAC at
 ; bit '1' DAC at 
 
; bit 2 DAC FM 
; bit 3 DAC FM
; bit 4 DAC FM 
; bit 5 DAC FM 
; bit 6 DAC FM  
; bit 7 DAC FM
; bit 8 DAC FM
; bit 9 DAC FM  
 
;    db1=DACAt,  LSB bit '8' DACAt  ;   
  Send_n_bits_nInform_0_If_Bits_are1  reg_byte0, ADDR_FM, 0x04
; send DAC FM coefs , bit '2' DAC FM
  Send_n_bits_nInform_0_If_Bits_are1  reg_byte1, ADDR_FM, 0x08
 ;  12 pulses 
 
ret
 
 
 
 
 SendModeBits: 
 ;   BitsOut reg_byte0 ,  BitsModul reg_byte1 ,  BitsLFO reg_byte2
 ;  24 bit data
 ; 8   no      LSB
 ; 4   no
 ; 2   no
 ;  1 Out 
 ;  8 +6dB
 ;  4 uV
 ;  2 mV
 ;  1 dBV
 
 ;   no LSB
 ;   no
 ;   PM ext
 ;  AM ext
;  FM ext
 ;  PM
;   AM
;   FM
 
 ;  10k LSB   reg_byte2  BitsLFO
 ;  3,4k
 ;  2,5k
 ;  1k
;   0,4k
;   0,3k
;   0,2k
;   0,05k 
 
  Send_n_bits_nInform_0_If_Bits_are1   reg_byte0, ADDR_MODE, 0x08
  Send_n_bits_nInform_0_If_Bits_are1   reg_byte1, ADDR_MODE, 0x08
  Send_n_bits_nInform_0_If_Bits_are1   reg_byte2, ADDR_MODE, 0x08
 
ret
 
 SendDAC_AM_VRefCoefs: ; DACVref reg_byte1, reg_byte0 ,  DACAM   reg_byte3,reg_byte2 
 
; for send 0  to the trigger AM/Vref  set 1   on the pin 34 and send SyncAM pulse 
;send DAC Vref 0...9 coefs , 1000= 0x03e8=0b 0000 0011 1110 1000 
 ; db1=DACVref ; 
 
;   bit 0 DAC VRef, reg_byte0,  LSB 
;   bit 1 DAC VRef  
;   bit 2 DAC VRef 
;   bit 3 DAC VRef
;   bit 4 DAC VRef 
;   bit 5 DAC VRef 
;   bit 6 DAC VRef  
;   bit 7 DAC VRef  
 
;   bit 8 DAC VRef reg_byte1, LSB
;   bit 9 DAC VRef 
 
 ;  bit 0 DAC AM , reg_byte2, LSB
 ;  bit 1 DAC AM
 ;  bit 2 DAC AM
 ;  bit 3 DAC AM
 ;  bit 4 DAC AM
 ;  bit 5 DAC AM
 ;  bit 6 DAC AM
 ;  bit 7 DAC AM
 
 ;  bit 8 DAC AM reg_byte3, LSB
 ;  bit 9 DAC AM
 
 
Send_n_bits_nInform_0_If_Bits_are1   reg_byte0, ADDR_AM_VREF, 0x08
Send_n_bits_nInform_0_If_Bits_are1   reg_byte1, ADDR_AM_VREF, 0x02
 
;send DAC AM coeffs 0...9
; send DAC Vref 0...9 coefs 
Send_n_bits_nInform_0_If_Bits_are1   reg_byte2, ADDR_AM_VREF, 0x08
Send_n_bits_nInform_0_If_Bits_are1   reg_byte3, ADDR_AM_VREF, 0x02
 
 ;  20 pulses StrobeSyncAM 
 
ret
 
 
 SendLFOBits: 
; LFObits  reg_byte0 ,  LFOenabled    reg_byte1
 
;     bit nE   reg_byte1 LFOenabled;  
 
;    bit '1' LFO reg_byte0 LFObits;  
;    bit '2' LFO
;    bit '4'   LFO
 
Send_n_bits_nInform_0_If_Bits_are1   reg_byte1, ADDR_LFO, 0x01
Send_n_bits_nInform_0_If_Bits_are1   reg_byte0, ADDR_LFO, 0x03
 
 
; SendMemWrPulse();
ret
 
 
 
 
 SendHFObits: 
; FMAtt reg_byte0 ,   OscCode  reg_byte1
 
;    FM Att 1/10     reg_byte0 ,LSB 
 
 ;     OSCSEL '1'   reg_byte1 ,LSB 
;      OSCSEL '2'
;      OSCSEL '4'
 ;     FilterBand
 ;     BandSel '1' 
;     BandSel '2'
;     BandSel '4'
 
 
 
Send_n_bits_nInform_0_If_Bits_are1   reg_byte0,  ADDR_HFO, 0x01
Send_n_bits_nInform_0_If_Bits_are1   reg_byte1, ADDR_HFO, 0x07
 
ret
 
; проверить на отсутствие ошибок для выбранной  схемы включения, улучшить макросы
Добавлено через 1 час 7 минут
Можно и SPI под nInform адаптировать , отправляя побайтно (MOSI на выход , MISO на ввод , отключать MOSI, когда прием ,SCK через мультиплексор адресов пропускать , инверсию инверторами с Z-состоянием адаптировать ), но тогда некоторые сообщения будут отправляться дольше (пустые биты отправлять первыми ) , кажется, в современных изделиях так и делают с адаптацией на платах под положительную логику еще в проекте . Для памяти программно реализовывать . Но это проблемнее , требует перепоектировки платы (см. схему с форума Мантрида и аналогичные ).
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
18.03.2020, 06:58  [ТС]
Assembler
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
.macro CheckFlagOneMask
 
mov r16, @0
andi r16, @1
cpi r16, 0x00    
brne @2
 
.endmacro 
 
 
 
CheckFlags1:
 
call LoadFlagsToRegisters
 
CheckFlagOneMask reg_data0, MASK_FLAG_PARSECODE_FM, LabelIfFlagParseCodeFM
CheckFlagOneMask reg_data0, MASK_FLAG_PARSECODE_AM, LabelIfFlagParseCodeAM
CheckFlagOneMask reg_data0, MASK_FLAG_PARSECODE_OUT, LabelIfFlagParseCodeOut
CheckFlagOneMask reg_data0, MASK_FLAG_PARSECODE_FREQ, LabelIfFlagParseCodeFreq
 
CheckFlagOneMask reg_data1, MASK_FLAG_INC_STEP, LabelIfFlagIncStep  ; 3 
CheckFlagOneMask reg_data1, MASK_FLAG_DEC_STEP, LabelIfFlagDecStep  
 
CheckFlagOneMask reg_data2, MASK_FLAG_TURN_OFF, LabelIfFlagTurnOffUnusedMode  
CheckFlagOneMask reg_data2, MASK_FLAG_DISP_ERROR, LabelIfFlagDisplError 
CheckFlagOneMask reg_data2, MASK_FLAG_DISP_FM, LabelIfFlagDisplayFM
CheckFlagOneMask reg_data2, MASK_FLAG_DISP_AM, LabelIfFlagDisplayAM
CheckFlagOneMask reg_data2, MASK_FLAG_DISP_OUT, LabelIfFlagDisplayOut
CheckFlagOneMask reg_data2, MASK_FLAG_DISP_FREQ, LabelIfFlagDisplayFreq
 
CheckFlagOneMask reg_data2, MASK_BLINK_OFF, LabelIfFlagBlinkOff ;4
CheckFlagOneMask reg_data2, MASK_FLAG_BLINK_CODE, LabelIfFlagBlinkCode 
 
 
CheckFlagOneMask reg_data3, MASK_FLAG_MODE, LabelIfFlagMode
CheckFlagOneMask reg_data3, MASK_FLAG_LFO, LabelIfFlagLFO
CheckFlagOneMask reg_data3, MASK_FLAG_FM_CODE, LabelIfFlagFMCode
CheckFlagOneMask reg_data3, MASK_FLAG_AM_CODE, LabelIfFlagAMCode
 
CheckFlagOneMask reg_data3, MASK_FLAG_ATT_CODE, LabelIfFlagAttCode ; 5
CheckFlagOneMask reg_data3, MASK_FLAG_HFO_CODE, LabelIfFlagHFOCode  
CheckFlagOneMask reg_data3, MASK_FLAG_DVDC_CODE, LabelIfFlagDVDCCode  
 
ret
 
;fixs arguments loading for subroutines  
LabelIfFlagParseCodeFM:
 
call ParseCodesFM ; 
call ParseCodesHFO ; 
jmp LabelPoint1
 
 
LabelIfFlagParseCodeAM:
call ParseCodesAM;
jmp LabelPoint1
 
LabelIfFlagParseCodeOut:
call ParseCodesAtt ;  
call ParseStaticCommands ; 
call ParseCodesOut ; 
 
jmp LabelPoint1
 
LabelIfFlagParseCodeFreq:
call ParseCodesDVDC ; 
call ParseCodesBand ; 
call ParseStaticCommands  
call CheckFMMax ;
jmp LabelPoint1
 
LabelIfFlagIncStep:
call IncStep 
jmp LabelPoint1
 
LabelIfFlagDecStep:
call DecStep 
jmp LabelPoint1 
 
LabelIfFlagTurnOffUnusedMode:
call TurnOffUnusedMode
jmp LabelPoint1                          
 
LabelIfFlagDisplError:
call DisplayErrorFM 
jmp LabelPoint1
  
 
 LabelIfFlagDisplayFM:
call DisplayFMValue 
jmp LabelPoint1
 
LabelIfFlagAMCode:
call DisplayAMValue
jmp LabelPoint1
 
LabelIfFlagDisplayOut:
caall  DisplayOutValue 
jmp LabelPoint1
 
LabelIfFlagDisplayFreq: 
call DisplayFreqValue
jmp LabelPoint1
 
LabelIfFlagBlinkOff:
call SendBlinkOff
jmp LabelPoint1 
 
 
LabelIfFlagBlinkCode:
call SendBlinkCode
jmp LabelPoint1 
 
LabelIfFlagMode:
call SendStaticCommands
jmp LabelPoint1 
 
 LabelIfFlagLFO:
 call SendLFOCodes
 jmp LabelPoint1 
 
LabelIfFlagFMCode:
call  SendFMCodes
 jmp LabelPoint1 
 
LabelIfFlagAMCode: 
 call SendAMCodes
 jmp LabelPoint1 
 
LabelIfFlagAttCode:
call SendAttCodes
 jmp LabelPoint1 
 
 LabelIfFlagHFOCode:
 call SendHFOCodes
 jmp LabelPoint1  
 
LabelIfFlagDVDCCode:
call  SendDVDCCodes
 jmp LabelPoint1 
 
 
 
 
 
 
 
 
 
 
 
 
; jump to this subroutine after main , init subs for loop forever if  no interrupts 
 
CheckDutyFlag:
LabelPoint1:
 
call GetDutyReg   ; data in r16 
cpi r16, 0x00  
brne  OnDutyRegNotZero  
  
call SendMemWrPulse; 
LabelNoInterrupts:
 
call LoadInterruptFlags ; int flags in r16
cpi r16, 0x00
breq  LabelNoInterrupts;  loop while no interrupts
jmp LabelPoint2
 
OnDutyRegNotZero:
call SetSelectedFlagZero
call CheckFlags1
jmp LabelPoint1
Добавлено через 3 минуты
В программе прерываний на флаг прерываний выделить 1 байт в ОЗУ , добавлять биты дизъюнкцией с 1 , сбрасывать конъюнкцией с 0

Добавлено через 16 минут
Assembler
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
LabelPoint2:
 
;   2     
call AnalyseInterrupt_InputData ;   fix
call GetByteIntFlags ; to r17 from RAM 
 
mov r16, r17
andi r16, INTERUPT3_BYTEMASK
cpi  r16, 0x00
brne  LabelPoint7 ; add decoder subroutines for GPIB
 
mov r16, r17
andi r16, INTERUPT2_BYTEMASK
cpi  r16, 0x00
brne  LabelPoint8 ;   add decoder subroutines ,    ParseKeyboard();
 
; if encoder event 
 
 
call SetSelectedFunctionParams ;  fix 
 
mov r16, r17
andi r16, FREQ_BYTEMASK
cpi  r16, 0x00
brne   NormalizeFreq  ; 12_1
 
mov r16, r17
andi r16, FM_BYTEMASK
cpi  r16, 0x00
brne   NormalizeFM  ; 13_1
 
mov r16, r17
andi r16, AM_BYTEMASK
cpi  r16, 0x00
brne   NormalizeAMCoef  ; 14_1
 
jmp NormalizeOutput1   ; 15_1
Добавлено через 55 минут
Assembler
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
 ;*********************
 
 
 
LabelPoint2:
 
;   2     
call AnalyseInterrupt_InputData ;
call GetByteIntFlags ; to r17
 
mov r16, r17
andi r16, INTERUPT3_BYTEMASK
cpi  r16, 0x00
brne  LabelPoint7 ; add decoder subroutines for GPIB
 
mov r16, r17
andi r16, INTERUPT2_BYTEMASK
cpi  r16, 0x00
brne  LabelPoint8 ;   add decoder subroutines ,    ParseKeyboard();
 
; if encoder event 
 
 
call SetSelectedFunctionParams ;  fix 
 
mov r16, r17
andi r16, FREQ_BYTEMASK
cpi  r16, 0x00
brne   NormalizeFreq  ; 12_1
 
mov r16, r17
andi r16, FM_BYTEMASK
cpi  r16, 0x00
brne   NormalizeFM  ; 13_1
 
mov r16, r17
andi r16, AM_BYTEMASK
cpi  r16, 0x00
brne   NormalizeAMCoef  ; 14_1
 
jmp NormalizeOutput1   ; 15_1
 
;***********************
 
CheckButtonNumericKeypad:
 
cpi r16, BUTTON_0
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_1
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_2
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_3
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_4
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_5
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_6
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_7
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_8
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_9
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_COMMA
breq  CaseBUTTON_NUMKEYPAD  
cpi r16, BUTTON_COMMA
breq  CaseBUTTON_SHARP
ret 
 
 
CaseBUTTON_NUMKEYPAD:
 
 CheckMemoryWriteModeOn     WriteStatement   ; macro
 CheckMemoryRecallModeOn    GetStatementFromMemory    ; macro 
; fix input subroutine registry
 call InputParamValue
 jmp LabelPoint1
 
 
;**************************
 
 
 
LabelPoint8:
 
 
;        8_1  
 
call GetScanCodeValue ; to r16
andi r16, BITMASK_KEYBOARD  ; gets keyboard scancodes  
 
call CheckButtonNumericKeypad
 
 
cpi r16, BUTTON_F
breq  CaseBUTTON_F  
 
cpi r16, BUTTON_FM
breq  CaseBUTTON_FM
 
cpi r16, BUTTON_AM
breq  CaseBUTTON_AM
 
cpi r16, BUTTON_PM
breq  CaseBUTTON_PM
 
cpi r16, BUTTON_MOD_OFF
breq  CaseBUTTON_MOD_OFF
 
cpi r16, BUTTON_EXT  ; 9
breq  CaseBUTTON_EXT
 
cpi r16, BUTTON_STEP
breq  CaseBUTTON_STEP
 
cpi r16, BUTTON_OUT
breq  CaseBUTTON_OUT
 
cpi r16, BUTTON_LFO
breq  CaseBUTTON_LFO
 
cpi r16, BUTTON_SHARP
breq  CaseBUTTON_SHARP
 
cpi r16, BUTTON_RECALL
breq  CaseBUTTON_RECALL
 
cpi r16, BUTTON_MHz
breq  CaseBUTTON_MHz
 
cpi r16, BUTTON_kHz
breq  CaseBUTTON_kHz
 
cpi r16, BUTTON_PERCENT
breq  CaseBUTTON_PERCENT
 
 
cpi r16, BUTTON_mV
breq  CaseBUTTON_mV
 
cpi r16, BUTTON_mkV
breq  CaseBUTTON_mkV
 
cpi r16, BUTTON_dBV
breq  CaseBUTTON_dBV
 
cpi r16, BUTTON_6dB
breq  CaseBUTTON_6dB
 
cpi r16, BUTTON_6dB
breq  CaseBUTTON_6dB
 
jmp CaseDefault
 
 
CaseBUTTON_F:  
                            ldi r16, TOKEN_F 
                            jmp SetDutyReg ;
CaseBUTTON_FM: 
                            call TurnOnFM ; 
                            ldi r16, TOKEN_FM
                            jmp  SetDutyReg ;
                          
Case BUTTON_AM:  
                              call  TurnOnAM ; 
                              ldi r16, TOKEN_AM     
                              jmp SetDutyReg ;
 
Case BUTTON_PM: 
                               call   TurnOnPM ; 
                                ldi r16, TOKEN_PM     
                                jmp SetDutyReg ;
Case BUTTON_MOD_OFF:
                              call TurnOffModulation ; 
                                ldi r16, TOKEN_MOD_OFF    
                                jmp SetDutyReg ;
 ;  9  
CaseBUTTON_EXT:  
                              call  PrepareExtModulation ; 
                              jmp LabelPoint1
CaseBUTTON_STEP:
                               call StepModeOn ;                               
                                jmp LabelPoint1
 
CaseBUTTON_OUT:  
                               call OutputOn ;   
                               ldi r16, TOKEN_OUT    
                                jmp SetDutyReg ;
 
CaseBUTTON_LFO:  
                              call ChangeLFOCode ;   
                              jmp LabelPoint1
CaseBUTTON_SHARP:
                             call SetMemWrMode ;  
                             jmp LabelPoint1
CaseBUTTON_RECALL:
                             call SetMemRecallMode ;   
                             jmp LabelPoint1
;  10   
CaseBUTTON_MHz:
                            jmp NormalizeFreq ;                               
                          
CaseBUTTON_kHz:
                           
                            CheckStepModeOn    NormalizeStep    , NormalizeFM ;  macro,  13_2 or to 1 
                         
CaseBUTTON_PERCENT:
                             jmp NormalizeAMCoef ;   14_2   
                           
CaseBUTTON_mV:
                            ldi r16, TOKEN_Out_mV 
                            jmp SetOutInputMode ;   15_2  
CaseBUTTON_uV:
                            ldi r16, TOKEN_Out_mkV 
                            jmp SetOutInputMode ;   15_2  
CaseBUTTON_dBV:
                             ldi r16, TOKEN_Out_dB 
                             jmp SetOutInputMode ;   15_2  
                              
;   11   
CaseBUTTON_6dB:
                               
                            CheckModeAM    TurnOn6dB  
                            jmp LabelPoint1
CaseDefault: 
                           
                            IsModeStep ChangeFreqOneStep ;     macro  12_3,   NormalizeFreq(); 
 
                            call  ChangeStepParam 
              
 jmp LabelPoint1
 
;****************************
Добавлено через 43 минуты
Assembler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; jump to this subroutine after main , init subs for loop forever if  no interrupts 
 
CheckDutyFlag:
LabelPoint1:
cli
call GetDutyReg   ; data into the r16 
cpi r16, 0x00  
brne  OnDutyRegNotZero  
  
call SendMemWrPulse;  fix 
sei
LabelNoInterrupts:
 
call LoadInterruptFlags ; int flags in r16
cpi r16, 0x00
breq  LabelNoInterrupts;  loop while no interrupts
cli
jmp LabelPoint2
 
OnDutyRegNotZero:
call SetSelectedFlagZero
call CheckFlags1
jmp LabelPoint1
в программе обработки прерываний все таки нужно использовать reti вместо jmp(rjmp) (возврат на следующую строку после той, где было вызвано прерывание, до входа в ожидание прерывания чувствительность к ним отключена с помощью cli ) , но loop forever как по инструкции, после прерывания , пока не обработается

Добавлено через 3 часа 58 минут
Желательно флаги , устанавливаемые по прерыванию помещать в РОН, а не в ОЗУ (еще дорабатывается), потом обрабатывать (по скорости ).

Добавлено через 9 минут
Делить на 5 можно разделив на 10(выборкой двоично-десятичных чисел сдвигом на 1 регистр цифры ) , потом сдвиг на 1 разряд влево (удвоив ), если "ограничение" не наступает , делить на 4 можно сдвигом (в каждом регистре 4-байтного или 2-байтного (тогда проще ) числа в двоичной форме ) вправо на 2 разряда .
Для надстроек над регистровой парой при инкрементировании и декрементировании учитывать переносы или для цифр организовать "цепочный" алгоритм вычисления с переносом и ограничением в соответствующие соседние регистры ,в которых хардово не используется продолжение как в регистровой паре (или учесть архитектуру для регистровых пар ) .
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 04:44  [ТС]
Assembler
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 
 
0.1-11.9999 MHz R47
12.0000-13.9999 MHz R48
14.0000-19.9999 MHz R42
20.0000-27.9999 MHz R43
28.0000-39.9999 MHz R44
40.0000-55.9999 MHz R45
56.0000-79.9999 MHz R46
80.0000-111.9999 MHz R47
112.0000-159.9999 MHz R48
 
160.000-223.999 MHz R49
224.000-319.999 MHz R50
320.000-447.999 MHz R51
448.000-639.999 MHz R52
 
Аппроксимации АЧХ диапазонных полосовых фильтров обычно близкие к аппроксимациям Баттерворта и Чебышева (иногда Кауэра или эмпирическая ) с малой амплитудой осцилляции (до 0,3...0,4 дБ ) в полосе пропускания .
Генераторы после 320 МГц переключаются через 40 МГц (номера в инструкции) с помощью КПЧК - кодов :
 
320,000-359,999 МГц
360,000-399,999 МГц
400,000-439,999 МГц
440,000-479,999 МГц
480,000-519,999 МГц
520,000-559,999 МГц
560,000-599,999 МГц
600,000-639,999 МГц
 
 
 
 
 
 
*/
 
uint32_t GetCoeffDPKD(uint32_t freq, uint8_t *band )
{
 //uint8_t Kdp;
 //uint8_t Kdpkd_div ;
uint32_t Kddpkd;
//Kddpkd_num= freq*Kd/5)  for f= 1.25 kHz
//Kddpkd_num=freq*Kd/4  for f=1 kHz
  
   //3200000- 6399990
 case 4480000 ... 6399990:           
                                                                  // Kdp=1   , fit to f*10 
                                               //R52 , fcomp=1.25kHz 
 
                                        //Kdp =1;   
                                        //Kdpkd_div=5;  
                                        Kddpkd=  freq/5;         ((uint32_t)(freq_fromdigits_div10  )     <<1);  
                                       //subband high       
                                    break; 
         
 case 3200000 ... 4479990:                  // Kdp=1  , fit to f*10 
                                                            //R51, fcomp=1.25kHz
                                    //Kdp =1; 
                                    //Kdpkd_div=5;  
                                     Kddpkd=  freq/5;   ((uint32_t)(freq_fromdigits_div10  )     <<1);         
                                        //subband low        
                                     break; 
                                              
 case 2240000 ... 3199990:              
                                             // Kdp=2  
                                          //R50, fcomp=1.25kHz
                                      // Kdp=2; 
                                      //Kdpkd_div=5;    
                                      Kddpkd=  (freq*2 /5);  ((uint32_t)(freq_fromdigits_div10  )    <<2);      //check for uint32_t compatibility without clipping 
                                    //subband high        
                                      break; 
 
 case 1600000 ... 2239990:               // Kdp=2      , fit to f*10 
                                               //R49, fcomp=1.25kHz
                                       //Kdp=2; 
                                       //Kdpkd_div=5;  
                                       Kddpkd=  (freq*2 /5);   ((uint32_t)(freq_fromdigits_div10  )    <<2);            //check for uint32_t compatibility without clipping 
                                    //subband low        
                                  break; 
 
 case 1120000 ... 1599999:             // Kdp=4      , fit to f  
                                              //R48, fcomp=1 kHz
 
                                      //Kdp=4;
                                      //Kdpkd_div=4;  
                                      Kddpkd=  freq ;    ((uint32_t)(freq_fromdigits  )  );  
                                    //subband high         
                                    break; 
 
 case  800000 ... 1119999 :             // Kdp=4   
                                            //R47, fcomp=1 kHz
                                      //Kdp=4; 
                                     //Kdpkd_div=4;  
                                       Kddpkd=  freq ;  ((freq_fromdigits  )  );  
                                        //subband low        
                                      break; 
 
 case 560000 ... 799999:             // Kdp=8   
                                             //R46, fcomp=1 kHz
                                      //Kdp=8;  
                                      //Kdpkd_div=4;  
                                       Kddpkd=  freq*2 ;     ((freq_fromdigits  )    <<1);  
                                     //subband high      
                                      break; 
 
 case 400000 ... 559999:             // Kdp=8   
                                             //R45, fcomp=1 kHz
                                      //Kdp=8; 
                                      //Kdpkd_div=4;  
                                      Kddpkd=  freq*2 ;  ((freq_fromdigits  ) <<1 );  
                                         //subband low 
                                      break; 
 
 case 280000 ... 399999:                         // Kdp=16   
                                            //R44  , fcomp=1 kHz
 
                                     //Kdp=16; 
                                     //Kdpkd_div=4;  
                                     Kddpkd=  freq*4 ;  ((freq_fromdigits  ) <<2 );  
                                       //subband high       
                                      break; 
 
 
 case 200000 ... 279999:                         // Kdp=16   
                                            //R43  , fcomp=1 kHz
                                      //Kdp=16;
                                     //Kdpkd_div=4;  
                                     Kddpkd=  freq*4 ; ((freq_fromdigits  ) <<2 );  
                                    //subband low 
                                      break; 
 
 case 140000 ... 199999:                         // Kdp=32 
                                            //R42  , fcomp=1 kHz
                                     //Kdp=32; 
                                     //Kdpkd_div=4;  
                                     Kddpkd=  freq*8 ;  ((freq_fromdigits  ) <<3 );  
                                      //subband high  , check , fix  in asm edition   
                                      break; 
/********************************** mixer on  *******************************/
 
 case 120000 ... 139999:  
 
                                     freq+=1000000;
                                                                    // Kdp=4 
                                       //R48  , fcomp=1 kHz
                                          //Kdp=4;   
                                      //Kdpkd_div=4;  
                                     Kddpkd=  freq ;   ((freq_fromdigits  )  );  
                                      //subband high 
                                      break; 
 
 case  1000...119999:       
 
                                     freq+=1000000;
                                                            // Kdp=4 
                                         //R47  , fcomp=1000  Hz
                                          //Kdp=4;  
                                          //Kdpkd_div=4; 
                                       Kddpkd=  freq ;  ((freq_fromdigits  )  );  
                                     //subband low 
                                      break; 
 
//call subroutine for transforming uint32_t Kddpkd to digits for DVCD   , MSB with  two digits in one (8421), oter  with 2421  
 
}
 
//add subroutines and variables for sending Kdp of the dividers and  numbers of the  filters, band, KattFM flags, MixOn flag , //FcompPLL= 1kHz flag or optimize types and subroutines 
//  
return  Kddpkd;
 
}
 
 
 
/*
 
K=4fcomp/Kdp
 
 
f=639 999  000  Hz 
fcomp=
639 999 0 00  * 1/4=159 999 750
 
Kddpkd=159 999 750/1250=127999, 8
цифры  для отправки 
 
Kddpkd_num=f(Hz)*Kdp*10/(4*fcomp(Hz)) ;
159 999 750/125=  [12][7][9][9][9][8]
 
10/4*1000=1/400
10/4*1250=1/500
 
Kddpkd_num=f(Hz) /500 for f= 1.25 kHz
Kddpkd_num=f(Hz) /400 for f=1 kHz
 
У нас число частоты,выраженной в герцах     поделено на 100 ,
поэтому 
Kddpkd_num=freq/5  for f= 1.25 kHz
Kddpkd_num=freq/4  for f=1 kHz
 
639 999 0 /5 =1 279 998 ->  байты  (MSB) [1 2][7][9] [9][9][8] (LSB)
 
 
160 000 0  *2 /5 =640 000->  байты  (MSB) [0][6][4] [0][0][0] (LSB)
159 999 9 *4/4=159 999 9->  байты  (MSB) [15][9][9] [9][9][9] (LSB)  
 
12 000 000 Hz->
freq=12 000 0   ->freq =112 000 0 , fcomp=1kHz  , Kdp=4 , MixOn
 
  Kddpkd_num=freq/4   = 112 000 0 *4/ 4  =112 000 0->  байты  (MSB) [11][2][0] [0][0][0] (LSB)
*/
Добавлено через 11 минут
Пробная программа деления на 5 для АТМЕГА16А, вызывающая проблему с тактовой частотой , от которой можно избавиться , как сказано выше, если обрабатывать данные о цифрах в альтернативной подпрограмме со сдвигом на один регистр (на ассемблере, иначе выбрать ), в отличие от условий , для которых это вычисляют поледовательно по цифрам
и признакам с учетом положения запятой (для программы условно переводят в четырехбайтный двоичный код на суммировании с весовыми числами по маске разряда )


C++
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
/*
 * Gccapp1.c
 *
 * Created: 20.03.2020 02:09:14
 * Author : USERPC01
 */ 
 
#include <avr/io.h>
#include <math.h>
uint32_t mul2(uint32_t data)
{
return ( data<<1)  ;    
    
    
}
uint32_t div5(uint32_t data )
{
return data/5   ;
    
 
}
 
uint32_t div10(uint32_t data )
{
    return data/10  ;
    
 
}
 
int main(void)
{
    uint32_t data=6399990;
    data+=(uint32_t ) PIND;
     
    
    
        uint32_t  data1= div5(data );
    
    
      
    //data2=mul4(  data2)  ;
    
    
    
    /* Replace with your application code */
    while (1) 
    {
        uint8_t data2 =mul2( data1);
    
         PORTD=(uint8_t)data2&0xff;
        
        
    }
}
Добавлено через 2 минуты
Code
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
Gccapp1.lss
 
 
 
Gccapp1.elf:     file format elf32-avr
 
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000017c  00000000  00000000  00000054  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00800060  00800060  000001d0  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .comment      00000030  00000000  00000000  000001d0  2**0
                  CONTENTS, READONLY
  3 .note.gnu.avr.deviceinfo 0000003c  00000000  00000000  00000200  2**2
                  CONTENTS, READONLY
  4 .debug_aranges 00000038  00000000  00000000  0000023c  2**0
                  CONTENTS, READONLY, DEBUGGING
  5 .debug_info   0000069b  00000000  00000000  00000274  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_abbrev 000005dc  00000000  00000000  0000090f  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_line   0000021a  00000000  00000000  00000eeb  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_frame  00000084  00000000  00000000  00001108  2**2
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_str    00000310  00000000  00000000  0000118c  2**0
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_loc    00000150  00000000  00000000  0000149c  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_ranges 00000028  00000000  00000000  000015ec  2**0
                  CONTENTS, READONLY, DEBUGGING
 
Disassembly of section .text:
 
00000000 <__vectors>:
   0:   0c 94 2a 00     jmp 0x54    ; 0x54 <__ctors_end>
   4:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
   8:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
   c:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  10:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  14:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  18:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  1c:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  20:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  24:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  28:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  2c:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  30:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  34:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  38:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  3c:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  40:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  44:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  48:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  4c:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
  50:   0c 94 34 00     jmp 0x68    ; 0x68 <__bad_interrupt>
 
00000054 <__ctors_end>:
  54:   11 24           eor r1, r1
  56:   1f be           out 0x3f, r1    ; 63
  58:   cf e5           ldi r28, 0x5F   ; 95
  5a:   d4 e0           ldi r29, 0x04   ; 4
  5c:   de bf           out 0x3e, r29   ; 62
  5e:   cd bf           out 0x3d, r28   ; 61
  60:   0e 94 36 00     call    0x6c    ; 0x6c <main>
  64:   0c 94 bc 00     jmp 0x178   ; 0x178 <_exit>
 
00000068 <__bad_interrupt>:
  68:   0c 94 00 00     jmp 0   ; 0x0 <__vectors>
 
0000006c <main>:
}
 
int main(void)
{
    uint32_t data=6399990;
    data+=(uint32_t ) PIND;
  6c:   60 b3           in  r22, 0x10   ; 16
    
    
    /* Replace with your application code */
    while (1) 
    {
        uint8_t data2 =mul2( data1);
  6e:   86 2f           mov r24, r22
  70:   90 e0           ldi r25, 0x00   ; 0
  72:   a0 e0           ldi r26, 0x00   ; 0
  74:   b0 e0           ldi r27, 0x00   ; 0
  76:   bc 01           movw    r22, r24
  78:   cd 01           movw    r24, r26
  7a:   6a 50           subi    r22, 0x0A   ; 10
  7c:   78 45           sbci    r23, 0x58   ; 88
  7e:   8e 49           sbci    r24, 0x9E   ; 158
  80:   9f 4f           sbci    r25, 0xFF   ; 255
  82:   2d ec           ldi r18, 0xCD   ; 205
  84:   3c ec           ldi r19, 0xCC   ; 204
  86:   4c ec           ldi r20, 0xCC   ; 204
  88:   5c ec           ldi r21, 0xCC   ; 204
  8a:   0e 94 5b 00     call    0xb6    ; 0xb6 <__umulsidi3>
  8e:   00 e2           ldi r16, 0x20   ; 32
  90:   0e 94 88 00     call    0x110   ; 0x110 <__lshrdi3>
  94:   82 2e           mov r8, r18
  96:   93 2e           mov r9, r19
  98:   a4 2e           mov r10, r20
  9a:   b5 2e           mov r11, r21
  9c:   d5 01           movw    r26, r10
  9e:   c4 01           movw    r24, r8
  a0:   b6 95           lsr r27
  a2:   a7 95           ror r26
  a4:   97 95           ror r25
  a6:   87 95           ror r24
  a8:   b6 95           lsr r27
  aa:   a7 95           ror r26
  ac:   97 95           ror r25
  ae:   87 95           ror r24
  b0:   88 0f           add r24, r24
    
         PORTD=(uint8_t)data2&0xff;
  b2:   82 bb           out 0x12, r24   ; 18
  b4:   fe cf           rjmp    .-4         ; 0xb2 <main+0x46>
 
000000b6 <__umulsidi3>:
  b6:   e8 94           clt
 
000000b8 <__umulsidi3_helper>:
  b8:   df 93           push    r29
  ba:   cf 93           push    r28
  bc:   fc 01           movw    r30, r24
  be:   db 01           movw    r26, r22
  c0:   0e 94 a4 00     call    0x148   ; 0x148 <__umulhisi3>
  c4:   7f 93           push    r23
  c6:   6f 93           push    r22
  c8:   e9 01           movw    r28, r18
  ca:   9a 01           movw    r18, r20
  cc:   ac 01           movw    r20, r24
  ce:   bf 93           push    r27
  d0:   af 93           push    r26
  d2:   3f 93           push    r19
  d4:   2f 93           push    r18
  d6:   df 01           movw    r26, r30
  d8:   0e 94 a4 00     call    0x148   ; 0x148 <__umulhisi3>
  dc:   26 f4           brtc    .+8         ; 0xe6 <__umulsidi3_helper+0x2e>
  de:   6c 1b           sub r22, r28
  e0:   7d 0b           sbc r23, r29
  e2:   82 0b           sbc r24, r18
  e4:   93 0b           sbc r25, r19
  e6:   9e 01           movw    r18, r28
  e8:   eb 01           movw    r28, r22
  ea:   fc 01           movw    r30, r24
  ec:   0e 94 b3 00     call    0x166   ; 0x166 <__muldi3_6>
  f0:   af 91           pop r26
  f2:   bf 91           pop r27
  f4:   2f 91           pop r18
  f6:   3f 91           pop r19
  f8:   0e 94 b3 00     call    0x166   ; 0x166 <__muldi3_6>
  fc:   be 01           movw    r22, r28
  fe:   cf 01           movw    r24, r30
 100:   f9 01           movw    r30, r18
 102:   2f 91           pop r18
 104:   3f 91           pop r19
 106:   cf 91           pop r28
 108:   df 91           pop r29
 10a:   08 95           ret
 
0000010c <__ashrdi3>:
 10c:   97 fb           bst r25, 7
 10e:   10 f8           bld r1, 0
 
00000110 <__lshrdi3>:
 110:   16 94           lsr r1
 112:   00 08           sbc r0, r0
 114:   0f 93           push    r16
 116:   08 30           cpi r16, 0x08   ; 8
 118:   98 f0           brcs    .+38        ; 0x140 <__lshrdi3+0x30>
 11a:   08 50           subi    r16, 0x08   ; 8
 11c:   23 2f           mov r18, r19
 11e:   34 2f           mov r19, r20
 120:   45 2f           mov r20, r21
 122:   56 2f           mov r21, r22
 124:   67 2f           mov r22, r23
 126:   78 2f           mov r23, r24
 128:   89 2f           mov r24, r25
 12a:   90 2d           mov r25, r0
 12c:   f4 cf           rjmp    .-24        ; 0x116 <__lshrdi3+0x6>
 12e:   05 94           asr r0
 130:   97 95           ror r25
 132:   87 95           ror r24
 134:   77 95           ror r23
 136:   67 95           ror r22
 138:   57 95           ror r21
 13a:   47 95           ror r20
 13c:   37 95           ror r19
 13e:   27 95           ror r18
 140:   0a 95           dec r16
 142:   aa f7           brpl    .-22        ; 0x12e <__lshrdi3+0x1e>
 144:   0f 91           pop r16
 146:   08 95           ret
 
00000148 <__umulhisi3>:
 148:   a2 9f           mul r26, r18
 14a:   b0 01           movw    r22, r0
 14c:   b3 9f           mul r27, r19
 14e:   c0 01           movw    r24, r0
 150:   a3 9f           mul r26, r19
 152:   70 0d           add r23, r0
 154:   81 1d           adc r24, r1
 156:   11 24           eor r1, r1
 158:   91 1d           adc r25, r1
 15a:   b2 9f           mul r27, r18
 15c:   70 0d           add r23, r0
 15e:   81 1d           adc r24, r1
 160:   11 24           eor r1, r1
 162:   91 1d           adc r25, r1
 164:   08 95           ret
 
00000166 <__muldi3_6>:
 166:   0e 94 a4 00     call    0x148   ; 0x148 <__umulhisi3>
 16a:   46 0f           add r20, r22
 16c:   57 1f           adc r21, r23
 16e:   c8 1f           adc r28, r24
 170:   d9 1f           adc r29, r25
 172:   08 f4           brcc    .+2         ; 0x176 <__muldi3_6+0x10>
 174:   31 96           adiw    r30, 0x01   ; 1
 176:   08 95           ret
 
00000178 <_exit>:
 178:   f8 94           cli
 
0000017a <__stop_program>:
 17a:   ff cf           rjmp    .-2         ; 0x17a <__stop_program>
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 11:33  [ТС]
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
uint32_t freq_fromdigits_div10( uint8_t freq[7])
{
uint32 result=0;
result+= freq[1];
result+= (freq[2]<<4);
result+= (freq[3]<<8);
result+= (freq[4]<<12); 
result+= (freq[5]<<16); 
result+= (freq[6]<<20); 
}
 
 
uint32_t freq_fromdigits_div( uint8_t freq[7])
{
uint32 result=0;
result+= freq[0];
result+= (freq[1]<<4);
result+= (freq[2]<<8);
result+= (freq[3]<<12); 
result+= (freq[4]<<16); 
result+= (freq[5]<<20); 
result+= (freq[6]<<24); 
 
}
 
 
 
 
uint8_t * GetCoeffDPKD(uint8_t freq[7] ,  uint8_t *compfreq)
{
 //uint8_t Kdp;
 //uint8_t Kdpkd_div ;
 
//Kddpkd_num= freq*Kd/5)  for f= 1.25 kHz
//Kddpkd_num=freq*Kd/4  for f=1 kHz
  
   //3200000- 6399990
 
if (freq[6]>=4){
if (freq[5]>=4){
if (freq[4]>=8){ /*
if (freq[3]>=0){  
if (freq[2]>=0){
if (freq[1]>=0){ */
 
if (freq[6]<=6){
if (freq[5]<=3){
if (freq[4]<=9){ /*
if (freq[3]<=9){ 
if (freq[2]<=9){
if (freq[1]<=9){ */
 
  freq[0]=0;
       
                                         // Kdp=1   , fit to f*10 
                                         //R52 , fcomp=1.25kHz 
 
                                        //Kdp =1;   
                                        //Kdpkd_div=5;  
                                        //Kddpkd=  freq/5;         ((uint32_t)(freq_fromdigits_div10  )     <<1);  
                                        //subband high 
                                          //   subband=SUBBAND_HIGH   ; 
                                            
                                             *compfreq=FREQ1_25kHz                                   
                                             KDVDC=  ((uint32_t)(freq_fromdigits_div10(freq)  ) <<1);          
   return  DVDC_DIGITS(KDVDC);
}}}  /*     }}}  */
 
 if (freq[6]>=3){
if (freq[5]>=2){
if (freq[4]>=0){ /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){ */
 
if (freq[6]<=4){
if (freq[5]<=4){
if (freq[4]<=7){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9){ */
 
    freq[0]=0;
 
                                    // Kdp=1  , fit to f*10 
                                    //R51, fcomp=1.25kHz
                                    //Kdp =1; 
                                    //Kdpkd_div=5;  
                                     //Kddpkd=  freq/5;   ((uint32_t)(freq_fromdigits_div10  )     <<1);         
                                        //subband low   
 
                                            //subband=SUBBAND_LOW   ;   
                                             *compfreq=FREQ1_25kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits_div10(freq)  ) <<1);   
    return  DVDC_DIGITS(KDVDC);
}}} /* }}}   */
          
  
                                              
if (freq[6]>=2){
if (freq[5]>=2){
if (freq[4]>=4){
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
 
if (freq[6]<=3){
if (freq[5]<=1){
if (freq[4]<=9){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9){ */
 
   freq[0]=0;
                                          // Kdp=2  
                                          //R50, fcomp=1.25kHz
                                      // Kdp=2; 
                                      //Kdpkd_div=5;    
                                     //    Kddpkd=  (freq*2 /5);  ((uint32_t)(freq_fromdigits_div10  )    <<2);      //check for uint32_t compatibility without clipping 
                                    //subband high  
                                       //subband=SUBBAND_HIGH   ;   
                                             *compfreq=FREQ1_25kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits_div10(freq)  ) <<2);   
   return  DVDC_DIGITS(KDVDC);
}}} /* }}}  */
 
                                              
if (freq[6]>=1){
if (freq[5]>=6){
if (freq[4]>=0){ /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){ */
 
if (freq[6]<=2){
if (freq[5]<=2){
if (freq[4]<=3){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9){   /*                                         
   freq[0]=0; 
                                     // Kdp=2      , fit to f*10 
                                      //R49, fcomp=1.25kHz
                                       //Kdp=2; 
                                       //Kdpkd_div=5;  
                                       //Kddpkd=  (freq*2 /5);   ((uint32_t)(freq_fromdigits_div10  )    <<2);            //check for uint32_t compatibility without clipping 
                                       //subband low      
                                       //subband=SUBBAND_LOW   ;   
                                             *compfreq=FREQ1_25kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits_div10(freq)  ) <<2);   
 
   return  DVDC_DIGITS(KDVDC);
 
}}}/* }}}*/
 
if (freq[6]>=1){ 
if (freq[5]>=1){
if (freq[4]>=2){ /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){  */
 
if (freq[6]<=1){
if (freq[5]<=5){
if (freq[4]<=9){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9) { 
if (freq[0]<=9) { */
                                      // Kdp=4      , fit to f  
                                              //R48, fcomp=1 kHz
 
                                      //Kdp=4;
                                      //Kdpkd_div=4;  
                                      //Kddpkd=  freq ;    ((uint32_t)(freq_fromdigits  )  );  
                                    //subband high  
                                            //subband=SUBBAND_HIGH   ;       
                                              *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  )  );         
               return  DVDC_DIGITS(KDVDC);                       
 }}}/* }}}}*/
 
if (freq[6]>=0){
if (freq[5]>=8){
if (freq[4]>=0){  /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){  */
 
if (freq[6]<=1){
if (freq[5]<=1){
if (freq[4]<=1){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9) {
if (freq[0]<=9) { */
 
 
 
 
                                     // Kdp=4   
                                            //R47, fcomp=1 kHz
                                      //Kdp=4; 
                                     //Kdpkd_div=4;  
                                       //Kddpkd=  freq ;  ((freq_fromdigits  )  );  
                                           //subband low  
                                            //subband=SUBBAND_LOW   ;       
                                              *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  )  );         
                     return  DVDC_DIGITS(KDVDC);                        
                                       
 }}}/* }}}}*/
 
 
 
 
if (freq[6]>=0){
if (freq[5]>=5){
if (freq[4]>=6){  /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){  */
 
if (freq[6]<=0){
if (freq[5]<=7){
if (freq[4]<=9){ /*
if (freq[3]<=9){ 
if (freq[2]<=9){
if (freq[1]<=9) {
if (freq[0]<=9) { */
 
                                          // Kdp=8   
                                             //R46, fcomp=1 kHz
                                      //Kdp=8;  
                                      //Kdpkd_div=4;  
                                   //    Kddpkd=  freq*2 ;     ((freq_fromdigits  )    <<1);  
                                     //subband high  
                                       //subband=SUBBAND_HIGH  ;       
                                              *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  <<1)  );   
       return  DVDC_DIGITS(KDVDC);
}}} /* }}}} */
 
 
if (freq[6]>=0){
if (freq[5]>=4){
if (freq[4]>=0){ /*
if (freq[3]>=0){  
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){ */
 
if (freq[6]<=0){
if (freq[5]<=5){
if (freq[4]<=5){ /*
if (freq[3]<=9){  
if (freq[2]<=9){
if (freq[1]<=9) {
if (freq[0]<=9) { */
                                   // Kdp=8   
                                             //R45, fcomp=1 kHz
                                      //Kdp=8; 
                                      //Kdpkd_div=4;  
                                      //Kddpkd=  freq*2 ;  ((freq_fromdigits  ) <<1 );  
                                         //subband low 
 
                                        //subband=SUBBAND_LOW  ;       
                                              *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  <<1)  );   
   return  DVDC_DIGITS(KDVDC);
}}} /* }}}} */
 
if (freq[6]>=0){
if (freq[5]>=2){
if (freq[4]>=8){ /*
if (freq[3]>=0){ 
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){ */
 
if (freq[6]<=0){
if (freq[5]<=3){
if (freq[4]<=9){ /*
if (freq[3]<=9){  
if (freq[2]<=9){
if (freq[1]<=9){
if (freq[0]<=9){ */
 
                                        // Kdp=16   
                                            //R44  , fcomp=1 kHz
 
                                     //Kdp=16; 
                                     //Kdpkd_div=4;  
                                     //Kddpkd=  freq*4 ;  ((freq_fromdigits  ) <<2 );  
                                       //subband high      
                                        //subband=SUBBAND_HIGH  ;
                                             *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  <<2)  );   
   return  DVDC_DIGITS(KDVDC);
 
   }}} /*}}}}  */
 
 
if (freq[6]>=0){
if (freq[5]>=2){
if (freq[4]>=0){ /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){ */
 
if (freq[6]<=0){
if (freq[5]<=2){
if (freq[4]<=7){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9){
if (freq[0]<=9){ */
 
 
                          // Kdp=16   
                                            //R43  , fcomp=1 kHz
                                      //Kdp=16;
                                     //Kdpkd_div=4;  
                                   //  Kddpkd=  freq*4 ; ((freq_fromdigits  ) <<2 );  
                                    //subband low 
                                     
                                          //subband=SUBBAND_LOW  ;
                                             *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  <<2)  );   
   return  DVDC_DIGITS(KDVDC);
 
}}} /* }}}} */
 
 
if (freq[6]>=0){
if (freq[5]>=1){
if (freq[4]>=4){ /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){ */
 
if (freq[6]<=0){
if (freq[5]<=1){
if (freq[4]<=9){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9){
if (freq[0]<=9){ */
 
                        // Kdp=32 
                                            //R42  , fcomp=1 kHz
                                     //Kdp=32; 
                                     //Kdpkd_div=4;  
                                     //Kddpkd=  freq*8 ;  ((freq_fromdigits  ) <<3 );  
                                      //subband high  , check , fix  in asm edition   
                                     //subband=SUBBAND_HIGH  ;
                                            *compfreq=FREQ1kHz                                       
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq)  <<3)  ); 
                                    return  DVDC_DIGITS(KDVDC);
}}}  /* }}}} */
 
/********************************** mixer on  *******************************/
 
if (freq[6]>=0){
if (freq[5]>=1){
if (freq[4]>=2){ /*
if (freq[3]>=0){
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){ */
 
if (freq[6]<=0){
if (freq[5]<=1){
if (freq[4]<=3){ /*
if (freq[3]<=9){
if (freq[2]<=9){
if (freq[1]<=9){
if (freq[0]<=9){ */
 
 
                               //      freq+=1000000;
                                                                    // Kdp=4 
                                       //R48  , fcomp=1 kHz
                                          //Kdp=4;   
                                      //Kdpkd_div=4;  
                                     //Kddpkd=  freq ;   ((freq_fromdigits  )  );  
                                      //subband high 
                                              //subband=SUBBAND_HIGH  ;
                                             *compfreq=FREQ1kHz   
                                            freq1[0]=freq[0];       
                                              freq1[1]=freq[1];
                                                freq1[2]=freq[2];
                                                  freq1[3]=freq[3];
                                                freq1[4]=freq[4];
                                                  freq1[5]=freq[5];
                                                  freq1[6]=0x01;
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq1  )  )  ); 
                                               return  DVDC_DIGITS(KDVDC);
}}} /* }}}}   */
 
if (freq[6]>=0){
if (freq[5]>=0){
if (freq[4]>=0){  
if (freq[3]>=1){  /*
if (freq[2]>=0){
if (freq[1]>=0){
if (freq[0]>=0){ */
 
if (freq[6]<=0){
if (freq[5]<=1){
if (freq[4]<=1){  
if (freq[3]<=9){  /*
if (freq[2]<=9){
if (freq[1]<=9){
if (freq[0]<=9){ */
 
  
 
                                     //freq+=1000000;
                                                            // Kdp=4 
                                         //R47  , fcomp=1000  Hz
                                          //Kdp=4;  
                                          //Kdpkd_div=4; 
                                      // Kddpkd=  freq ;  ((freq_fromdigits  )  );  
                                     //subband low 
                                           //subband=SUBBAND_LOW ;
                                             *compfreq=FREQ1kHz   
                                            freq1[0]=freq[0];       
                                              freq1[1]=freq[1];
                                                freq1[2]=freq[2];
                                                  freq1[3]=freq[3];
                                                freq1[4]=freq[4];
                                                  freq1[5]=freq[5];
                                                  freq1[6]=0x01;
                                             KDVDC=  ((uint32_t)(freq_fromdigits (freq1  )  )  );  
                     return  DVDC_DIGITS(KDVDC);
 }}}} /*}}}*/
 
 
 
}
Добавлено через 1 час 58 минут
Все таки нужно сравнивать в виде uint32_t (проблема с 6-м байтом и далее ).

Воспользоваться
C++
1
freq_fromdigits_div( uint8_t freq[7])
и записывать как для длинного 32-битного беззнакового числа интервально (в начале с ветвлением )

Добавлено через 54 минуты
C++
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
...
 
uint32_t freqvalue;
freqvalue= freq_fromdigits ( freq );
 
 
 
//600.000 -639.999
 
switch(freqvalue)
{
 
case 6000000...6399990:
 
       *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G4_SUBBAND_R52_HIGH;
       break;
 
case 5600000...5999990:
 
      *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G3_SUBBAND_R52_HIGH;
      break;
 
 
 
case 5200000...5599990:
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G8_SUBBAND_R52_HIGH ;
break;
 
case  4800000...5199990:
 
     
     *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G7_SUBBAND_R52_HIGH ;
break;
 
 
case  4480000...4799990 :  //   high,    448-479.999
 
       *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G6_SUBBAND_R52_HIGH;
break; 
 
 
case   4400000...4479990: //  low,    440-447.999
 
 
      *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G6_SUBBAND_R51_LOW;
break; 
 
 
 
 
case   4000000...4399990: //  low,    400-439.999
 
      
       *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G5_SUBBAND_R51_LOW;
break; 
 
 
 
case   3600000...3999990: //  low,    
     *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G2_SUBBAND_R51_LOW;
break; 
 
 
 
case   3200000...3599990: // low,    
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= OSC_G1_SUBBAND_R51_LOW;
break; 
 
...
далее для других коэффициентов деления и поддиапазонов 
}
 
/* *************************  */
Проблема 8-битности по скорости возникнет при выполнении многократно этой подпрограммы сравнения для большего количества условий

Добавлено через 1 минуту
C++
1
2
3
4
5
6
7
8
9
10
uint32_t freq_fromdigits ( uint8_t freq[7])
{
uint32 result=0;
result+= freq[0];
result+= (freq[1]<<4);
result+= (freq[2]<<8);
result+= (freq[3]<<12); 
result+= (freq[4]<<16); 
result+= (freq[5]<<20); 
result+= (freq[6]<<24);
Добавлено через 15 секунд

Добавлено через 1 час 48 минут
Code
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
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
0<<HFO_HL верхний дешифратор  (1<<HFO_HL  для nInform)
 
1<<HFO_HL нижний дешифратор  (0<<HFO_HL  для nInform)
*/
Добавлено через 36 минут
Проверить инверсию и верхний/нижний диапазоны
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 13:21  [ТС]
Code
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
 
 
 
#define  HFO_FM0_1 0
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
 
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42)
Добавлено через 10 минут
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
// 1kHz pin   low 1kHz (set nInform  low), high  1.25 kHz    (set nInform  high)
#define FREQ1kHz  0x00         //check for circuit 
#define FREQ1_25kHz  0x01
 
#define  HFO_FM0_1 0   //fix for sender 
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
//rule for  inverse Inform code  , for  nInform pin
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42) 
 
 
 
 
 
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
uint32 result=0;
result+= freq[0];
result+= (freq[1]<<4);
result+= (freq[2]<<8);
result+= (freq[3]<<12); 
result+= (freq[4]<<16); 
result+= (freq[5]<<20); 
result+= (freq[6]<<24); 
 
}
 
 
 
 
 
 
 
 
 
 
void  GetOSCNum(uint8_t freq[7] , uint8_t *compfreq, uint8_t *oscnum )
{
 
uint32_t freqvalue;
freqvalue= freq_fromdigits ( freq );
 
 
 
//600.000 -639.999
 
switch(freqvalue)
{
 
case 6000000...6399990:
 
       *compfreq=FREQ1_25kHz    
        *oscnum=nOSC_G4_SUBBAND_R52_HIGH;
       break;
 
case 5600000...5999990:
 
      *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G3_SUBBAND_R52_HIGH;
      break;
 
 
 
case 5200000...5599990:
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G8_SUBBAND_R52_HIGH ;
break;
 
case  4800000...5199990:
 
     
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G7_SUBBAND_R52_HIGH ;
break;
 
 
case  4480000...4799990 :  //   high,    448-479.999
 
       *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G6_SUBBAND_R52_HIGH;
break; 
 
 
case   4400000...4479990: //  low,    440-447.999
 
 
      *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G6_SUBBAND_R51_LOW;
break; 
 
 
 
 
case   4000000...4399990: //  low,    400-439.999
 
      
       *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G5_SUBBAND_R51_LOW;
break; 
 
 
 
case   3600000...3999990: //  low,    
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G2_SUBBAND_R51_LOW;
break; 
 
 
 
case   3200000...3599990: // low,    
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G1_SUBBAND_R51_LOW;
break; 
 
 
 
/* *************************  */
 
case   3000000...3199990:   //   high,  
       *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G4_SUBBAND_R50_HIGH;  //600-639.999 /2 
break; 
 
 
case    2800000 ... 2999990 //  high   
 
      
      *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G3_SUBBAND_R50_HIGH;  //560-599.999 /2
break; 
 
 
case     2600000...2799990: // high  
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G8_SUBBAND_R50_HIGH;  //520-559.999 /2
break; 
 
 
 
case  2400000... 2599990: // high 
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G7_SUBBAND_R50_HIGH;  //480-519.999 /2
break;
 
case  2240000...2399990:  // high  
 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G6_SUBBAND_R50_HIGH;  //440-479.999 /2 
break;
 
 
case  2200000...2239990: // low 
      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G6_SUBBAND_R49_LOW;  //440-479.999 /2 
break;
 
 
 
 
case  2000000...2199990://low subband ,      
     *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G5_SUBBAND_R49_LOW;  //400-419.999 /2 
break;
 
case  1800000...1999990:// low subband ,
     
       *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G2_SUBBAND_R49_LOW;  //360-399.999 /2 
break;
 
 
case  1600000 ...1799990:// low subband ,      
       *compfreq=FREQ1_25kHz    
       *oscnum= nOSC_G1_SUBBAND_R49_LOW;  //320-359.999 /2 
break;
/* *****************************  */
 
case   1500000...1599999://high subband ,      
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G4_SUBBAND_R48_HIGH;  //600-639.999  /4 
break;
 
case   1400000...1499999:// high subband    
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G3_SUBBAND_R48_HIGH;  //560-599.999  /4 
break;
 
case   1300000...1399999: // high subband ,
      
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G8_SUBBAND_R48_HIGH;  //520-559.999  /4 
break;
 
 
case  1200000...1299999:// high subband ,         
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G7_SUBBAND_R48_HIGH;  //480-519.999  /4 
break;
 
 
 
 
case  1120000 ...1199999: // high subband ,   
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G6_SUBBAND_R48_HIGH;  //440-479.999  /4 
break;
 
 
case  1100000...1119999://  low subband ,   80-111.9999    
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G6_SUBBAND_R47_LOW;  //440-479.999  /4 
break;
 
 
case  1000000...1099999:// low subband ,   
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G5_SUBBAND_R47_LOW;  //400-439.999  /4 
break;
 
case  900000... 999999: // low subband     
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G2_SUBBAND_R47_LOW;  //360-399.999  /4 
break;
 
case  800000... 899999: // low subband     
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G1_SUBBAND_R47_LOW;  //320-359.999  /4 
break;
/* *******************  */
case  750000... 799999: // high subband    
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G4_SUBBAND_R46_HIGH;  //600-639.999  /8
break;
 
case  700000... 749999: // high subband    
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G3_SUBBAND_R46_HIGH;  //560-599.999  /8
break;
 
case  650000... 699999: // high subband     
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G8_SUBBAND_R46_HIGH;  //520-559.999  /8
break;
 
case  600000... 649999: // high subband  
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G7_SUBBAND_R46_HIGH;  //480-519.999  /8
break;
 
case  560000... 599999: // high subband  
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G6_SUBBAND_R46_HIGH;  //440-479.999  /8
break;
 
case  550000... 559999: // low subband  
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G6_SUBBAND_R45_LOW;  //440-479.999  /8
break;
 
case  500000... 549999: // low subband  
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G5_SUBBAND_R45_LOW;  //400-439.999  /8
break;
 
case  450000... 549999: // low subband  
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G2_SUBBAND_R45_LOW;  //360-399.999  /8
break;
 
case  400000... 449999: // low subband  
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G1_SUBBAND_R45_LOW;  //320-359.999  /8
break;
/* ****************************** */
 
case  280000... 399999: // high subband    
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G4_SUBBAND_R44_HIGH;  //600-639.999  /16
break;
 
case  200000... 279999: //low subband    
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G3_SUBBAND_R43_LOW;  //560-599.999  /16
break;
 
case  140000... 199999: // high subband     
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G8_SUBBAND_R42_HIGH;  //520-559.999  /32
break;
/* ******************************* */
 
case  120000... 139999: // low subband   , 112 -113.9999, 448  -455,99996‬
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G6_SUBBAND_R48_HIGH;  //440-479.999  /4
break;
 
 case  1000... 119999: // low subband   , 113 -113.9999
       *compfreq=FREQ1kHz    
       *oscnum= nOSC_G6_SUBBAND_R47_LOW; //440-479.999  /4
break;
 
}
 
 return;
 
}
Добавлено через 25 минут
проблема с типом данных 6399990 (639999 ) и диапазоном при обработке, может через if попробовать , исправив мелкие ошибки

Добавлено через 35 минут
переполняется стек при ветвлении , через

C++
1
2
3
4
5
6
7
if ( freqvalue>=6000000 ) {  
if(freqvalue <=  6399990) { 
 
       *compfreq=FREQ1_25kHz;    
       nosc_code= nOSC_G4_SUBBAND_R52_HIGH;
}}
...
пробовать
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 14:14  [ТС]
Проверка подпрограммы : при 12 МГц 45,50 мкс,Cycle counter примерно 546 после сброса
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/*
 * Gccapp1.c
 *
 * Created: 20.03.2020 02:09:14
 * Author : USERPC01
 */ 
 
#include <avr/io.h>
#include <math.h>
 
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
// 1kHz pin   low 1kHz (set nInform  low), high  1.25 kHz    (set nInform  high)
#define FREQ1kHz  0x00         //check for circuit 
#define FREQ1_25kHz  0x01
 
#define  HFO_FM0_1 0   //fix for sender 
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
//rule for  inverse Inform code  , for  nInform pin
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42) 
 
 
 
 
 
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
 
 uint32_t result;
 uint16_t result1; 
 
 
 result=(uint32_t)  (freq[4] );
 result+=(uint32_t) (freq[5]<<4);
 result+=(uint32_t) (freq[6]<<8);
result=(result<<16);
result1 =(uint16_t) freq[0];
result1+=(uint16_t) (freq[1]<<4);
result1+=(uint16_t) (freq[2]<<8);
result1+=(uint16_t) (freq[3]<<12);
 
 
 
 
 
 
return result;
}
 
 
 
 
 
 
 
 
 
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
 
uint32_t freqvalue;
//freqvalue= freq_fromdigits ( freq );
//uint8_t  nosc_code;
 
 
//600.000 -639.999
freqvalue= freq_fromdigits  ( freq );
 
 
if ( freqvalue>=6000000 ) {  
if(freqvalue <=  6399990)   
 
       *compfreq=FREQ1_25kHz;    
      return nOSC_G4_SUBBAND_R52_HIGH;
} 
 
  
if ( freqvalue>=5600000 )   
if(freqvalue <=  5999990) {  
      *compfreq=FREQ1_25kHz;    
       return nOSC_G3_SUBBAND_R52_HIGH;
}
 
if ( freqvalue>=5200000 )
if(freqvalue <=  5599990) {
 
 
 
      
     *compfreq=FREQ1_25kHz;    
       return nOSC_G8_SUBBAND_R52_HIGH ;
}
 
 
if ( freqvalue>=4800000 )
if(freqvalue <=  5199990) { 
     
     *compfreq=FREQ1_25kHz;    
       return nOSC_G7_SUBBAND_R52_HIGH ;
}
 
if ( freqvalue>=4480000 )
if(freqvalue <=  4799990) {
   //   high,    448-479.999
 
       *compfreq=FREQ1_25kHz;    
       return nOSC_G6_SUBBAND_R52_HIGH;
}
 
if ( freqvalue>=4400000 )
if(freqvalue <=  4479990) {
   //low,    440-447.999
 
 
      *compfreq=FREQ1_25kHz;    
       return nOSC_G6_SUBBAND_R51_LOW;
}
 
 
if ( freqvalue>=4000000 )
if(freqvalue <=  4399990) {
 
  //  low,    400-439.999
 
      
       *compfreq=FREQ1_25kHz;    
       return nOSC_G5_SUBBAND_R51_LOW;
}
 
 
if ( freqvalue>=3600000 )
if(freqvalue <=  3999990) {
  //  low,    
     *compfreq=FREQ1_25kHz;    
       return nOSC_G2_SUBBAND_R51_LOW;
}
 
 
if ( freqvalue>=3200000 )
if(freqvalue <=  3599990) {
  // low,    
 
      
     *compfreq=FREQ1_25kHz ;   
       return nOSC_G1_SUBBAND_R51_LOW;
} 
 
 
 
/* *************************  */
if ( freqvalue>=3000000 )
if(freqvalue <=  3199990) {
    //   high,  
       *compfreq=FREQ1_25kHz ;   
        return nOSC_G4_SUBBAND_R50_HIGH;  //600-639.999 /2 
} 
 
if ( freqvalue>=2800000 )
if(freqvalue <=  2999990) {
  //  high   
 
      
      *compfreq=FREQ1_25kHz   ; 
       return nOSC_G3_SUBBAND_R50_HIGH;  //560-599.999 /2
} 
 
if ( freqvalue>=2600000 )
if(freqvalue <=  2799990) {
  // high  
 
      
     *compfreq=FREQ1_25kHz   ; 
       return nOSC_G8_SUBBAND_R50_HIGH;  //520-559.999 /2
} 
 
 
if ( freqvalue>=2400000 )
if(freqvalue <=  2599990) {
  // high 
 
      
     *compfreq=FREQ1_25kHz   ; 
       return nOSC_G7_SUBBAND_R50_HIGH;  //480-519.999 /2
}
 
if ( freqvalue>=2240000 )
if(freqvalue <=  2399990) {
   // high  
 
      
     *compfreq=FREQ1_25kHz   ; 
      return nOSC_G6_SUBBAND_R50_HIGH;  //440-479.999 /2 
}
 
if ( freqvalue>=2200000 )
if(freqvalue <=  2239990) {
  // low 
      
     *compfreq=FREQ1_25kHz   ; 
      return nOSC_G6_SUBBAND_R49_LOW;  //440-479.999 /2 
}
 
 
 
if ( freqvalue>=2000000 )
if(freqvalue <=  2199990) {
 //low subband ,      
     *compfreq=FREQ1_25kHz  ;  
       return nOSC_G5_SUBBAND_R49_LOW;  //400-419.999 /2 
}
 
if ( freqvalue>=1800000 )
if(freqvalue <=  1999990) {
 // low subband ,
     
       *compfreq=FREQ1_25kHz;    
       return nOSC_G2_SUBBAND_R49_LOW;  //360-399.999 /2 
}
 
if ( freqvalue>=1600000 )
if(freqvalue <=  1799990) {
 // low subband ,      
       *compfreq=FREQ1_25kHz;    
       return nOSC_G1_SUBBAND_R49_LOW;  //320-359.999 /2 
}
 
 
 
 
if ( freqvalue>=1500000 )
if(freqvalue <=  1599999) {  
 //high subband ,      
       *compfreq=FREQ1kHz    ;
       return nOSC_G4_SUBBAND_R48_HIGH;  //600-639.999  /4 
}
 
if ( freqvalue>=1400000 )
if(freqvalue <=  1499999) {
 // high subband    
       *compfreq=FREQ1kHz    ;
       return nOSC_G3_SUBBAND_R48_HIGH;  //560-599.999  /4 
}
 
if ( freqvalue>=1300000 )
if(freqvalue <=  1399999) {
  // high subband ,
      
       *compfreq=FREQ1kHz   ; 
       return nOSC_G8_SUBBAND_R48_HIGH;  //520-559.999  /4 
}
 
if ( freqvalue>=1200000 )
if(freqvalue <=  1299999) {
 // high subband ,         
       *compfreq=FREQ1kHz   ; 
       return nOSC_G7_SUBBAND_R48_HIGH;  //480-519.999  /4 
}
 
 
 
if ( freqvalue>=1120000 )
if(freqvalue <=  1199999 ) {
  // high subband ,   
       *compfreq=FREQ1kHz ;   
       return nOSC_G6_SUBBAND_R48_HIGH;  //440-479.999  /4 
}
 
if ( freqvalue>=1100000 )
if(freqvalue <=  1119999 ) {
 //  low subband ,   80-111.9999    
       *compfreq=FREQ1kHz ;   
       return nOSC_G6_SUBBAND_R47_LOW;  //440-479.999  /4 
}
 
if ( freqvalue>=1000000 )
if(freqvalue <=  1099999) {
 // low subband ,   
       *compfreq=FREQ1kHz   ; 
       return nOSC_G5_SUBBAND_R47_LOW;  //400-439.999  /4 
}
 
if ( freqvalue>=900000 )
if(freqvalue <=  999999) { 
  // low subband     
       *compfreq=FREQ1kHz ;   
       return nOSC_G2_SUBBAND_R47_LOW;  //360-399.999  /4 
}
 
if ( freqvalue>=800000 )
if(freqvalue <=  899999) {
  // low subband     
       *compfreq=FREQ1kHz ;   
      return nOSC_G1_SUBBAND_R47_LOW;  //320-359.999  /4 
}
/* *******************  */
if ( freqvalue>=750000 )
if(freqvalue <=  799999) {
  // high subband    
       *compfreq=FREQ1kHz;    
       return nOSC_G4_SUBBAND_R46_HIGH;  //600-639.999  /8
}
 
if ( freqvalue>=700000 )
if(freqvalue <=  749999) {
  // high subband    
       *compfreq=FREQ1kHz  ;  
       return nOSC_G3_SUBBAND_R46_HIGH;  //560-599.999  /8
}
 
if ( freqvalue>=650000 )
if(freqvalue <=  699999) {
  // high subband     
       *compfreq=FREQ1kHz ;   
       return nOSC_G8_SUBBAND_R46_HIGH;  //520-559.999  /8
}
 
if ( freqvalue>=600000 )
if(freqvalue <=  649999) {
  // high subband  
       *compfreq=FREQ1kHz;    
      return nOSC_G7_SUBBAND_R46_HIGH;  //480-519.999  /8
}
 
if ( freqvalue>=560000 )
if(freqvalue <=  599999) {
  // high subband  
       *compfreq=FREQ1kHz ;   
       return nOSC_G6_SUBBAND_R46_HIGH;  //440-479.999  /8
}
 
if ( freqvalue>=550000 )
if(freqvalue <=  559999) {
  // low subband  
       *compfreq=FREQ1kHz ;   
       return nOSC_G6_SUBBAND_R45_LOW;  //440-479.999  /8
}
 
if ( freqvalue>=500000 )
if(freqvalue <=  549999) {
   // low subband  
       *compfreq=FREQ1kHz ;   
        return nOSC_G5_SUBBAND_R45_LOW;  //400-439.999  /8
}
 
if ( freqvalue>=450000 )
if(freqvalue <=  499999) {
  // low subband  
       *compfreq=FREQ1kHz  ;  
       return nOSC_G2_SUBBAND_R45_LOW;  //360-399.999  /8
}
 
if ( freqvalue>=400000 )
if(freqvalue <=  449999) {
  // low subband  
       *compfreq=FREQ1kHz  ;  
       return nOSC_G1_SUBBAND_R45_LOW;  //320-359.999  /8
}
 
 
if ( freqvalue>=280000 )
if(freqvalue <=  399999) {  
      
       *compfreq=FREQ1kHz   ; 
       return nOSC_G4_SUBBAND_R44_HIGH;  //600-639.999  /16
}
 
if ( freqvalue>=200000 )
if(freqvalue <=  279999) {
    
       *compfreq=FREQ1kHz   ; 
       return nOSC_G3_SUBBAND_R43_LOW;  //560-599.999  /16
}
 
if ( freqvalue>=140000 )
if(freqvalue <=  199999) {
     
       *compfreq=FREQ1kHz  ;  
       return nOSC_G8_SUBBAND_R42_HIGH;  //520-559.999  /32
}
  
if ( freqvalue>=120000 )
if(freqvalue <=  139999) {
   // high subband   , 112 -113.9999, 448  -455,99996‬
       *compfreq=FREQ1kHz  ;  
       return nOSC_G6_SUBBAND_R48_HIGH;  //440-479.999  /4
 }
 
if ( freqvalue>=1000 )
if(freqvalue <=  119999) {
   // low subband   , 113 -113.9999
        *compfreq=FREQ1kHz  ;
        return nOSC_G6_SUBBAND_R47_LOW; //440-479.999  /4
 }
 
 
 
  return 0x00 ;
 
}
int main(void)
{
     uint8_t compfreq;
      uint8_t freq[7];
        
        freq[6]=PIND;
         freq[5]=PIND;
          freq[4]=PIND;
      
       freq[3]=PIND;
      freq[2]=PIND;
       freq[1]=PIND;
        freq[0]=PIND;
      while (1) 
    {
         
     
    uint8_t osc_num=GetOSCNum( freq  , &compfreq  );
    
         
    
    
      
    //data2=mul4(  data2)  ;
    
    
    
   
   
    
         PORTD=(uint8_t)osc_num;
        
        
    }
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 14:19  [ТС]
Листинг на ассемблере, сгенерированный компилятором и пробная программа (проблема со сдвигом на 4 байта в старших разрядах (12, 16, 24)):
Вложения
Тип файла: zip Gccapp1.zip (11.8 Кб, 6 просмотров)
Тип файла: zip Gccapp2.zip (53.5 Кб, 6 просмотров)
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 16:23  [ТС]
Code
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
0000006c <freq_fromdigits>:
 
 
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
  6c:   fc 01           movw    r30, r24
 
 uint32_t result;
 uint16_t result1; 
 
 
 result=(uint32_t)  (freq[4] );
  6e:   24 81           ldd r18, Z+4    ; 0x04
 result+=(uint32_t) (freq[5]<<4);
 result+=(uint32_t) (freq[6]<<8);
  70:   65 81           ldd r22, Z+5    ; 0x05
  72:   80 e1           ldi r24, 0x10   ; 16
  74:   68 9f           mul r22, r24
  76:   b0 01           movw    r22, r0
  78:   11 24           eor r1, r1
  7a:   ab 01           movw    r20, r22
  7c:   77 0f           add r23, r23
  7e:   66 0b           sbc r22, r22
  80:   77 0b           sbc r23, r23
  82:   86 81           ldd r24, Z+6    ; 0x06
  84:   90 e0           ldi r25, 0x00   ; 0
  86:   98 2f           mov r25, r24
  88:   88 27           eor r24, r24
  8a:   09 2e           mov r0, r25
  8c:   00 0c           add r0, r0
  8e:   aa 0b           sbc r26, r26
  90:   bb 0b           sbc r27, r27
  92:   84 0f           add r24, r20
  94:   95 1f           adc r25, r21
  96:   a6 1f           adc r26, r22
  98:   b7 1f           adc r27, r23
  9a:   82 0f           add r24, r18
  9c:   91 1d           adc r25, r1
  9e:   a1 1d           adc r26, r1
  a0:   b1 1d           adc r27, r1
 
 
 
 
 
return result;
  a2:   77 27           eor r23, r23
  a4:   66 27           eor r22, r22
}
  a6:   08 95           ret
Добавлено через 2 минуты
Code
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
000000a8 <GetOSCNum>:
 
 
 
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
  a8:   0f 93           push    r16
  aa:   1f 93           push    r17
  ac:   cf 93           push    r28
  ae:   df 93           push    r29
  b0:   eb 01           movw    r28, r22
//freqvalue= freq_fromdigits ( freq );
//uint8_t  nosc_code;
 
 
//600.000 -639.999
freqvalue= freq_fromdigits  ( freq );
  b2:   0e 94 36 00     call    0x6c    ; 0x6c <freq_fromdigits>
 
 
if ( freqvalue>=6000000 ) {  
  b6:   60 38           cpi r22, 0x80   ; 128
  b8:   2d e8           ldi r18, 0x8D   ; 141
  ba:   72 07           cpc r23, r18
  bc:   2b e5           ldi r18, 0x5B   ; 91
  be:   82 07           cpc r24, r18
  c0:   91 05           cpc r25, r1
  c2:   50 f0           brcs    .+20        ; 0xd8 <GetOSCNum+0x30>
if(freqvalue <=  6399990)   
  c4:   67 3f           cpi r22, 0xF7   ; 247
  c6:   77 4a           sbci    r23, 0xA7   ; 167
  c8:   81 46           sbci    r24, 0x61   ; 97
  ca:   91 05           cpc r25, r1
  cc:   08 f0           brcs    .+2         ; 0xd0 <GetOSCNum+0x28>
  ce:   85 c2           rjmp    .+1290      ; 0x5da <__stack+0x17b>
 
       *compfreq=FREQ1_25kHz;    
  d0:   81 e0           ldi r24, 0x01   ; 1
  d2:   88 83           st  Y, r24
      return nOSC_G4_SUBBAND_R52_HIGH;
  d4:   8e ed           ldi r24, 0xDE   ; 222
  d6:   1b c4           rjmp    .+2102      ; 0x90e <__stack+0x4af>
} 
 
  
if ( freqvalue>=5600000 )   
  d8:   8b 01           movw    r16, r22
  da:   9c 01           movw    r18, r24
  dc:   13 57           subi    r17, 0x73   ; 115
  de:   25 45           sbci    r18, 0x55   ; 85
  e0:   31 09           sbc r19, r1
  e2:   07 37           cpi r16, 0x77   ; 119
  e4:   1a 41           sbci    r17, 0x1A   ; 26
  e6:   26 40           sbci    r18, 0x06   ; 6
  e8:   31 05           cpc r19, r1
  ea:   20 f4           brcc    .+8         ; 0xf4 <GetOSCNum+0x4c>
if(freqvalue <=  5999990) {  
      *compfreq=FREQ1_25kHz;    
  ec:   81 e0           ldi r24, 0x01   ; 1
  ee:   88 83           st  Y, r24
       return nOSC_G3_SUBBAND_R52_HIGH;
  f0:   8c ed           ldi r24, 0xDC   ; 220
  f2:   0d c4           rjmp    .+2074      ; 0x90e <__stack+0x4af>
}
 
if ( freqvalue>=5200000 )
  f4:   8b 01           movw    r16, r22
  f6:   9c 01           movw    r18, r24
  f8:   00 58           subi    r16, 0x80   ; 128
  fa:   18 45           sbci    r17, 0x58   ; 88
  fc:   2f 44           sbci    r18, 0x4F   ; 79
  fe:   31 09           sbc r19, r1
 100:   07 37           cpi r16, 0x77   ; 119
 102:   1a 41           sbci    r17, 0x1A   ; 26
 104:   26 40           sbci    r18, 0x06   ; 6
 106:   31 05           cpc r19, r1
 108:   20 f4           brcc    .+8         ; 0x112 <GetOSCNum+0x6a>
if(freqvalue <=  5599990) {
 
 
 
      
     *compfreq=FREQ1_25kHz;    
 10a:   81 e0           ldi r24, 0x01   ; 1
 10c:   88 83           st  Y, r24
       return nOSC_G8_SUBBAND_R52_HIGH ;
 10e:   8a ed           ldi r24, 0xDA   ; 218
 110:   fe c3           rjmp    .+2044      ; 0x90e <__stack+0x4af>
}
 
 
if ( freqvalue>=4800000 )
 112:   8b 01           movw    r16, r22
 114:   9c 01           movw    r18, r24
 116:   1e 53           subi    r17, 0x3E   ; 62
 118:   29 44           sbci    r18, 0x49   ; 73
 11a:   31 09           sbc r19, r1
 11c:   07 37           cpi r16, 0x77   ; 119
 11e:   1a 41           sbci    r17, 0x1A   ; 26
 120:   26 40           sbci    r18, 0x06   ; 6
 122:   31 05           cpc r19, r1
 124:   20 f4           brcc    .+8         ; 0x12e <GetOSCNum+0x86>
if(freqvalue <=  5199990) { 
     
     *compfreq=FREQ1_25kHz;    
 126:   81 e0           ldi r24, 0x01   ; 1
 128:   88 83           st  Y, r24
       return nOSC_G7_SUBBAND_R52_HIGH ;
 12a:   8e ed           ldi r24, 0xDE   ; 222
 12c:   f0 c3           rjmp    .+2016      ; 0x90e <__stack+0x4af>
}
 
if ( freqvalue>=4480000 )
 12e:   8b 01           movw    r16, r22
 130:   9c 01           movw    r18, r24
 132:   1c 55           subi    r17, 0x5C   ; 92
 134:   24 44           sbci    r18, 0x44   ; 68
 136:   31 09           sbc r19, r1
 138:   07 3f           cpi r16, 0xF7   ; 247
 13a:   11 4e           sbci    r17, 0xE1   ; 225
 13c:   24 40           sbci    r18, 0x04   ; 4
 13e:   31 05           cpc r19, r1
 140:   20 f4           brcc    .+8         ; 0x14a <GetOSCNum+0xa2>
if(freqvalue <=  4799990) {
   //   high,    448-479.999
 
       *compfreq=FREQ1_25kHz;    
 142:   81 e0           ldi r24, 0x01   ; 1
 144:   88 83           st  Y, r24
       return nOSC_G6_SUBBAND_R52_HIGH;
 146:   86 ed           ldi r24, 0xD6   ; 214
 148:   e2 c3           rjmp    .+1988      ; 0x90e <__stack+0x4af>
}
 
if ( freqvalue>=4400000 )
 14a:   8b 01           movw    r16, r22
 14c:   9c 01           movw    r18, r24
 14e:   00 58           subi    r16, 0x80   ; 128
 150:   13 42           sbci    r17, 0x23   ; 35
 152:   23 44           sbci    r18, 0x43   ; 67
 154:   31 09           sbc r19, r1
 156:   07 37           cpi r16, 0x77   ; 119
 158:   18 43           sbci    r17, 0x38   ; 56
 15a:   21 40           sbci    r18, 0x01   ; 1
 15c:   31 05           cpc r19, r1
 15e:   20 f4           brcc    .+8         ; 0x168 <GetOSCNum+0xc0>
if(freqvalue <=  4479990) {
   //low,    440-447.999
 
 
      *compfreq=FREQ1_25kHz;    
 160:   81 e0           ldi r24, 0x01   ; 1
 162:   88 83           st  Y, r24
       return nOSC_G6_SUBBAND_R51_LOW;
 164:   86 ec           ldi r24, 0xC6   ; 198
 166:   d3 c3           rjmp    .+1958      ; 0x90e <__stack+0x4af>
}
 
 
if ( freqvalue>=4000000 )
 168:   8b 01           movw    r16, r22
 16a:   9c 01           movw    r18, r24
 16c:   19 50           subi    r17, 0x09   ; 9
 16e:   2d 43           sbci    r18, 0x3D   ; 61
 170:   31 09           sbc r19, r1
 172:   07 37           cpi r16, 0x77   ; 119
 174:   1a 41           sbci    r17, 0x1A   ; 26
 176:   26 40           sbci    r18, 0x06   ; 6
 178:   31 05           cpc r19, r1
 17a:   20 f4           brcc    .+8         ; 0x184 <GetOSCNum+0xdc>
if(freqvalue <=  4399990) {
 
  //  low,    400-439.999
 
      
       *compfreq=FREQ1_25kHz;    
 17c:   81 e0           ldi r24, 0x01   ; 1
 17e:   88 83           st  Y, r24
       return nOSC_G5_SUBBAND_R51_LOW;
 180:   84 ec           ldi r24, 0xC4   ; 196
 182:   c5 c3           rjmp    .+1930      ; 0x90e <__stack+0x4af>
}
 
 
if ( freqvalue>=3600000 )
 184:   8b 01           movw    r16, r22
 186:   9c 01           movw    r18, r24
 188:   00 58           subi    r16, 0x80   ; 128
 18a:   1e 4e           sbci    r17, 0xEE   ; 238
 18c:   26 43           sbci    r18, 0x36   ; 54
 18e:   31 09           sbc r19, r1
 190:   07 37           cpi r16, 0x77   ; 119
 192:   1a 41           sbci    r17, 0x1A   ; 26
 194:   26 40           sbci    r18, 0x06   ; 6
 196:   31 05           cpc r19, r1
 198:   20 f4           brcc    .+8         ; 0x1a2 <GetOSCNum+0xfa>
if(freqvalue <=  3999990) {
  //  low,    
     *compfreq=FREQ1_25kHz;    
 19a:   81 e0           ldi r24, 0x01   ; 1
 19c:   88 83           st  Y, r24
       return nOSC_G2_SUBBAND_R51_LOW;
 19e:   82 ec           ldi r24, 0xC2   ; 194
 1a0:   b6 c3           rjmp    .+1900      ; 0x90e <__stack+0x4af>
}
 
 
if ( freqvalue>=3200000 )
 1a2:   8b 01           movw    r16, r22
 1a4:   9c 01           movw    r18, r24
 1a6:   14 5d           subi    r17, 0xD4   ; 212
 1a8:   20 43           sbci    r18, 0x30   ; 48
 1aa:   31 09           sbc r19, r1
 1ac:   07 37           cpi r16, 0x77   ; 119
 1ae:   1a 41           sbci    r17, 0x1A   ; 26
 1b0:   26 40           sbci    r18, 0x06   ; 6
 1b2:   31 05           cpc r19, r1
 1b4:   20 f4           brcc    .+8         ; 0x1be <GetOSCNum+0x116>
if(freqvalue <=  3599990) {
  // low,    
 
      
     *compfreq=FREQ1_25kHz ;   
 1b6:   81 e0           ldi r24, 0x01   ; 1
 1b8:   88 83           st  Y, r24
       return nOSC_G1_SUBBAND_R51_LOW;
 1ba:   80 ec           ldi r24, 0xC0   ; 192
 1bc:   a8 c3           rjmp    .+1872      ; 0x90e <__stack+0x4af>
} 
 
 
 
/* *************************  */
if ( freqvalue>=3000000 )
 1be:   8b 01           movw    r16, r22
 1c0:   9c 01           movw    r18, r24
 1c2:   00 5c           subi    r16, 0xC0   ; 192
 1c4:   16 4c           sbci    r17, 0xC6   ; 198
 1c6:   2d 42           sbci    r18, 0x2D   ; 45
 1c8:   31 09           sbc r19, r1
 1ca:   07 33           cpi r16, 0x37   ; 55
 1cc:   1d 40           sbci    r17, 0x0D   ; 13
 1ce:   23 40           sbci    r18, 0x03   ; 3
 1d0:   31 05           cpc r19, r1
 1d2:   20 f4           brcc    .+8         ; 0x1dc <GetOSCNum+0x134>
if(freqvalue <=  3199990) {
    //   high,  
       *compfreq=FREQ1_25kHz ;   
 1d4:   81 e0           ldi r24, 0x01   ; 1
 1d6:   88 83           st  Y, r24
        return nOSC_G4_SUBBAND_R50_HIGH;  //600-639.999 /2 
 1d8:   8e eb           ldi r24, 0xBE   ; 190
 1da:   99 c3           rjmp    .+1842      ; 0x90e <__stack+0x4af>
} 
 
...
Может, таблично из памяти подставлять верхние и нижние значения ? Так компактнее, но сбоенеустойчивее , непредсказуемее время обращения к памяти, но это большая программа .

Добавлено через 28 минут
Подозрительно с
Code
1
if(freqvalue <=  5999990)
и аналогичными : (ошибка мэппинга подпрограмм в памяти , перестроить ).
На этом языке для таких контроллеров обычно возникают проблемы с большими и сложными программами, типами данных , проверяется по листингу и при отладке в симуляторе.

Добавлено через 1 минуту
Code
1
2
 e0:    31 09           sbc r19, r1
  e2:   07 37           cpi r16, 0x77   ; 119
там есть

Добавлено через 2 минуты
Code
1
2
5 600 000‬ =0x00 55 73 00‬
5 999 990=0x00 5B 8D 76
Добавлено через 2 минуты
Слишком "лонговый" тип (у нас 8-битка, а не 16-битка , как в оригинале, но по битам при более высокой тактовой нечто можно сделать , это и хотелось прикинуть ).

Добавлено через 1 час 21 минуту
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
 * Gccapp1.c
 *
 * Created: 20.03.2020 02:09:14
 * Author : USERPC01
 */ 
 
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <math.h>
 
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
// 1kHz pin   low 1kHz (set nInform  low), high  1.25 kHz    (set nInform  high)
#define FREQ1kHz  0x00         //check for circuit 
#define FREQ1_25kHz  0x01
 
#define  HFO_FM0_1 0   //fix for sender 
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
//rule for  inverse Inform code  , for  nInform pin
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42) 
 
 
 
 
 
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
 
 uint32_t result;
 uint16_t result1; 
 
 
 result=(uint32_t)  (freq[4] );
 result+=(uint32_t) (freq[5]<<4);
 result+=(uint32_t) (freq[6]<<8);
result=(result<<16);
result1 =(uint16_t) freq[0];
result1+=(uint16_t) (freq[1]<<4);
result1+=(uint16_t) (freq[2]<<8);
result1+=(uint16_t) (freq[3]<<12);
 
 
 
 
 
 
return result;
}
 
 
 
const uint32_t array_lowfreq [41] PROGMEM ={
6000000,5600000, 5200000,4800000 , 4480000, 4400000, 4000000, 3600000,3200000,3000000, 
2800000,2600000, 2400000,2240000,2200000,  2000000,1800000,  1600000 ,1500000,1400000,
1300000,1200000,1120000, 1100000, 1000000,900000,800000,750000 ,700000,650000,
 600000,560000, 550000,500000,450000, 400000,  280000, 200000,140000, 120000, 1000  
};
 
const uint32_t array_highfreq [41] PROGMEM ={
6399990,5999990,5599990, 5199990, 4799990,4479990,4399990,3999990,3599990,3199990,
2999990,2799990,2599990,2399990,2239990,2199990,1999990, 1799990,1599999,1499999,
1399999,1299999,1199999,1119999, 1099999,999999,899999,799999,749999,699999,
649999,599999,559999,549999,499999,449999,399999,279999,199999,139999,119999
};
 
const  uint8_t  array_osc_results[41] PROGMEM =
{
 
nOSC_G4_SUBBAND_R52_HIGH, nOSC_G3_SUBBAND_R52_HIGH, nOSC_G8_SUBBAND_R52_HIGH, nOSC_G7_SUBBAND_R52_HIGH,
nOSC_G6_SUBBAND_R52_HIGH, nOSC_G6_SUBBAND_R51_LOW, nOSC_G5_SUBBAND_R51_LOW, nOSC_G2_SUBBAND_R51_LOW,
nOSC_G1_SUBBAND_R51_LOW, nOSC_G4_SUBBAND_R50_HIGH, nOSC_G3_SUBBAND_R50_HIGH, nOSC_G8_SUBBAND_R50_HIGH,
nOSC_G7_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R49_LOW, nOSC_G5_SUBBAND_R49_LOW,
nOSC_G2_SUBBAND_R49_LOW,  nOSC_G1_SUBBAND_R49_LOW, nOSC_G4_SUBBAND_R48_HIGH, nOSC_G3_SUBBAND_R48_HIGH,
nOSC_G8_SUBBAND_R48_HIGH, nOSC_G7_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R47_LOW,
nOSC_G5_SUBBAND_R47_LOW, nOSC_G2_SUBBAND_R47_LOW, nOSC_G1_SUBBAND_R47_LOW, nOSC_G4_SUBBAND_R46_HIGH,
nOSC_G3_SUBBAND_R46_HIGH, nOSC_G8_SUBBAND_R46_HIGH, nOSC_G7_SUBBAND_R46_HIGH, nOSC_G6_SUBBAND_R46_HIGH,
nOSC_G6_SUBBAND_R45_LOW, nOSC_G5_SUBBAND_R45_LOW, nOSC_G2_SUBBAND_R45_LOW, nOSC_G1_SUBBAND_R45_LOW,
nOSC_G4_SUBBAND_R44_HIGH, nOSC_G3_SUBBAND_R43_LOW,nOSC_G8_SUBBAND_R42_HIGH,nOSC_G6_SUBBAND_R48_HIGH,
nOSC_G6_SUBBAND_R47_LOW
 
};
 
 
uint8_t array_fref[41]=
{
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz, FREQ1kHz
};
 
 
 
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
 
uint32_t freqvalue;
 
 
 
 
freqvalue= freq_fromdigits  ( freq );
 
 
uint8_t count=0;
 
while (count<41){ 
 
if ( freqvalue>=array_lowfreq[count] )   {  
if (freqvalue <= array_highfreq [count]){ 
 *compfreq=array_fref[count];  return array_osc_results[count];
}}
count++;
}
 
  return 0x00 ;
 
}
 
 
int main(void)
{
     uint8_t compfreq;
      uint8_t freq[7];
        
        freq[6]=PIND;
         freq[5]=PIND;
          freq[4]=PIND;
      
       freq[3]=PIND;
      freq[2]=PIND;
       freq[1]=PIND;
        freq[0]=PIND;
      while (1) 
    {
         
     
    uint8_t osc_num=GetOSCNum( freq  , &compfreq  );
    
         
    
    
      
    //data2=mul4(  data2)  ;
    
    
    
   
   
    
         PORTD=(uint8_t)osc_num;
        
        
    }
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 17:32  [ТС]
Gccapp1.lss
Code
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
Gccapp1.elf:     file format elf32-avr
 
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         000002ec  00000000  00000000  00000074  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         0000002a  00800060  000002ec  00000360  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .comment      00000030  00000000  00000000  0000038a  2**0
                  CONTENTS, READONLY
  3 .note.gnu.avr.deviceinfo 0000003c  00000000  00000000  000003bc  2**2
                  CONTENTS, READONLY
  4 .debug_aranges 00000030  00000000  00000000  000003f8  2**0
                  CONTENTS, READONLY, DEBUGGING
  5 .debug_info   000007b5  00000000  00000000  00000428  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_abbrev 00000606  00000000  00000000  00000bdd  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_line   00000253  00000000  00000000  000011e3  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_frame  00000074  00000000  00000000  00001438  2**2
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_str    00000385  00000000  00000000  000014ac  2**0
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_loc    0000021e  00000000  00000000  00001831  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_ranges 00000020  00000000  00000000  00001a4f  2**0
                  CONTENTS, READONLY, DEBUGGING
 
Disassembly of section .text:
 
00000000 <__vectors>:
   0:   0c 94 e3 00     jmp 0x1c6   ; 0x1c6 <__ctors_end>
   4:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
   8:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
   c:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  10:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  14:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  18:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  1c:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  20:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  24:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  28:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  2c:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  30:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  34:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  38:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  3c:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  40:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  44:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  48:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  4c:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
  50:   0c 94 f8 00     jmp 0x1f0   ; 0x1f0 <__bad_interrupt>
 
00000054 <__trampolines_end>:
  54:   de dc           rcall   .-1604      ; 0xfffffa12 <__eeprom_end+0xff7efa12>
  56:   da de           rcall   .-588       ; 0xfffffe0c <__eeprom_end+0xff7efe0c>
  58:   d6 c6           rjmp    .+3500      ; 0xe06 <__stack+0x9a7>
  5a:   c4 c2           rjmp    .+1416      ; 0x5e4 <__stack+0x185>
  5c:   c0 be           out 0x30, r12   ; 48
  5e:   bc ba           out 0x1c, r11   ; 28
  60:   b8 b6           in  r11, 0x38   ; 56
  62:   a6 a4           ldd r10, Z+46   ; 0x2e
  64:   a2 a0           ldd r10, Z+34   ; 0x22
  66:   9e 9c           mul r9, r14
  68:   9a 98           cbi 0x13, 2 ; 19
  6a:   96 86           std Z+14, r9    ; 0x0e
  6c:   84 82           std Z+4, r8 ; 0x04
  6e:   90 7e           andi    r25, 0xE0   ; 224
  70:   7c 7a           andi    r23, 0xAC   ; 172
  72:   78 76           andi    r23, 0x68   ; 104
  74:   66 64           ori r22, 0x46   ; 70
  76:   62 60           ori r22, 0x02   ; 2
  78:   5e 4c           sbci    r21, 0xCE   ; 206
  7a:   5a 96           adiw    r26, 0x1a   ; 26
  7c:   86 f6           Address 0x0000007c is out of bounds.
.word   0xffff  ; ????
 
0000007d <array_highfreq>:
  7d:   f6 a7 61 00 76 8d 5b 00 f6 72 55 00 76 58 4f 00     ..a.v.[..rU.vXO.
  8d:   f6 3d 49 00 f6 5b 44 00 76 23 43 00 f6 08 3d 00     .=I..[D.v#C...=.
  9d:   76 ee 36 00 f6 d3 30 00 b6 c6 2d 00 76 b9 2a 00     v.6...0...-.v.*.
  ad:   36 ac 27 00 f6 9e 24 00 f6 2d 22 00 b6 91 21 00     6.'...$..-"...!.
  bd:   76 84 1e 00 36 77 1b 00 ff 69 18 00 5f e3 16 00     v...6w...i.._...
  cd:   bf 5c 15 00 1f d6 13 00 7f 4f 12 00 ff 16 11 00     .\.......O......
  dd:   df c8 10 00 3f 42 0f 00 9f bb 0d 00 ff 34 0c 00     ....?B.......4..
  ed:   af 71 0b 00 5f ae 0a 00 0f eb 09 00 bf 27 09 00     .q.._........'..
  fd:   7f 8b 08 00 6f 64 08 00 1f a1 07 00 cf dd 06 00     ....od..........
 10d:   7f 1a 06 00 bf 45 04 00 3f 0d 03 00 df 22 02 00     .....E..?...."..
 11d:   bf d4 01 00                                         ....
 
00000121 <array_lowfreq>:
 121:   80 8d 5b 00 00 73 55 00 80 58 4f 00 00 3e 49 00     ..[..sU..XO..>I.
 131:   00 5c 44 00 80 23 43 00 00 09 3d 00 80 ee 36 00     .\D..#C...=...6.
 141:   00 d4 30 00 c0 c6 2d 00 80 b9 2a 00 40 ac 27 00     ..0...-...*.@.'.
 151:   00 9f 24 00 00 2e 22 00 c0 91 21 00 80 84 1e 00     ..$..."...!.....
 161:   40 77 1b 00 00 6a 18 00 60 e3 16 00 c0 5c 15 00     @w...j..`....\..
 171:   20 d6 13 00 80 4f 12 00 00 17 11 00 e0 c8 10 00      ....O..........
 181:   40 42 0f 00 a0 bb 0d 00 00 35 0c 00 b0 71 0b 00     @B.......5...q..
 191:   60 ae 0a 00 10 eb 09 00 c0 27 09 00 80 8b 08 00     `........'......
 1a1:   70 64 08 00 20 a1 07 00 d0 dd 06 00 80 1a 06 00     pd.. ...........
 1b1:   c0 45 04 00 40 0d 03 00 e0 22 02 00 c0 d4 01 00     .E..@...."......
 1c1:   e8 03 00 00 00                                      .....
 
000001c6 <__ctors_end>:
 1c6:   11 24           eor r1, r1
 1c8:   1f be           out 0x3f, r1    ; 63
 1ca:   cf e5           ldi r28, 0x5F   ; 95
 1cc:   d4 e0           ldi r29, 0x04   ; 4
 1ce:   de bf           out 0x3e, r29   ; 62
 1d0:   cd bf           out 0x3d, r28   ; 61
 
000001d2 <__do_copy_data>:
 1d2:   10 e0           ldi r17, 0x00   ; 0
 1d4:   a0 e6           ldi r26, 0x60   ; 96
 1d6:   b0 e0           ldi r27, 0x00   ; 0
 1d8:   ec ee           ldi r30, 0xEC   ; 236
 1da:   f2 e0           ldi r31, 0x02   ; 2
 1dc:   02 c0           rjmp    .+4         ; 0x1e2 <__do_copy_data+0x10>
 1de:   05 90           lpm r0, Z+
 1e0:   0d 92           st  X+, r0
 1e2:   aa 38           cpi r26, 0x8A   ; 138
 1e4:   b1 07           cpc r27, r17
 1e6:   d9 f7           brne    .-10        ; 0x1de <__do_copy_data+0xc>
 1e8:   0e 94 53 01     call    0x2a6   ; 0x2a6 <main>
 1ec:   0c 94 74 01     jmp 0x2e8   ; 0x2e8 <_exit>
 
000001f0 <__bad_interrupt>:
 1f0:   0c 94 00 00     jmp 0   ; 0x0 <__vectors>
 
000001f4 <freq_fromdigits>:
 
 
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
 1f4:   fc 01           movw    r30, r24
 
 uint32_t result;
 uint16_t result1; 
 
 
 result=(uint32_t)  (freq[4] );
 1f6:   24 81           ldd r18, Z+4    ; 0x04
 result+=(uint32_t) (freq[5]<<4);
 result+=(uint32_t) (freq[6]<<8);
 1f8:   65 81           ldd r22, Z+5    ; 0x05
 1fa:   80 e1           ldi r24, 0x10   ; 16
 1fc:   68 9f           mul r22, r24
 1fe:   b0 01           movw    r22, r0
 200:   11 24           eor r1, r1
 202:   ab 01           movw    r20, r22
 204:   77 0f           add r23, r23
 206:   66 0b           sbc r22, r22
 208:   77 0b           sbc r23, r23
 20a:   86 81           ldd r24, Z+6    ; 0x06
 20c:   90 e0           ldi r25, 0x00   ; 0
 20e:   98 2f           mov r25, r24
 210:   88 27           eor r24, r24
 212:   09 2e           mov r0, r25
 214:   00 0c           add r0, r0
 216:   aa 0b           sbc r26, r26
 218:   bb 0b           sbc r27, r27
 21a:   84 0f           add r24, r20
 21c:   95 1f           adc r25, r21
 21e:   a6 1f           adc r26, r22
 220:   b7 1f           adc r27, r23
 222:   82 0f           add r24, r18
 224:   91 1d           adc r25, r1
 226:   a1 1d           adc r26, r1
 228:   b1 1d           adc r27, r1
 
 
 
 
 
return result;
 22a:   77 27           eor r23, r23
 22c:   66 27           eor r22, r22
}
 22e:   08 95           ret
 
00000230 <GetOSCNum>:
 
 
 
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
 230:   ef 92           push    r14
 232:   ff 92           push    r15
 234:   0f 93           push    r16
 236:   1f 93           push    r17
 238:   cf 93           push    r28
 23a:   df 93           push    r29
 23c:   eb 01           movw    r28, r22
uint32_t freqvalue;
 
 
 
 
freqvalue= freq_fromdigits  ( freq );
 23e:   0e 94 fa 00     call    0x1f4   ; 0x1f4 <freq_fromdigits>
 242:   8b 01           movw    r16, r22
 244:   9c 01           movw    r18, r24
 246:   a1 e2           ldi r26, 0x21   ; 33
 248:   b1 e0           ldi r27, 0x01   ; 1
 24a:   ed e7           ldi r30, 0x7D   ; 125
 24c:   f0 e0           ldi r31, 0x00   ; 0
 24e:   80 e0           ldi r24, 0x00   ; 0
 250:   90 e0           ldi r25, 0x00   ; 0
 
uint8_t count=0;
 
while (count<41){ 
 
if ( freqvalue>=array_lowfreq[count] )   {  
 252:   7c 01           movw    r14, r24
 254:   4d 91           ld  r20, X+
 256:   5d 91           ld  r21, X+
 258:   6d 91           ld  r22, X+
 25a:   7d 91           ld  r23, X+
 25c:   04 17           cp  r16, r20
 25e:   15 07           cpc r17, r21
 260:   26 07           cpc r18, r22
 262:   37 07           cpc r19, r23
 264:   98 f0           brcs    .+38        ; 0x28c <GetOSCNum+0x5c>
if (freqvalue <= array_highfreq [count]){ 
 266:   40 81           ld  r20, Z
 268:   51 81           ldd r21, Z+1    ; 0x01
 26a:   62 81           ldd r22, Z+2    ; 0x02
 26c:   73 81           ldd r23, Z+3    ; 0x03
 26e:   40 17           cp  r20, r16
 270:   51 07           cpc r21, r17
 272:   62 07           cpc r22, r18
 274:   73 07           cpc r23, r19
 276:   50 f0           brcs    .+20        ; 0x28c <GetOSCNum+0x5c>
 *compfreq=array_fref[count];  return array_osc_results[count];
 278:   fc 01           movw    r30, r24
 27a:   e0 5a           subi    r30, 0xA0   ; 160
 27c:   ff 4f           sbci    r31, 0xFF   ; 255
 27e:   80 81           ld  r24, Z
 280:   88 83           st  Y, r24
 282:   f7 01           movw    r30, r14
 284:   ec 5a           subi    r30, 0xAC   ; 172
 286:   ff 4f           sbci    r31, 0xFF   ; 255
 288:   80 81           ld  r24, Z
 28a:   06 c0           rjmp    .+12        ; 0x298 <GetOSCNum+0x68>
 28c:   01 96           adiw    r24, 0x01   ; 1
 28e:   34 96           adiw    r30, 0x04   ; 4
freqvalue= freq_fromdigits  ( freq );
 
 
uint8_t count=0;
 
while (count<41){ 
 290:   89 32           cpi r24, 0x29   ; 41
 292:   91 05           cpc r25, r1
 294:   f1 f6           brne    .-68        ; 0x252 <GetOSCNum+0x22>
 *compfreq=array_fref[count];  return array_osc_results[count];
}}
count++;
}
 
  return 0x00 ;
 296:   80 e0           ldi r24, 0x00   ; 0
 
}
 298:   df 91           pop r29
 29a:   cf 91           pop r28
 29c:   1f 91           pop r17
 29e:   0f 91           pop r16
 2a0:   ff 90           pop r15
 2a2:   ef 90           pop r14
 2a4:   08 95           ret
 
000002a6 <main>:
 
 
int main(void)
{
 2a6:   cf 93           push    r28
 2a8:   df 93           push    r29
 2aa:   cd b7           in  r28, 0x3d   ; 61
 2ac:   de b7           in  r29, 0x3e   ; 62
 2ae:   28 97           sbiw    r28, 0x08   ; 8
 2b0:   0f b6           in  r0, 0x3f    ; 63
 2b2:   f8 94           cli
 2b4:   de bf           out 0x3e, r29   ; 62
 2b6:   0f be           out 0x3f, r0    ; 63
 2b8:   cd bf           out 0x3d, r28   ; 61
     uint8_t compfreq;
      uint8_t freq[7];
        
        freq[6]=PIND;
 2ba:   80 b3           in  r24, 0x10   ; 16
 2bc:   88 87           std Y+8, r24    ; 0x08
         freq[5]=PIND;
 2be:   80 b3           in  r24, 0x10   ; 16
 2c0:   8f 83           std Y+7, r24    ; 0x07
          freq[4]=PIND;
 2c2:   80 b3           in  r24, 0x10   ; 16
 2c4:   8e 83           std Y+6, r24    ; 0x06
      
       freq[3]=PIND;
 2c6:   80 b3           in  r24, 0x10   ; 16
 2c8:   8d 83           std Y+5, r24    ; 0x05
      freq[2]=PIND;
 2ca:   80 b3           in  r24, 0x10   ; 16
 2cc:   8c 83           std Y+4, r24    ; 0x04
       freq[1]=PIND;
 2ce:   80 b3           in  r24, 0x10   ; 16
 2d0:   8b 83           std Y+3, r24    ; 0x03
        freq[0]=PIND;
 2d2:   80 b3           in  r24, 0x10   ; 16
 2d4:   8a 83           std Y+2, r24    ; 0x02
      while (1) 
    {
         
     
    uint8_t osc_num=GetOSCNum( freq  , &compfreq  );
 2d6:   be 01           movw    r22, r28
 2d8:   6f 5f           subi    r22, 0xFF   ; 255
 2da:   7f 4f           sbci    r23, 0xFF   ; 255
 2dc:   ce 01           movw    r24, r28
 2de:   02 96           adiw    r24, 0x02   ; 2
 2e0:   0e 94 18 01     call    0x230   ; 0x230 <GetOSCNum>
    
    
   
   
    
         PORTD=(uint8_t)osc_num;
 2e4:   82 bb           out 0x12, r24   ; 18
 2e6:   f7 cf           rjmp    .-18        ; 0x2d6 <main+0x30>
 
000002e8 <_exit>:
 2e8:   f8 94           cli
 
000002ea <__stop_program>:
 2ea:   ff cf           rjmp    .-2         ; 0x2ea <__stop_program>
Добавлено через 11 минут
https://web.stanford.edu/class... lAsmCB.pdf

Добавлено через 28 минут
Некорректное преобразование цифр в код , дорабатывать

Добавлено через 27 минут
Вычисление четырехбайтного числа по цифрам (частота в Герцах, деленная на 100 ) на компьютере правильн было бы делать следующим образом ( там другое кодирование):
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
uint32_t freq_fromdigits ( uint8_t freq[7])
{
 
 uint32_t result;
 
 
 
 
  
 
 
result1 =(uint16_t) freq[0];
result1+=(uint16_t) (freq[1] *10 );
result1+=(uint16_t) (freq[2]*100);
result1+=(uint16_t) (freq[3]*1000);
 result+=(uint32_t)  (freq[4] *10000);
  result+=(uint32_t) (freq[5]*100000);
 result+=(uint32_t) (freq[6]*1000000);
 
 
return result;
}
Это медленный алгоритм, попробовать через частичные произведения или иначе( с лукап-таблицей) .

Добавлено через 49 секунд
freq[і] у нас от 0 до 9 , 1 байт .
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 18:03  [ТС]
Концептуальный вариант (на Си++ может не работать ), дополнительная информация на тему в аттаче
Code
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
const uint32_t mul_array1[7][10] PROGMEM =
{
{0,1,2,3,4,5,6,7,8,9 },
{0,10,20,30,40,50,60,70,80,90 },        
{0,100,200,300,400,500,600,700,800,900 },   
{0,1000,2000,3000,4000,5000,6000,7000,8000,9000 }{0,10000,20000,30000,40000,50000,60000,70000,80000,90000 },
{0,100000,200000,300000,400000,500000,600000,700000,800000,900000 },
{0,1000000,2000000,3000000,4000000,5000000,6000000,7000000,8000000,9000000 }            
};
 
 
const uint16_t mul_array2_1 [10] PROGMEM ={0,1,2,3,4,5,6,7,8,9 };
const uint16_t mul_array2_10 [10] PROGMEM ={0,10,20,30,40,50,60,70,80,90 }; 
const uint16_t mul_array2_100 [10] PROGMEM ={0,100,200,300,400,500,600,700,800,900 };       
 
 
 
 
 
 
    //99%->990  , DACAMCOEF=990 =03DE;
    //50%->500  , DACAMCOEF=500 =01f4;
    //1%->10  , DACAMCOEF=10   =0x0A;
 
 
uint16_t   GetAMCode(uint8_t AM_COEF[2]   )
{
 
  
  
 
 
 uint16_t   result  ;
 uint16_t  table; 
  table=mul_array2_10[(uint8_t) AM_COEF[0]];
 result=(uint16_t) table; 
  table=mul_array2_100[(uint8_t) AM_COEF[1]];
 result+=(uint16_t) table;
 
  return  result ;
 
}
Миниатюры
Замена  микросхемы 1827ВЕ1-0000000 в Г4-164 на AVR -МК   Замена  микросхемы 1827ВЕ1-0000000 в Г4-164 на AVR -МК  
Вложения
Тип файла: pdf Умножение.pdf (588.1 Кб, 6 просмотров)
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 19:46  [ТС]
Для АМ проверка подпрограммы
C++
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
#include <avr/io.h>
#include <math.h>
#include <avr/pgmspace.h>
 
 
 
 
 
 
 
    //99%->990  , DACAMCOEF=990 =03DE;
    //50%->500  , DACAMCOEF=500 =01f4;
    //1%->10  , DACAMCOEF=10   =0x0A;
 
 
uint16_t   GetAMCode(uint8_t *AM_COEF    )
{
 
  
  
 
 
 uint16_t   result =0 ;
  
    
  for (uint8_t i =0; i<AM_COEF[0]; i++)
  {
     result+=10;   
  }
  for (uint8_t i =0; i<AM_COEF[1]; i++)
  {
      result+=100;
  }
  
 // table+=10;
 //result=(uint16_t) table; 
 // table=mul_array2_100[(uint8_t) AM_COEF[1]];
 //result+=(uint16_t) table;
 
  return  result ;
 
}
 
 
 
int main(void)
{
     uint16_t res ; 
      uint8_t AMcoef[2];
        
        
        AMcoef[1]=0x00; //PIND;
        AMcoef[0]=0x00; //PIND;
        
        
          //PORTD=(uint8_t)( 0x00ff&res );
         
      while (1) 
    {
         
     AMcoef[0]+=1;
     res=GetAMCode( AMcoef   );
     PORTD=res;
         
    
    
      
  
    
    
    
   
   
    
        
        
    }
}
Добавлено через 3 минуты
С зацикливанием для 7-разрядного десятичного числа это достаточно долго, можно поискать иначе , но возможно (поразрядно для цифр в цикле инкрементировать с переносом на весовое число десятичной системы , количество операций равно цифре разряда ). Для АМ у нас смещение на 1 разряд десятичной системы в кодах в сравнении с коэффициентом .

Добавлено через 1 час 3 минуты
Проблемы со счетчиком цикла и мэппингом в памяти
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * Gccapp1.c
 *
 * Created: 20.03.2020 02:09:14
 * Author : USERPC01
 */ 
 
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <math.h>
 
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
// 1kHz pin   low 1kHz (set nInform  low), high  1.25 kHz    (set nInform  high)
#define FREQ1kHz  0x00         //check for circuit 
#define FREQ1_25kHz  0x01
 
#define  HFO_FM0_1 0   //fix for sender 
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
//rule for  inverse Inform code  , for  nInform pin
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42) 
 
 
 
 
 
 
 
 
 
 
 
const uint32_t array_lowfreq [41] PROGMEM ={
6000000,5600000, 5200000,4800000 , 4480000, 4400000, 4000000, 3600000,3200000,3000000, 
2800000,2600000, 2400000,2240000,2200000,  2000000,1800000,  1600000 ,1500000,1400000,
1300000,1200000,1120000, 1100000, 1000000,900000,800000,750000 ,700000,650000,
 600000,560000, 550000,500000,450000, 400000,  280000, 200000,140000, 120000, 1000  
};
 
const uint32_t array_highfreq [41] PROGMEM ={
6399990,5999990,5599990, 5199990, 4799990,4479990,4399990,3999990,3599990,3199990,
2999990,2799990,2599990,2399990,2239990,2199990,1999990, 1799990,1599999,1499999,
1399999,1299999,1199999,1119999, 1099999,999999,899999,799999,749999,699999,
649999,599999,559999,549999,499999,449999,399999,279999,199999,139999,119999
};
 
const  uint8_t  array_osc_results[41] PROGMEM =
{
 
nOSC_G4_SUBBAND_R52_HIGH, nOSC_G3_SUBBAND_R52_HIGH, nOSC_G8_SUBBAND_R52_HIGH, nOSC_G7_SUBBAND_R52_HIGH,
nOSC_G6_SUBBAND_R52_HIGH, nOSC_G6_SUBBAND_R51_LOW, nOSC_G5_SUBBAND_R51_LOW, nOSC_G2_SUBBAND_R51_LOW,
nOSC_G1_SUBBAND_R51_LOW, nOSC_G4_SUBBAND_R50_HIGH, nOSC_G3_SUBBAND_R50_HIGH, nOSC_G8_SUBBAND_R50_HIGH,
nOSC_G7_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R49_LOW, nOSC_G5_SUBBAND_R49_LOW,
nOSC_G2_SUBBAND_R49_LOW,  nOSC_G1_SUBBAND_R49_LOW, nOSC_G4_SUBBAND_R48_HIGH, nOSC_G3_SUBBAND_R48_HIGH,
nOSC_G8_SUBBAND_R48_HIGH, nOSC_G7_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R47_LOW,
nOSC_G5_SUBBAND_R47_LOW, nOSC_G2_SUBBAND_R47_LOW, nOSC_G1_SUBBAND_R47_LOW, nOSC_G4_SUBBAND_R46_HIGH,
nOSC_G3_SUBBAND_R46_HIGH, nOSC_G8_SUBBAND_R46_HIGH, nOSC_G7_SUBBAND_R46_HIGH, nOSC_G6_SUBBAND_R46_HIGH,
nOSC_G6_SUBBAND_R45_LOW, nOSC_G5_SUBBAND_R45_LOW, nOSC_G2_SUBBAND_R45_LOW, nOSC_G1_SUBBAND_R45_LOW,
nOSC_G4_SUBBAND_R44_HIGH, nOSC_G3_SUBBAND_R43_LOW,nOSC_G8_SUBBAND_R42_HIGH,nOSC_G6_SUBBAND_R48_HIGH,
nOSC_G6_SUBBAND_R47_LOW
 
};
 
 
uint8_t array_fref[41]=
{
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz, FREQ1kHz
};
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
    uint32_t result=(uint32_t)0;
     for (uint8_t j=0x00;j<freq[6];j++)
     {
         result+=(uint32_t)1000000;
     }
     for (uint8_t j=0x00;j<freq[5];j++)
     {
     result+=(uint32_t)100000;
     }
     for (uint8_t j=0x00;j<freq[4];j++)
     {
     result+=(uint32_t)10000;
     }
     for (uint8_t j=0x00;j<freq[3];j++)
      {
      result+=(uint32_t)1000;
      }
      for (uint8_t j=0x00;j<freq[2];j++)
      {
      result+=(uint32_t)100;
      }
     for (uint8_t j=0x00;j<freq[1];j++)
     {
         result+=(uint32_t)10;
     }
 
    
    for (uint8_t j=0x00;j<freq[0];j++)
    {
    result+=1;      
    } 
 
    
 
     
    
    
 
    return result;
}
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
 
uint32_t freqvalue;
 
 
 
 
freqvalue=(uint32_t) freq_fromdigits  ( freq );
uint8_t count; 
 
 
 
  
for ( count=0x00; count<0x29; count+=1){  // 41 item
 
 
if (((uint32_t) freqvalue>=(uint32_t)array_lowfreq[(uint8_t)count] ) &&     
        
  ((uint32_t) array_highfreq [(uint8_t)count] >= (uint32_t)freqvalue ) ) 
{ 
 
 
// *compfreq=(uint8_t)array_fref[(uint8_t)count];  
 return(uint8_t) array_osc_results[(uint8_t)count];
} 
  
 
}
 
  return 0x00 ;
 
}
 
 
int main(void)
{
     uint8_t compfreq;
      uint8_t freq[7];
        
        freq[6]=PIND+2;
         freq[5]=PIND+1;
          freq[4]=PIND;
      
       freq[3]=PIND;
      freq[2]=PIND;
       freq[1]=PIND;
        freq[0]=PIND;
      while (1) 
    {
         
     
    uint8_t osc_num=GetOSCNum( freq  , &compfreq  );
    
         
    
    
      
    //data2=mul4(  data2)  ;
    
    
    
   
   
    
         PORTD=(uint8_t)osc_num;
        
        
    }
}

Можно и на инлайновом попробовать , там регистры вручную
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
20.03.2020, 20:23  [ТС]
Иногда сбоит на последних условиях (конфликт регистров, стека ) и эта программа
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
 * Gccapp1.c
 *
 * Created: 20.03.2020 02:09:14
 * Author : USERPC01
 */ 
 
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <math.h>
 
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
// 1kHz pin   low 1kHz (set nInform  low), high  1.25 kHz    (set nInform  high)
#define FREQ1kHz  0x00         //check for circuit 
#define FREQ1_25kHz  0x01
 
#define  HFO_FM0_1 0   //fix for sender 
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
//rule for  inverse Inform code  , for  nInform pin
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42) 
 
 
 
 
 
 
 
 
 
 
 
const uint32_t array_lowfreq [41] PROGMEM ={
6000000,5600000, 5200000,4800000 , 4480000, 4400000, 4000000, 3600000,3200000,3000000, 
2800000,2600000, 2400000,2240000,2200000,  2000000,1800000,  1600000 ,1500000,1400000,
1300000,1200000,1120000, 1100000, 1000000,900000,800000,750000 ,700000,650000,
 600000,560000, 550000,500000,450000, 400000,  280000, 200000,140000, 120000, 1000  
};
 
const uint32_t array_highfreq [41] PROGMEM ={
6399990,5999990,5599990, 5199990, 4799990,4479990,4399990,3999990,3599990,3199990,
2999990,2799990,2599990,2399990,2239990,2199990,1999990, 1799990,1599999,1499999,
1399999,1299999,1199999,1119999, 1099999,999999,899999,799999,749999,699999,
649999,599999,559999,549999,499999,449999,399999,279999,199999,139999,119999
};
 
const  uint8_t  array_osc_results[41] PROGMEM =
{
 
nOSC_G4_SUBBAND_R52_HIGH, nOSC_G3_SUBBAND_R52_HIGH, nOSC_G8_SUBBAND_R52_HIGH, nOSC_G7_SUBBAND_R52_HIGH,
nOSC_G6_SUBBAND_R52_HIGH, nOSC_G6_SUBBAND_R51_LOW, nOSC_G5_SUBBAND_R51_LOW, nOSC_G2_SUBBAND_R51_LOW,
nOSC_G1_SUBBAND_R51_LOW, nOSC_G4_SUBBAND_R50_HIGH, nOSC_G3_SUBBAND_R50_HIGH, nOSC_G8_SUBBAND_R50_HIGH,
nOSC_G7_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R49_LOW, nOSC_G5_SUBBAND_R49_LOW,
nOSC_G2_SUBBAND_R49_LOW,  nOSC_G1_SUBBAND_R49_LOW, nOSC_G4_SUBBAND_R48_HIGH, nOSC_G3_SUBBAND_R48_HIGH,
nOSC_G8_SUBBAND_R48_HIGH, nOSC_G7_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R47_LOW,
nOSC_G5_SUBBAND_R47_LOW, nOSC_G2_SUBBAND_R47_LOW, nOSC_G1_SUBBAND_R47_LOW, nOSC_G4_SUBBAND_R46_HIGH,
nOSC_G3_SUBBAND_R46_HIGH, nOSC_G8_SUBBAND_R46_HIGH, nOSC_G7_SUBBAND_R46_HIGH, nOSC_G6_SUBBAND_R46_HIGH,
nOSC_G6_SUBBAND_R45_LOW, nOSC_G5_SUBBAND_R45_LOW, nOSC_G2_SUBBAND_R45_LOW, nOSC_G1_SUBBAND_R45_LOW,
nOSC_G4_SUBBAND_R44_HIGH, nOSC_G3_SUBBAND_R43_LOW,nOSC_G8_SUBBAND_R42_HIGH,nOSC_G6_SUBBAND_R48_HIGH,
nOSC_G6_SUBBAND_R47_LOW
 
};
 
 
const uint8_t array_fref[41] PROGMEM =
{
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz, FREQ1kHz
};
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
    uint32_t result=(uint32_t)0;
     for (uint8_t j=0x00;j<freq[6];j++)
     {
         result+=(uint32_t)1000000;
     }
     for (uint8_t j=0x00;j<freq[5];j++)
     {
     result+=(uint32_t)100000;
     }
     for (uint8_t j=0x00;j<freq[4];j++)
     {
     result+=(uint32_t)10000;
     }
     for (uint8_t j=0x00;j<freq[3];j++)
      {
      result+=(uint32_t)1000;
      }
      for (uint8_t j=0x00;j<freq[2];j++)
      {
      result+=(uint32_t)100;
      }
     for (uint8_t j=0x00;j<freq[1];j++)
     {
         result+=(uint32_t)10;
     }
 
    
    for (uint8_t j=0x00;j<freq[0];j++)
    {
    result+=1;      
    } 
 
    
 
     
    
    
 
    return result;
}
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
 
uint32_t freqvalue;
 
 
 
 
freqvalue=(uint32_t) freq_fromdigits  ( freq );
 
/*
 
const uint32_t array_lowfreq [41] PROGMEM ={
6000000,5600000, 5200000,4800000 , 4480000, 4400000, 4000000, 3600000,3200000,3000000, 
2800000,2600000, 2400000,2240000,2200000,  2000000,1800000,  1600000 ,1500000,1400000,
1300000,1200000,1120000, 1100000, 1000000,900000,800000,750000 ,700000,650000,
 600000,560000, 550000,500000,450000, 400000,  280000, 200000,140000, 120000, 1000  
};
*/
  
 
 
 
if ((( int32_t) freqvalue>=array_lowfreq [1]) && (( int32_t) freqvalue<=array_highfreq [0] )) { *compfreq=(uint8_t)array_fref[0];  return(uint8_t) array_osc_results[0]; } 
if ((( int32_t) freqvalue>=array_lowfreq [1] ) && (( int32_t) freqvalue<=array_highfreq [1] )) { *compfreq=(uint8_t)array_fref[1];  return(uint8_t) array_osc_results[1]; }   
if ((( int32_t) freqvalue>=array_lowfreq [2] ) && (( int32_t) freqvalue<=array_highfreq [2] )) { *compfreq=(uint8_t)array_fref[2];  return(uint8_t) array_osc_results[2]; }  
if ((( int32_t) freqvalue>=array_lowfreq [3] ) && (( int32_t) freqvalue<=array_highfreq [3] )) { *compfreq=(uint8_t)array_fref[3];  return(uint8_t) array_osc_results[3]; } 
if ((( int32_t) freqvalue>=array_lowfreq [4] ) && (( int32_t) freqvalue<=array_highfreq [4] )) { *compfreq=(uint8_t)array_fref[4];  return(uint8_t) array_osc_results[4]; } 
if ((( int32_t) freqvalue>=array_lowfreq [5] ) && (( int32_t) freqvalue<=array_highfreq [5] )) { *compfreq=(uint8_t)array_fref[5];  return(uint8_t) array_osc_results[5]; } 
if ((( int32_t) freqvalue>=array_lowfreq [6] ) && (( int32_t) freqvalue<=array_highfreq [6] )) { *compfreq=(uint8_t)array_fref[6];  return(uint8_t) array_osc_results[6]; } 
if ((( int32_t) freqvalue>=array_lowfreq [7] ) && (( int32_t) freqvalue<=array_highfreq [7] )) { *compfreq=(uint8_t)array_fref[7];  return(uint8_t) array_osc_results[7]; } 
if ((( int32_t) freqvalue>=array_lowfreq [8] ) && (( int32_t) freqvalue<=array_highfreq [8] )) { *compfreq=(uint8_t)array_fref[8];  return(uint8_t) array_osc_results[8]; } 
if ((( int32_t) freqvalue>=array_lowfreq [9] ) && (( int32_t) freqvalue<=array_highfreq [9] )) { *compfreq=(uint8_t)array_fref[9];  return(uint8_t) array_osc_results[9]; } 
 
if ((( int32_t) freqvalue>=array_lowfreq [10] ) && (( int32_t) freqvalue<=array_highfreq [10] )) { *compfreq=(uint8_t)array_fref[10];  return(uint8_t) array_osc_results[10]; } 
if ((( int32_t) freqvalue>=array_lowfreq [11] ) && (( int32_t) freqvalue<=array_highfreq [11] )) { *compfreq=(uint8_t)array_fref[11];  return(uint8_t) array_osc_results[11]; }   
if ((( int32_t) freqvalue>=array_lowfreq [12] ) && (( int32_t) freqvalue<=array_highfreq [12] )) { *compfreq=(uint8_t)array_fref[12];  return(uint8_t) array_osc_results[12]; }  
if ((( int32_t) freqvalue>=array_lowfreq [13] ) && (( int32_t) freqvalue<=array_highfreq [13] )) { *compfreq=(uint8_t)array_fref[13];  return(uint8_t) array_osc_results[13]; } 
if ((( int32_t) freqvalue>=array_lowfreq [14] ) && (( int32_t) freqvalue<=array_highfreq [14] )) { *compfreq=(uint8_t)array_fref[14];  return(uint8_t) array_osc_results[14]; } 
if ((( int32_t) freqvalue>=array_lowfreq [15] ) && (( int32_t) freqvalue<=array_highfreq [15] )) { *compfreq=(uint8_t)array_fref[15];  return(uint8_t) array_osc_results[15]; } 
if ((( int32_t) freqvalue>=array_lowfreq [16] ) && (( int32_t) freqvalue<=array_highfreq [16] )) { *compfreq=(uint8_t)array_fref[16];  return(uint8_t) array_osc_results[16]; } 
if ((( int32_t) freqvalue>=array_lowfreq [17] ) && (( int32_t) freqvalue<=array_highfreq [17] )) { *compfreq=(uint8_t)array_fref[17];  return(uint8_t) array_osc_results[17]; } 
if ((( int32_t) freqvalue>=array_lowfreq [18] ) && (( int32_t) freqvalue<=array_highfreq [18] )) { *compfreq=(uint8_t)array_fref[18];  return(uint8_t) array_osc_results[18]; } 
if ((( int32_t) freqvalue>=array_lowfreq [19] ) && (( int32_t) freqvalue<=array_highfreq [19] )) { *compfreq=(uint8_t)array_fref[19];  return(uint8_t) array_osc_results[19]; }     
    
if ((( int32_t) freqvalue>=array_lowfreq [20] ) && (( int32_t) freqvalue<=array_highfreq [20] )) { *compfreq=(uint8_t)array_fref[20];  return(uint8_t) array_osc_results[20]; } 
if ((( int32_t) freqvalue>=array_lowfreq [21] ) && (( int32_t) freqvalue<=array_highfreq [21] )) { *compfreq=(uint8_t)array_fref[21];  return(uint8_t) array_osc_results[21]; }   
if ((( int32_t) freqvalue>=array_lowfreq [22] ) && (( int32_t) freqvalue<=array_highfreq [22] )) { *compfreq=(uint8_t)array_fref[22];  return(uint8_t) array_osc_results[22]; }  
if ((( int32_t) freqvalue>=array_lowfreq [23] ) && (( int32_t) freqvalue<=array_highfreq [23] )) { *compfreq=(uint8_t)array_fref[23];  return(uint8_t) array_osc_results[23]; } 
if ((( int32_t) freqvalue>=array_lowfreq [24] ) && (( int32_t) freqvalue<=array_highfreq [24] )) { *compfreq=(uint8_t)array_fref[24];  return(uint8_t) array_osc_results[24]; } 
if ((( int32_t) freqvalue>=array_lowfreq [25] ) && (( int32_t) freqvalue<=array_highfreq [25] )) { *compfreq=(uint8_t)array_fref[25];  return(uint8_t) array_osc_results[25]; } 
if ((( int32_t) freqvalue>=array_lowfreq [26] ) && (( int32_t) freqvalue<=array_highfreq [26] )) { *compfreq=(uint8_t)array_fref[26];  return(uint8_t) array_osc_results[26]; } 
if ((( int32_t) freqvalue>=array_lowfreq [27] ) && (( int32_t) freqvalue<=array_highfreq [27] )) { *compfreq=(uint8_t)array_fref[27];  return(uint8_t) array_osc_results[27]; } 
if ((( int32_t) freqvalue>=array_lowfreq [28] ) && (( int32_t) freqvalue<=array_highfreq [28] )) { *compfreq=(uint8_t)array_fref[28];  return(uint8_t) array_osc_results[28]; } 
if ((( int32_t) freqvalue>=array_lowfreq [29] ) && (( int32_t) freqvalue<=array_highfreq [29] )) { *compfreq=(uint8_t)array_fref[29];  return(uint8_t) array_osc_results[29]; } 
 
 
if ((( int32_t) freqvalue>=array_lowfreq [30] ) && (( int32_t) freqvalue<=array_highfreq [30] )) { *compfreq=(uint8_t)array_fref[30];  return(uint8_t) array_osc_results[30]; } 
if ((( int32_t) freqvalue>=array_lowfreq [31] ) && (( int32_t) freqvalue<=array_highfreq [31] )) { *compfreq=(uint8_t)array_fref[31];  return(uint8_t) array_osc_results[31]; }   
if ((( int32_t) freqvalue>=array_lowfreq [32] ) && (( int32_t) freqvalue<=array_highfreq [32] )) { *compfreq=(uint8_t)array_fref[32];  return(uint8_t) array_osc_results[32]; }  
if ((( int32_t) freqvalue>=array_lowfreq [33] ) && (( int32_t) freqvalue<=array_highfreq [33] )) { *compfreq=(uint8_t)array_fref[33];  return(uint8_t) array_osc_results[33]; } 
if ((( int32_t) freqvalue>=array_lowfreq [34] ) && (( int32_t) freqvalue<=array_highfreq [34] )) { *compfreq=(uint8_t)array_fref[34];  return(uint8_t) array_osc_results[34]; } 
if ((( int32_t) freqvalue>=array_lowfreq [35] ) && (( int32_t) freqvalue<=array_highfreq [35] )) { *compfreq=(uint8_t)array_fref[35];  return(uint8_t) array_osc_results[35]; } 
if ((( int32_t) freqvalue>=array_lowfreq [36] ) && (( int32_t) freqvalue<=array_highfreq [36] )) { *compfreq=(uint8_t)array_fref[36];  return(uint8_t) array_osc_results[36]; } 
if ((( int32_t) freqvalue>=array_lowfreq [37] ) && (( int32_t) freqvalue<=array_highfreq [37] )) { *compfreq=(uint8_t)array_fref[37];  return(uint8_t) array_osc_results[37]; } 
if ((( int32_t) freqvalue>=array_lowfreq [38] ) && (( int32_t) freqvalue<=array_highfreq [38] )) { *compfreq=(uint8_t)array_fref[38];  return(uint8_t) array_osc_results[38]; } 
if ((( int32_t) freqvalue>=array_lowfreq [39] ) && (( int32_t) freqvalue<=array_highfreq [39] )) { *compfreq=(uint8_t)array_fref[39];  return(uint8_t) array_osc_results[39]; }  
if ((( int32_t) freqvalue>=array_lowfreq [40] ) && (( int32_t) freqvalue<=array_highfreq [40] )) { *compfreq=(uint8_t)array_fref[40];  return(uint8_t) array_osc_results[41]; } 
if ((( int32_t) freqvalue>=array_lowfreq [41] ) && (( int32_t) freqvalue<=array_highfreq [41] )) { *compfreq=(uint8_t)array_fref[41];  return(uint8_t) array_osc_results[39]; }     
        
  return 0x00 ;
 
}
 
 
int main(void)
{
     uint8_t compfreq;
      uint8_t freq[7];
        
        freq[6]=PIND+1;
         freq[5]=PIND+1;
          freq[4]=PIND;
      
       freq[3]=PIND;
      freq[2]=PIND;
       freq[1]=PIND;
        freq[0]=PIND;
      while (1) 
    {
         
     
    uint8_t osc_num=GetOSCNum( freq  , &compfreq  );
          freq[6]=0;
          freq[5]=0;
          freq[4]=0;
      
         freq[3]=1;
      freq[2]=5;
       freq[1]=0;
        freq[0]=0 ;
        
  osc_num=GetOSCNum( freq  , &compfreq  );
    
    
     
   
    
         PORTD=(uint8_t)osc_num;
        
        
    }
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
21.03.2020, 00:00  [ТС]
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*
 * Gccapp1.c
 *
 * Created: 20.03.2020 02:09:14
 * Author : USERPC01
 */ 
 
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <math.h>
 
/* 
 
1                        2                            4
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G4 600-639.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G3   560-599.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G8   520-559.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G7   480-519.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G6   440-479.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G5  400-440.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G2    360-399.999
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)   G1   320-359.999
 
for nInform 
(1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G4 600-639.999
(0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    G3   560-599.999
(1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G8   520-559.999
(0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    G7   480-519.999
(1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G6   440-479.999
(0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    G5  400-440.999
(1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    G2    360-399.999
(0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   G1   320-359.999
 
on the Inform Bus  (7 D2.1)    , for nInform use inverted data 
 
 
(First sent)   1               2          3         4              5          6        7         8   (Last sent bit )
           FM1/10         G1         G2       G4         H/L      B1      B2        B4 
 
R52  1     (0<<HFO_FM0_1) | (G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(0 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL )| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)|(0<<HFO_B2)| (1 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(G1<<HFO_G1)| (G2<<HFO_G2)| (G4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
 
 
R52  1     (0<<HFO_FM0_1) | (nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)           
R51  1     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4) 
R50  2     (0<<HFO_FM0_1) |(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R49  2     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R48  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R47  3     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) 
R46  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R45  4     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R44  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
R43  5     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (0<<HFO_HL)| (0<<HFO_B1)|(1<<HFO_B2)| (0 <<HFO_B4) 
R42  6     (0<<HFO_FM0_1)|(nG1<<HFO_G1)| (nG2<<HFO_G2)| (nG4<<HFO_G4)| (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) 
 
 
 
*/
 
// 1kHz pin   low 1kHz (set nInform  low), high  1.25 kHz    (set nInform  high)
#define FREQ1kHz  0x00         //check for circuit 
#define FREQ1_25kHz  0x01
 
#define  HFO_FM0_1 0   //fix for sender 
#define  HFO_G1 1
#define  HFO_G2 2
#define  HFO_G4 3
#define  HFO_HL 4
#define  HFO_B1 5
#define  HFO_B2 6
#define  HFO_B4 7
 
 
 
#define nOSC_G4 (1<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G4 600-639.999
#define nOSC_G3 (0<<HFO_G1)|(1<<HFO_G2) | (1<<HFO_G4)    //G3   560-599.999
#define nOSC_G8 (1<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G8   520-559.999
#define nOSC_G7 (0<<HFO_G1)|(0<<HFO_G2) | (1<<HFO_G4)    //G7   480-519.999
#define nOSC_G6 (1<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G6   440-479.999
#define nOSC_G5 (0<<HFO_G1)|(1<<HFO_G2) | (0<<HFO_G4)    //G5  400-440.999
#define nOSC_G2 (1<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)    //G2    360-399.999
#define nOSC_G1 (0<<HFO_G1)|(0<<HFO_G2) | (0<<HFO_G4)   //G1   320-359.999
 
#define  nFILTER_R52         (1<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)  //1          
#define  nFILTER_R51        (0<<HFO_HL)| (0<<HFO_B1)| (1<<HFO_B2)|(1 <<HFO_B4)   //1
#define  nFILTER_R50         (1<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R49        (0<<HFO_HL)| (1<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //2
#define  nFILTER_R48         (1<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R47         (0<<HFO_HL)| (0<<HFO_B1)| (0<<HFO_B2)|(1 <<HFO_B4) //3
#define  nFILTER_R46         (1<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R45         (0<<HFO_HL)| (1<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //4
#define  nFILTER_R44        (1<<HFO_HL )| (0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R43        (0<<HFO_HL)|(0<<HFO_B1)|(1<<HFO_B2)|(0 <<HFO_B4) //5
#define  nFILTER_R42        (1<<HFO_HL)|(0<<HFO_B1)| (1<<HFO_B2)|(0 <<HFO_B4) //6
 
//rule for  inverse Inform code  , for  nInform pin
#define  nOSC_G4_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)
#define  nOSC_G3_SUBBAND_R52_HIGH  (nOSC_G3| nFILTER_R52)
#define  nOSC_G8_SUBBAND_R52_HIGH  (nOSC_G8| nFILTER_R52)
#define  nOSC_G7_SUBBAND_R52_HIGH  (nOSC_G4| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R52_HIGH  (nOSC_G6| nFILTER_R52)  
#define  nOSC_G6_SUBBAND_R51_LOW   (nOSC_G6| nFILTER_R51)  
#define  nOSC_G5_SUBBAND_R51_LOW   (nOSC_G5| nFILTER_R51)  
#define  nOSC_G2_SUBBAND_R51_LOW   (nOSC_G2| nFILTER_R51)    
#define  nOSC_G1_SUBBAND_R51_LOW   (nOSC_G1| nFILTER_R51)  
 
#define  nOSC_G4_SUBBAND_R50_HIGH  (nOSC_G4| nFILTER_R50) 
#define  nOSC_G3_SUBBAND_R50_HIGH   (nOSC_G3| nFILTER_R50)  
#define  nOSC_G8_SUBBAND_R50_HIGH    (nOSC_G8| nFILTER_R50) 
#define  nOSC_G7_SUBBAND_R50_HIGH    (nOSC_G7| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R50_HIGH    (nOSC_G6| nFILTER_R50) 
#define  nOSC_G6_SUBBAND_R49_LOW     (nOSC_G6| nFILTER_R49) 
#define  nOSC_G5_SUBBAND_R49_LOW    (nOSC_G5| nFILTER_R49) 
#define  nOSC_G2_SUBBAND_R49_LOW    (nOSC_G2| nFILTER_R49) 
#define  nOSC_G1_SUBBAND_R49_LOW    (nOSC_G1| nFILTER_R49) 
 
#define  nOSC_G4_SUBBAND_R48_HIGH  (nOSC_G4| nFILTER_R48) 
#define  nOSC_G3_SUBBAND_R48_HIGH  (nOSC_G3| nFILTER_R48)   
#define  nOSC_G8_SUBBAND_R48_HIGH  (nOSC_G8| nFILTER_R48) 
#define  nOSC_G7_SUBBAND_R48_HIGH  (nOSC_G7| nFILTER_R48)  
#define  nOSC_G6_SUBBAND_R48_HIGH  (nOSC_G6| nFILTER_R48)   
#define   nOSC_G6_SUBBAND_R47_LOW  (nOSC_G6| nFILTER_R47) 
#define nOSC_G5_SUBBAND_R47_LOW    (nOSC_G5| nFILTER_R47)  
#define nOSC_G2_SUBBAND_R47_LOW    (nOSC_G2| nFILTER_R47)  
#define nOSC_G1_SUBBAND_R47_LOW    (nOSC_G1| nFILTER_R48)  
 
#define nOSC_G4_SUBBAND_R46_HIGH (nOSC_G4| nFILTER_R46) 
#define nOSC_G3_SUBBAND_R46_HIGH (nOSC_G3| nFILTER_R46) 
#define nOSC_G8_SUBBAND_R46_HIGH (nOSC_G8| nFILTER_R46) 
#define nOSC_G7_SUBBAND_R46_HIGH (nOSC_G7| nFILTER_R46) 
#define nOSC_G6_SUBBAND_R46_HIGH (nOSC_G6| nFILTER_R46)   
#define  nOSC_G6_SUBBAND_R45_LOW (nOSC_G6| nFILTER_R45)    
#define nOSC_G5_SUBBAND_R45_LOW  (nOSC_G5| nFILTER_R45)      
#define nOSC_G2_SUBBAND_R45_LOW  (nOSC_G2| nFILTER_R45)       
#define nOSC_G1_SUBBAND_R45_LOW  (nOSC_G1| nFILTER_R45)    
 
 
#define nOSC_G4_SUBBAND_R44_HIGH   (nOSC_G4| nFILTER_R44) 
#define nOSC_G3_SUBBAND_R43_LOW    (nOSC_G3| nFILTER_R43) 
#define nOSC_G8_SUBBAND_R42_HIGH   (nOSC_G8| nFILTER_R42) 
 
 
 
 
 
 
 
 
 
 
 
const uint32_t array_lowfreq [41] PROGMEM ={
6000000,5600000, 5200000,4800000 , 4480000, 4400000, 4000000, 3600000,3200000,3000000, 
2800000,2600000, 2400000,2240000,2200000,  2000000,1800000,  1600000 ,1500000,1400000,
1300000,1200000,1120000, 1100000, 1000000,900000,800000,750000 ,700000,650000,
 600000,560000, 550000,500000,450000, 400000,  280000, 200000,140000, 120000, 1000  
};
 
const uint32_t array_highfreq [41] PROGMEM ={
6399990,5999990,5599990, 5199990, 4799990,4479990,4399990,3999990,3599990,3199990,
2999990,2799990,2599990,2399990,2239990,2199990,1999990, 1799990,1599999,1499999,
1399999,1299999,1199999,1119999, 1099999,999999,899999,799999,749999,699999,
649999,599999,559999,549999,499999,449999,399999,279999,199999,139999,119999
};
 
const  uint8_t  array_osc_results[41] PROGMEM =
{
 
nOSC_G4_SUBBAND_R52_HIGH, nOSC_G3_SUBBAND_R52_HIGH, nOSC_G8_SUBBAND_R52_HIGH, nOSC_G7_SUBBAND_R52_HIGH,
nOSC_G6_SUBBAND_R52_HIGH, nOSC_G6_SUBBAND_R51_LOW, nOSC_G5_SUBBAND_R51_LOW, nOSC_G2_SUBBAND_R51_LOW,
nOSC_G1_SUBBAND_R51_LOW, nOSC_G4_SUBBAND_R50_HIGH, nOSC_G3_SUBBAND_R50_HIGH, nOSC_G8_SUBBAND_R50_HIGH,
nOSC_G7_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R50_HIGH, nOSC_G6_SUBBAND_R49_LOW, nOSC_G5_SUBBAND_R49_LOW,
nOSC_G2_SUBBAND_R49_LOW,  nOSC_G1_SUBBAND_R49_LOW, nOSC_G4_SUBBAND_R48_HIGH, nOSC_G3_SUBBAND_R48_HIGH,
nOSC_G8_SUBBAND_R48_HIGH, nOSC_G7_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R48_HIGH, nOSC_G6_SUBBAND_R47_LOW,
nOSC_G5_SUBBAND_R47_LOW, nOSC_G2_SUBBAND_R47_LOW, nOSC_G1_SUBBAND_R47_LOW, nOSC_G4_SUBBAND_R46_HIGH,
nOSC_G3_SUBBAND_R46_HIGH, nOSC_G8_SUBBAND_R46_HIGH, nOSC_G7_SUBBAND_R46_HIGH, nOSC_G6_SUBBAND_R46_HIGH,
nOSC_G6_SUBBAND_R45_LOW, nOSC_G5_SUBBAND_R45_LOW, nOSC_G2_SUBBAND_R45_LOW, nOSC_G1_SUBBAND_R45_LOW,
nOSC_G4_SUBBAND_R44_HIGH, nOSC_G3_SUBBAND_R43_LOW,nOSC_G8_SUBBAND_R42_HIGH,nOSC_G6_SUBBAND_R48_HIGH,
nOSC_G6_SUBBAND_R47_LOW
 
};
 
 
const uint8_t array_fref[41] PROGMEM =
{
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz, FREQ1_25kHz,
FREQ1_25kHz, FREQ1_25kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,FREQ1kHz,
FREQ1kHz,FREQ1kHz,FREQ1kHz, FREQ1kHz
};
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
    uint32_t result=(uint32_t)0;
     for (uint8_t j=0x00;j<freq[6];j++)
     {
         result+=(uint32_t)1000000;
     }
     for (uint8_t j=0x00;j<freq[5];j++)
     {
     result+=(uint32_t)100000;
     }
     for (uint8_t j=0x00;j<freq[4];j++)
     {
     result+=(uint32_t)10000;
     }
     for (uint8_t j=0x00;j<freq[3];j++)
      {
      result+=(uint32_t)1000;
      }
      for (uint8_t j=0x00;j<freq[2];j++)
      {
      result+=(uint32_t)100;
      }
     for (uint8_t j=0x00;j<freq[1];j++)
     {
         result+=(uint32_t)10;
     }
 
    
    for (uint8_t j=0x00;j<freq[0];j++)
    {
    result+=1;      
    } 
 
    
 
     
    
    
 
    return result;
}
 
uint8_t   GetOSCNum(uint8_t freq[7] , uint8_t *compfreq  )
{
 
uint32_t freqvalue;
 
 
 
 
freqvalue=(uint32_t) freq_fromdigits  ( freq );
 
 
  
 
        
if ((( uint32_t) freqvalue>=6000000) && (( uint32_t) freqvalue<=6399990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t)nOSC_G4_SUBBAND_R52_HIGH; } 
if ((( uint32_t) freqvalue>=5600000 ) && (( uint32_t) freqvalue<=5999990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t)nOSC_G3_SUBBAND_R52_HIGH; }   
if ((( uint32_t) freqvalue>=5200000 ) && (( uint32_t) freqvalue<=5599990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t)nOSC_G8_SUBBAND_R52_HIGH; }  
if ((( uint32_t) freqvalue>=4800000 ) && (( uint32_t) freqvalue<=5199990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t)nOSC_G7_SUBBAND_R52_HIGH; } 
if ((( uint32_t) freqvalue>=4480000 ) && (( uint32_t) freqvalue<=4799990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t)nOSC_G6_SUBBAND_R52_HIGH; } 
if ((( uint32_t) freqvalue>=4400000 ) && (( uint32_t) freqvalue<=4479990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G6_SUBBAND_R51_LOW; } 
if ((( uint32_t) freqvalue>=4000000) && (( uint32_t) freqvalue<=4399990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G5_SUBBAND_R51_LOW; } 
if ((( uint32_t) freqvalue>=3600000 ) && (( uint32_t) freqvalue<=3999990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G2_SUBBAND_R51_LOW; } 
if ((( uint32_t) freqvalue>=3200000 ) && (( uint32_t) freqvalue<=3599990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G1_SUBBAND_R51_LOW; } 
if ((( uint32_t) freqvalue>=3000000 ) && (( uint32_t) freqvalue<=3199990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G4_SUBBAND_R50_HIGH; } 
 
if ((( uint32_t) freqvalue>=2800000 ) && (( uint32_t) freqvalue<=2999990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G3_SUBBAND_R50_HIGH; } 
if ((( uint32_t) freqvalue>=2600000 ) && (( uint32_t) freqvalue<=2799990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G8_SUBBAND_R50_HIGH; }   
if ((( uint32_t) freqvalue>=2400000) && (( uint32_t) freqvalue<=2599990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t)  nOSC_G7_SUBBAND_R50_HIGH; }  
if ((( uint32_t) freqvalue>=2240000 ) && (( uint32_t) freqvalue<=2399990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G6_SUBBAND_R50_HIGH; } 
if ((( uint32_t) freqvalue>=2200000 ) && (( uint32_t) freqvalue<=2239990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G6_SUBBAND_R49_LOW ; } 
if ((( uint32_t) freqvalue>=2000000 ) && (( uint32_t) freqvalue<=2199990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G5_SUBBAND_R49_LOW; } 
if ((( uint32_t) freqvalue>=1800000 ) && (( uint32_t) freqvalue<=1999990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G2_SUBBAND_R49_LOW; } 
if ((( uint32_t) freqvalue>=1600000 ) && (( uint32_t) freqvalue<=1799990 )) { *compfreq=(uint8_t)FREQ1_25kHz;  return(uint8_t) nOSC_G1_SUBBAND_R49_LOW; } 
if ((( uint32_t) freqvalue>=1500000 ) && (( uint32_t) freqvalue<=1599999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G4_SUBBAND_R48_HIGH; } 
if ((( uint32_t) freqvalue>=1400000 ) && (( uint32_t) freqvalue<=1499999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t)  nOSC_G3_SUBBAND_R48_HIGH; }    
    
if ((( uint32_t) freqvalue>=1300000 ) && (( uint32_t) freqvalue<=1399999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G8_SUBBAND_R48_HIGH; } 
if ((( uint32_t) freqvalue>=1200000 ) && (( uint32_t) freqvalue<=1299999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G7_SUBBAND_R48_HIGH; }   
if ((( uint32_t) freqvalue>=1120000 ) && (( uint32_t) freqvalue<=1199999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G6_SUBBAND_R48_HIGH; }  
if ((( uint32_t) freqvalue>=1100000 ) && (( uint32_t) freqvalue<=1119999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G6_SUBBAND_R47_LOW; } 
if ((( uint32_t) freqvalue>=1000000 ) && (( uint32_t) freqvalue<=1099999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G5_SUBBAND_R47_LOW; } 
if ((( uint32_t) freqvalue>=900000 ) && (( uint32_t) freqvalue<=999999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G2_SUBBAND_R47_LOW; } 
if ((( uint32_t) freqvalue>=800000 ) && (( uint32_t) freqvalue<=899999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G1_SUBBAND_R47_LOW; } 
if ((( uint32_t) freqvalue>=750000 ) && (( uint32_t) freqvalue<=799999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G4_SUBBAND_R46_HIGH; } 
if ((( uint32_t) freqvalue>=700000 ) && (( uint32_t) freqvalue<=749999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G3_SUBBAND_R46_HIGH; } 
if ((( uint32_t) freqvalue>=650000 ) && (( uint32_t) freqvalue<=699999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G8_SUBBAND_R46_HIGH; } 
 
 
if ((( uint32_t) freqvalue>=600000 ) && (( uint32_t) freqvalue<=649999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G7_SUBBAND_R46_HIGH; } 
if ((( uint32_t) freqvalue>=560000 ) && (( uint32_t) freqvalue<=599999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G6_SUBBAND_R46_HIGH; }   
if ((( uint32_t) freqvalue>=550000 ) && (( uint32_t) freqvalue<=559999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G6_SUBBAND_R45_LOW; }  
if ((( uint32_t) freqvalue>=500000 ) && (( uint32_t) freqvalue<=549999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G5_SUBBAND_R45_LOW; } 
if ((( uint32_t) freqvalue>=450000 ) && (( uint32_t) freqvalue<=499999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G2_SUBBAND_R45_LOW; } 
if ((( uint32_t) freqvalue>=400000 ) && (( uint32_t) freqvalue<=449999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G1_SUBBAND_R45_LOW; } 
if ((( uint32_t) freqvalue>=280000 ) && (( uint32_t) freqvalue<=399999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G4_SUBBAND_R44_HIGH; } 
if ((( uint32_t) freqvalue>=200000 ) && (( uint32_t) freqvalue<=279999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G3_SUBBAND_R43_LOW; } 
if ((( uint32_t) freqvalue>=140000 ) && (( uint32_t) freqvalue<=199999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G8_SUBBAND_R42_HIGH; } 
if ((( uint32_t) freqvalue>= 120000 ) && (( uint32_t) freqvalue<=139999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G6_SUBBAND_R48_HIGH; }  
if ((( uint32_t) freqvalue>=1000 ) && (( uint32_t) freqvalue<=119999 )) { *compfreq=(uint8_t)FREQ1kHz;  return(uint8_t) nOSC_G6_SUBBAND_R47_LOW; } 
            
        
  return 0x00 ;
 
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
int main(void)
{
     uint8_t compfreq;
      uint8_t freq[7];
       uint8_t osc_num; 
     
      while (1) 
    {
         
        freq[6]= 1;
         freq[5]= 1;
          freq[4]=0;
      
       freq[3]=0;
      freq[2]=0;
       freq[1]=0;
        freq[0]=0;
        
     osc_num=GetOSCNum( freq  , &compfreq  );
          freq[6]=0;
          freq[5]=1;
          freq[4]=2;
      
         freq[3]=1;
      freq[2]=5;
       freq[1]=0;
        freq[0]=0 ;
        
  osc_num=GetOSCNum( freq  , &compfreq  );
    
    
     
   
    
         PORTD=(uint8_t)osc_num;
        
        
    }
}
Добавлено через 1 минуту
Code
1
2
3
4
5
6
7
8
   text    data     bss     dec     hex filename
           1860       0       0    1860     744 Gccapp1.elf
    Done executing task "RunCompilerTask".
    Task "RunOutputFileVerifyTask"
                Program Memory Usage    :   1860 bytes   11,4 % Full
                Data Memory Usage       :   0 bytes   0,0 % Full
    Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "Gccapp1.cproj"
Добавлено через 2 часа 12 минут
Преобразование кодов коэффициента ДДПКД в цифры кода для отправки в ДПКД можно организовать на основе принципа, аналогичного
(с устранением проблем типов, "лонговости" ,возможно по альтернативному алгоритму , в старшем байте от 0 до 15 , в остальных от 0 до 9 ) , число согласовать по адекватности с ТТЛ логикой и шиной Информ и инвертором перед ней для вывода 34
C++
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
 
uint8_t  *DVDC_DIGITS(uint32_t Kdvdc)
{
uint8_t Digits[6];
//160 000 0  *2 /5 =640 000‬->  байты  (MSB) [0][6][4] [0][0][0] (LSB)
//159 999 9 *4/4=159 999 9‬->  байты  (MSB) [15][9][9] [9][9][9] (LSB)  00 *18 69 FF= ‬>F 9 9 9 9 9
 
    temp = Kdvdc ;   // make into binary degrees  value
 
uint8_t     Digits[5] =(uint8_t)div32(temp,100000 );   //        (uint8_t) temp/100000;   div32  , Dig_5=(uint8_t) 159999/100000  = 15  =0x0f
    temp  =  mod32(temp,100000 );                         //  temp - (Dig_5 * 100000);    temp%100000, mod32 , temp=159999-1 500 000‬=99 999
 
uint8_t    Digits[4] =(uint8_t)div32(temp,10000  );      //(uint8_t) temp/10000;  div32  ,  Dig_4=(uint8_t)99 999/10000=9 =0x09
    temp  = mod32(temp,10000  );                             // temp%10000 ,  mod32    temp  =99 999 - 90000=9 999
 
uint8_t    Digits[3] =(uint8_t)div32(temp,1000   );   // temp/1000;  div32  ,  Dig_3=(uint8_t) 9 999/1000 =9  =0x09
   temp  =mod32(temp,1000   );                            // temp - (Dig_3 * 1000);   temp%1000  mod32    temp  = 9 999 - 9000 = 999
 
uint8_t    Digits[2] =(uint8_t)div32(temp,100    );  //  temp/100;   div32  ,  Dig_2=(uint8_t)  999/100  =9    =0x09
   temp  =mod32(temp,100    );                           // temp - (Dig_2 * 100);   temp%100  mod32    temp  =  999 - 900  =  99 
 
uint8_t    Digits[1] =(uint8_t)div32(temp,10     );  // temp/10;  div32  ,  Dig_2=(uint8_t)  99/10  =9 =0x09
   temp  = mod32(temp,10     );                          // temp - (Dig_1 * 10);   temp%10  div32  , temp  =  99  - 90  =  9 
 
uint8_t    Digits[0] =(uint8_t) temp;                        //temp  =    9   =0x09
 
  
return  Digits;
 
 
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
21.03.2020, 00:30  [ТС]
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
uint32_t freq_fromdigits_div10( uint8_t freq[7])
{
uint32_t result=0;
result  =(uint32_t) freq[1];
result +=(uint32_t) (freq[2] *10 );
result +=(uint32_t) (freq[3]*100);
result +=(uint32_t) (freq[4]*1000);
 result+=(uint32_t)  (freq[5] *10000);
  result+=(uint32_t) (freq[6]*100000);
 return result;
}
 
 
uint32_t freq_fromdigits ( uint8_t freq[7])
{
uint32_t  result=0;
 
result  =(uint32_t) freq[0];
result +=(uint32_t) (freq[1] *10 );
result +=(uint32_t) (freq[2]*100);
result +=(uint32_t) (freq[3]*1000);
 result+=(uint32_t)  (freq[4] *10000);
  result+=(uint32_t) (freq[5]*100000);
 result+=(uint32_t) (freq[6]*1000000); 
 return result;
}
 
 
 
 
uint8_t * GetCoeffDPKD(uint8_t freq[7]  )
{
 
 
//Kddpkd_num= freq*Kd/5)  for f= 1.25 kHz
//Kddpkd_num=freq*Kd/4  for f=1 kHz
  
   //3200000- 6399990
 
 
uint32_t freqvalue;
 
 
freqvalue= freq_fromdigits_div10  ( freq ); 
if ((( uint32_t) freqvalue>=448000) && (( uint32_t) freqvalue<=639999 )) 
{
// Kdp=1   , fit to f*10 ,R52 , fcomp=1.25kHz 
//Kdp =1;   Kdpkd_div=5;  
//Kddpkd=  freq/5;         ((uint32_t)(freq_fromdigits_div10  )     <<1);  
//subband=SUBBAND_HIGH   ; 
                                            
// *compfreq=FREQ1_25kHz ;   
 KDVDC=  ((uint32_t)(freqvalue) <<1);       return  DVDC_DIGITS(KDVDC);
}
 
 
if ((( uint32_t) freqvalue>=320000) && (( uint32_t) freqvalue<=447999 )) 
{ 
// Kdp=1  , fit to f*10 ,R51, fcomp=1.25kHz
//Kdp =1; Kdpkd_div=5;  
//Kddpkd=  freq/5;   ((uint32_t)(freq_fromdigits_div10  )     <<1);         
//subband=SUBBAND_LOW   ;   
                                                                             
//*compfreq=FREQ1_25kHz ;  
 KDVDC=  ((uint32_t)(freqvalue ) <<1);    return  DVDC_DIGITS(KDVDC);
}
  
 if ((( uint32_t) freqvalue>=224000) && (( uint32_t) freqvalue<=319999 ))                                              
{
 // Kdp=2  R50, fcomp=1.25kHz  Kdp=2; 
 //Kdpkd_div=5;    
 // Kddpkd=  (freq*2 /5);  ((uint32_t)(freq_fromdigits_div10  )    <<2);      //check for uint32_t compatibility without clipping   
 //subband=SUBBAND_HIGH   ;   
 //*compfreq=FREQ1_25kHz   ; 
KDVDC=  ((uint32_t)(freqvalue) <<2);     return  DVDC_DIGITS(KDVDC);
}
 
 if ((( uint32_t) freqvalue>=160000) && (( uint32_t) freqvalue<=223999 ))     
{
                                              
 // Kdp=2      , fit to f*10 , R49, fcomp=1.25kHz
 //Kdp=2; Kdpkd_div=5;  
 //Kddpkd=  (freq*2 /5);   ((uint32_t)(freq_fromdigits_div10  )  <<2);            //check for uint32_t compatibility without clipping      
 //subband=SUBBAND_LOW   ;   
// *compfreq=FREQ1_25kHz ; 
KDVDC=  ((uint32_t)(freqvalue ) <<2);    return  DVDC_DIGITS(KDVDC);
}
 
/*  *****************************************************   */
freqvalue= freq_fromdigits  ( freq ); 
 
 if ((( uint32_t) freqvalue>=1120000) && (( uint32_t) freqvalue<=1599999 )) 
{    
 // Kdp=4      , fit to f  , R48, fcomp=1 kHz
//Kdp=4; Kdpkd_div=4;  
//Kddpkd=  freq ;    ((uint32_t)(freq_fromdigits  )  );  
//subband=SUBBAND_HIGH   ;       
//*compfreq=FREQ1kHz                                       
KDVDC=  ((uint32_t)(freqvalue  )  );        return  DVDC_DIGITS(KDVDC);                       
}
 
if ((( uint32_t) freqvalue>=800000) && (( uint32_t) freqvalue<=1119999 )) 
{
  // Kdp=4 R47, fcomp=1 kHz
//Kdp=4; Kdpkd_div=4;  
//Kddpkd=  freq ;  ((freq_fromdigits  )  );  
 //subband=SUBBAND_LOW   ;       
//*compfreq=FREQ1kHz                                       
KDVDC=  ((uint32_t)(freqvalue )  );    return  DVDC_DIGITS(KDVDC);                        
                                       
}
 
if ((( uint32_t) freqvalue>=560000) && (( uint32_t) freqvalue<=799999 ))  
 {
  // Kdp=8 ,R46, fcomp=1 kHz
//Kdp=8;  Kdpkd_div=4;  
//    Kddpkd=  freq*2 ;     ((freq_fromdigits  )    <<1);  
//subband=SUBBAND_HIGH  ;       
//*compfreq=FREQ1kHz                                       
KDVDC=  ((uint32_t)(freqvalue<<1)  );    return  DVDC_DIGITS(KDVDC);
}
 
 if ((( uint32_t) freqvalue>=400000) && (( uint32_t) freqvalue<=559999 ))  
 {
// Kdp=8, R45, fcomp=1 kHz
//Kdp=8; Kdpkd_div=4;  
//Kddpkd=  freq*2 ;  ((freq_fromdigits  ) <<1 );  
//subband=SUBBAND_LOW  ;       
//*compfreq=FREQ1kHz                                       
KDVDC=  ((uint32_t)(freqvalue <<1)  );   return  DVDC_DIGITS(KDVDC);
}
 
  if ((( uint32_t) freqvalue>=280000) && (( uint32_t) freqvalue<=399999 ))  
{
 
 // Kdp=16   , R44  , fcomp=1 kHz
 //Kdp=16;  Kdpkd_div=4;  
//Kddpkd=  freq*4 ;  ((freq_fromdigits  ) <<2 );  
//subband=SUBBAND_HIGH  ;
//*compfreq=FREQ1kHz                                       
 KDVDC=  ((uint32_t)(freqvalue <<2)  );   return  DVDC_DIGITS(KDVDC);
}
 
   if ((( uint32_t) freqvalue>=200000) && (( uint32_t) freqvalue<=279999 ))  
{
// Kdp=16 ,R43  , fcomp=1 kHz
//Kdp=16; Kdpkd_div=4;  
//  Kddpkd=  freq*4 ; ((freq_fromdigits  ) <<2 );  
//subband=SUBBAND_LOW  ;
//*compfreq=FREQ1kHz                                       
 KDVDC=  ((uint32_t)(freqvalue <<2)  );   return  DVDC_DIGITS(KDVDC);
}
 
if ((( uint32_t) freqvalue>=140000) && (( uint32_t) freqvalue<=199999 ))  
{ 
 // Kdp=32 , R42  , fcomp=1 kHz
 //Kdp=32; 
  //Kdpkd_div=4;  
 //Kddpkd=  freq*8 ;  ((freq_fromdigits  ) <<3 );  
//subband=SUBBAND_HIGH  ;
//*compfreq=FREQ1kHz                                       
KDVDC=  ((uint32_t)(freqvalue <<3)  ); return  DVDC_DIGITS(KDVDC);
 
}
 
/********************************** mixer on  *******************************/
 if ((( uint32_t) freqvalue>=120000) && (( uint32_t) freqvalue<=139999 ))  
{
//      freq+=1000000;
// Kdp=4, R48  , fcomp=1 kHz
//Kdp=4;   Kdpkd_div=4;  
 //Kddpkd=  freq ;   ((freq_fromdigits  )  );  
//subband=SUBBAND_HIGH  ;
//*compfreq=FREQ1kHz   
      
   freqvalue+=1000000;
  KDVDC=  ((uint32_t)(freqvalue )  ); return  DVDC_DIGITS(KDVDC);
}
 
 if ((( uint32_t) freqvalue>=1000) && (( uint32_t) freqvalue<=119999 ))  
{
 //freq+=1000000;
 // Kdp=4 ,R47  , fcomp=1000  Hz
 //Kdp=4;  Kdpkd_div=4; 
// Kddpkd=  freq ;  ((freq_fromdigits  )  );  
 //subband=SUBBAND_LOW ;
//*compfreq=FREQ1kHz   
  freqvalue+=1000000;
  KDVDC=  ((uint32_t)(freqvalue )  );  return  DVDC_DIGITS(KDVDC);
}
 
 return { 0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 
}
Добавлено через 59 секунд
Подобрать более быстрые аналоги для наших частных случаев и типов .

Добавлено через 28 минут
Программа проверки
C++
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
#include  <stdio.h>
#include  <math.h>
#include  <stdint.h>
 
 
 
 
uint8_t * DVDC_DIGITS(uint32_t Kdvdc)
{
    
uint8_t Digits[6];
//160 000 0  *2 /5 =640 000‬->  Р±Р°Р№С‚С‹  (MSB) [0][6][4] [0][0][0] (LSB)
//159 999 9 *4/4=159 999 9‬->  Р±Р°Р№С‚С‹  (MSB) [15][9][9] [9][9][9] (LSB)  00 *18 69 FF= ‬>F 9 9 9 9 9
 
uint32_t    temp = Kdvdc ;   // make into binary degrees  value
 
  Digits[5] =(uint8_t) (temp/100000 );   //        (uint8_t) temp/100000;   div32  , Dig_5=(uint8_t) 159999/100000  = 15  =0x0f
    temp  =   (temp%100000 );                         //  temp - (Dig_5 * 100000);    temp%100000, mod32 , temp=159999-1 500 000‬=99 999
 
 Digits[4] =(uint8_t) (temp/10000  );      //(uint8_t) temp/10000;  div32  ,  Dig_4=(uint8_t)99 999/10000=9 =0x09
    temp  =  (temp%10000  );                             // temp%10000 ,  mod32    temp  =99 999 - 90000=9 999
 
 Digits[3] =(uint8_t) (temp/1000   );   // temp/1000;  div32  ,  Dig_3=(uint8_t) 9 999/1000 =9  =0x09
   temp  = (temp%1000   );                            // temp - (Dig_3 * 1000);   temp%1000  mod32    temp  = 9 999 - 9000 = 999
 
  Digits[2] =(uint8_t) (temp/100    );  //  temp/100;   div32  ,  Dig_2=(uint8_t)  999/100  =9    =0x09
   temp  = (temp%100    );                           // temp - (Dig_2 * 100);   temp%100  mod32    temp  =  999 - 900  =  99 
 
 Digits[1] =(uint8_t) (temp/10     );  // temp/10;  div32  ,  Dig_2=(uint8_t)  99/10  =9 =0x09
   temp  =  (temp%10     );                          // temp - (Dig_1 * 10);   temp%10  div32  , temp  =  99  - 90  =  9 
 
 Digits[0] =(uint8_t) (temp&0x0f);                        //temp  =    9   =0x09
 
  //printf (" %d %d %d %d %d %d ",  (int)Digits[5], (int)Digits[4], (int)Digits[3], (int)Digits[2], (int)Digits[1],(int)Digits[0]   );
return  Digits;
 
 
}
 
 
 
 
int main ()
{
uint32_t  Kdvdc;
printf("\n Input KoeffDVCD (1599999) : ");
scanf("%d",&Kdvdc);
 
 
uint8_t *Digits ;
Digits= (uint8_t *)DVDC_DIGITS(  Kdvdc);
printf (" %d %d %d %d %d %d ",  (int)Digits[5], (int)Digits[4], (int)Digits[3], (int)Digits[2], (int)Digits[1],(int)Digits[0]   );
 
int key;
scanf("%d",&key);
 
 
 
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
21.03.2020, 11:21  [ТС]
Возможный вариант подпрограммы декодирования ЧМ (нормализация в программе нормализации , декодирование диапазонов внешнее , доработать программу выработки (парсер кодов) кодов ген. ВЧ и ПДЧ , учитывать память )
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
995  FMCommaPos=2
100  FMCommaPos=2
99.5 FMCommaPos=1
10.0 FMCommaPos=1
9.95 FMCommaPos=0
1.00 FMCommaPos=0
0.05 FMCommaPos=0
0.00 FMCommaPos=0
*/
 
 
 
uint16_t GetFMValueFromDigits(uint8_t fm_digits[3])
{
uint16_t FM_Value=0;
for (uint8_t  i=0;i<fm_digits[2] ; i++) { FM_Value+=100; }
for (uint8_t  i=0;i<fm_digits[1] ; i++) { FM_Value+=10; }
for (uint8_t  i=0;i<fm_digits[0] ; i++) { FM_Value+=1; }
return FM_Value;
}
 
uint16_t GetFMValueFromDigits_div10(uint8_t fm_digits[3])
{
uint16_t FM_Value=0;
for (uint8_t  i=0;i<fm_digits[2] ; i++) { FM_Value+=10 ; }
for (uint8_t  i=0;i<fm_digits[1] ; i++) { FM_Value+=1 ; }
 
return FM_Value;
}
 
 
 
 
uint8_t GetCodeFM (uint8_t fm_digits[3], uint8_t FMCommaPos,  uint8_t  band , uint8_t *AttCorFM, uint8_t  *DAC_LFO  )
{
 
uint16_t FM_Value=0;
FM_Value=GetFMValueFromDigits( fm_digits );
 
//320-639.999 MHz   
if (band==0)               
{
if (FMCommaPos==2) {
if(FM_Value>=100) &&(FM_Value<=995 )  {         //995->    199(796),  000
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R53;   
return K_DACFM;  }}
 
if (FMCommaPos==1) {     
if((FM_Value>=100)&&(FM_Value<=995 )){         //99.5->    199(796),   011
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R59;
return K_DACFM;  }}
 
 
if (FMCommaPos==0) {     
if(FM_Value<=995){         //9.95->    199(796),   011
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R59; 
return K_DACFM;
 }}
 
}
 
//
160.000-319.999 MHz   
if (band==1)                  
{
if (FMCommaPos==2) {
if(FM_Value>=100) &&(FM_Value<=500 )  {         //500->    200(800),  000
K_DACFM=(uint8_t)(FM_Value*2/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R53;  
return K_DACFM;
 }}
 
if (FMCommaPos==1) {     
if( (FM_Value>=100)&&( FM_Value<=995 )){         //99.5->    199(796),   001
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R57;
return K_DACFM;
 }}
 
 
if (FMCommaPos==0) {     
if( FM_Value<=995 ){         //9.95->    199(796),   001
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R57;  
return K_DACFM;
}}
 
}
 
//80.0000-159.9999MHz 
if (band==2)                  
{
if (FMCommaPos==2) {
if(FM_Value>=100) &&(FM_Value<=250 )  {         //250->    200(800),  000
K_DACFM=(uint8_t)(FM_Value*4/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R53;  
return K_DACFM;
 }}
 
if (FMCommaPos==1) {     
if( (FM_Value>=100)&&( FM_Value<=995 )){         //99.5->    199(796),   010
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R55; 
return K_DACFM;
}}
 
 
if (FMCommaPos==0) {     
if( FM_Value<=995 ){         //9.95->    199(796),   010
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R55; 
return K_DACFM;
 }}
}
 
//40.0000-79.9999MHz
if (band==3)                  
{
if (FMCommaPos==2) {
if(FM_Value>=100) &&(FM_Value<=125 )  {         //100->    160(640),  000
K_DACFM=(uint8_t)(FM_Value*8/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R53;  
return K_DACFM;
 }}
 
if (FMCommaPos==1) {     
if( (FM_Value>=100)&&( FM_Value<=995 )){         //99.5->    199(796),   100
K_DACFM=(uint8_t)FM_Value/5;
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R54; 
return K_DACFM;
}}
 
if (FMCommaPos==0) {     
if( FM_Value<=995 ){      //9.95->    199(796),   100
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R54;  
return K_DACFM;
}}
}
 
 
 
 
 
 
 
 
//20.0000-39.9999MHz
if (band==4)                  
{
 
if (FMCommaPos==1) {     
if( (FM_Value>=100)&&( FM_Value<=500 )){         //50.0->    200(800),   100
 
K_DACFM=(uint8_t)(GetFMValueFromDigits_div10( fm_digits ))*4;
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R54;
return K_DACFM;
 }}
 
if (FMCommaPos==0) {     
if( FM_Value<=995 ){      //9.95->    199(796),  101
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R58; 
return K_DACFM;
 }}
}
 
 
//14.0000-19.9999MHz
if (band==5)                  
{
 
if (FMCommaPos==1) {     
if( (FM_Value>=100)&&( FM_Value<=250 )){         //25.0->    200(800),   100
K_DACFM=(uint8_t)(GetFMValueFromDigits_div10( fm_digits ))*8;
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R54; 
return K_DACFM;
}}
 
if (FMCommaPos==0) {     
if( FM_Value<=995 ){      //9.95->    199(796),  110
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R56;  
return K_DACFM;
}}
}
 
if (band==6)                  
{
 
if (FMCommaPos==1) {     
if( (FM_Value>=100)&&( FM_Value<=995 )){         //99.5->    199(796),   000
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_OFF;
*DAC_LFO=ATT_R55; 
return K_DACFM;
}}
 
if (FMCommaPos==0) {     
if( FM_Value<=995 ){      //9.95->    199(796),  010
K_DACFM=(uint8_t)(FM_Value/5);
*AttCorFM=ATTCORRFM_ON;
*DAC_LFO=ATT_R55;
return K_DACFM;  
//MIX_ON
}}
 
}
 
 
return K_DACFM; 
}
Добавлено через 1 минуту
nOSC_Gx , nFILTER_R сделать в прямой логике, адаптировать в программе отправки .
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
22.03.2020, 17:38  [ТС]
Code
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
A -0x41 //частота , МГц , не более 7  разрядов с точкой,   ОД 0x2C(про  реакцию на  0x2E в качестве ОД уточнить   )
B- 0x42//внутр . АМ,  не более 2 разрядов  , ОД 0x2C(про  реакцию на  0x2E в качестве ОД уточнить  )
C- 0x43//внутр . ЧМ , не более 3 разрядов с 0x2E  , ОД 0x2C(про  реакцию на  0x2E в качестве ОД уточнить  )
D- 0x44// внутр ИМ , ОД 0x2C (про  реакцию на  0x2E в качестве ОД уточнить   )
 
NB 0x4E 0x42 // внеш. АМ , не более 2  разрядов  , ОД 0x2C(про  реакцию на  0x2E в качестве ОД уточнить  )
NC 0x4E 0x43 //внеш. ЧМ  , не более 3  разрядов с 0x2E   , ОД 0x2C(про  реакцию на  0x2E в качестве ОД уточнить  )
ND 0x4E 0x44 // внеш.  ИМ ,  ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить   )
 
BE 0x42  0x45 // выкл. АМ,  ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить   )
CE 0x43 0x45//  выкл . ЧМ ,  ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить  )
E   0x45 // выкл ИМ, ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить   )
F   0x46 //частота , 1 знак после , ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить   )
K   0x4B //вкл выход,если ОД ,   выход,  - дБВ,  не более 3,5 разрядов (старший только 1 , если 4 ),    , ОД 0x2C(про  реакцию на  0x2E в качестве ОД уточнить  )
L   0x4C //для РГ4-17-01 , режим мВ , 3,5 разрядов , ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить   ) 
M 0x4D // выход мкВ, режим мкВ , 3,5 разрядов , ОД 0x2C  (про  реакцию на  0x2E в качестве ОД уточнить   ) 
I 0x49    // выкл выход ,   ОД 0x2C или 0x2E 
O 0x4F  //вкл +6 дБ ,   ОД 0x2C  или   0x2E  
H 0x48 // выкл +6 дБ ,   ОД 0x2C  или  0x2E  
',' 0x2C // ограничитель данных , исполняется по этому символу 
'.' 0x2E // элемент ТД2 (или  ОД сообщения) 
 
' " ' 0x22 //для Г4-164 , режим мВ
 
 
0 0x30
1 0x31
2 0x32
3 0x33
4 0x34
5 0x35
6 0x36
7 0x37
8 0x38
9 0x39
Добавлено через 30 секунд
Информация уточняется

Добавлено через 3 часа 31 минуту
Концептуально для точки 7 алгоритма ввод и дешифрация байта могут быть аналогичны программе (с доработками, устранить мелкие баги и неадекватность другим модулям )
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 uint8_t counter=0;   
 uint8_t FlagEnd=0;
 uint8_t flagLFO=0; 
 uint8_t NoComma=0;
 
 
void ParseCommand()
{
     
    
 //if GPIB, no blinking     , update after delimitter of the  command  was received 
 
uint8_t byte=GetGPIBByte ();  //gets  TTL code from inverse code for LD bus  bits 
// asm("cli");
 
switch(byte)
{
 
 
case  0x2C: //','
               counter=0;   
               FlagEndMsg= 0;   
          
               ExecCMD(FlagMode); 
               FlagMode=MODE_NOCMD;     
               break; 
case  0x2E: //'.'
               if ((FlagEndMsg==0)&&(NoComma==0)) { ParseCommaPos(counter, FlagMode);   NoComma=1;  } 
               if (FlagEndMsg==1) {  ExecCMD(FlagMode);  counter=0;  FlagEndMsg=0; FlagMode=MODE_NOCMD;  }    //fix 
               break; 
 
case 0x30 ... 0x39 :
           if (counter>0) 
           {  
           if (FlagMode==MODE_TURN_ON_OUT) { FlagMode= MODE_TURN_ON_OUT_dB;  } 
           if (FlagMode==MODE_PREPSETFREQLFO)  { FlagMode== GetModeLFOIfDigit(byte);  FlagEndMsg=1;  }
           else {   PutDigitToGPIBStackIfByte(count, byte  );  }   // put byte-0x30 to stack
           counter--;
            }
           else { counter=0;  FlagEndMsg=1; }
           break; 
 
 
 
case 0x49: //I   turn off output
                 counter=0;         
                 FlagMode=MODE_TURN_OFF_OUT; 
                 FlagEndMsg=1;
                 break;                     
 
case 0x48: //H  6 dB off
                counter=0; 
                FlagMode=MODE_TURN_OFF_6dB; 
                FlagEndMsg=1;
                break;
case 0x4F: //O   turn on 6 dB  
                counter=0; 
                FlagMode=MODE_TURN_ON_6dB; 
                FlagEndMsg=1;
                break;  
 
 
case 0x44: //D   PM on ; off for ND  
                counter=0; 
                if(MODE_PREP_EXT_MOD) {  FlagMode=MODE_TURN_ON_EXT_ PM; }  else {  FlagMode=MODE_TURN_ON_INT_ PM; }
                FlagEndMsg=1;
                break;
 
 
case 0x45: //E  PM off, end for BE,CE     
                counter=0; 
                if(FlagMode==MODE_EXT_AM) {   FlagMode=MODE_TURN_OFF_EXT_AM; }
                if(FlagMode==MODE_INT_AM) {   FlagMode=MODE_TURN_OFF_INT_AM; }
                if(FlagMode==MODE_EXT_FM) {   FlagMode=MODE_TURN_OFF_EXT_FM; }
                if(FlagMode==MODE_INT_FM) {   FlagMode=MODE_TURN_OFF_INT_FM; }
                else  {   FlagMode=MODE_TURN_OFF_PM; }             
                FlagEndMsg=1;
                break;
 
case 0x41:  //A      freq  , for example "A520.100,B80." or "A520.100," <=7 digits + comma
   //fix problem with init stack if mode was changed 
                     counter=NUM_DIGITS_FREQ;
                     FlagMode=MODE_FREQ; 
                     NoComma=0;
                     FlagEndMsg=0 ;                                       
                     break;
 
case 0x4E: //N , for example "NB,","NB20,",  "NС,","ND" ,"NC100,"
 
               counter=1;
               FlagMode=MODE_PREP_EXT_MOD;    
               FlagEndMsg=0 ;
               break;   
            
 
 
case 0x42: //B    end of  NB, NC,    begin of BE        AM,% for example  "B80." or "B80," , <=2 digits
  //fix problem with init stack if mode was changed and leave digits if  no digis in message
             counter=NUM_DIGITS_AM;
             NoComma=0;           
                if (FlagMode==MODE_PREP_EXT_MOD) {  FlagMode=MODE_EXT_AM ; }       else  {  FlagMode=MODE_INT_AM ;  } 
               FlagEndMsg=0 ; 
                break;
    
case 0x43: //C    end of  NB, NC,    begin of CE         , FM, kHz , <=3  digits 
  //fix problem with init stack if mode was changed and leave digits if  no digis in message 
                counter=NUM_DIGITS_FM; 
                NoComma=0;          
                if (FlagMode==MODE_PREP_EXT_MOD)   {  FlagMode=MODE_EXT_FM ; }   else  {  FlagMode=MODE_INT_FM ;  } 
                FlagEndMsg=0 ; 
                break;
 
 
case 0x4B: //K   turn on output ,  input att., dB if with digits 
 //fix problem with init stack if mode was changed and leave digits if  no digis in message 
                counter=NUM_DIGITS_OUT;
                 NoComma=0;    
                FlagMode=MODE_TURN_ON_OUT ;   /*  if  only K , turn on output            */
                FlagEndMsg=0 ;
                break;
 
case 0x4C: // L   для РГ4-17-01        output, mV, <=3.5 digits + comma
case 0x22 : // " , для Г4-164
//fix problem with init stack if mode was changed and leave digits if  no digis in message 
                counter=NUM_DIGITS_OUT;
                 NoComma=0;    
                FlagMode=MODE_TURN_ON_OUT_mV;
                FlagEndMsg=0 ;
                break;                  
case 0x4D: //M  , for example,"M10.00",<=3.5 digits + comma
//fix problem with init stack if mode was changed and leave digits if  no digis in message 
               counter=NUM_DIGITS_OUT; 
               NoComma=0;    
               FlagMode=MODE_TURN_ON_OUT_mkV;            
               FlagEndMsg=0 ;
               break;       
 
case 0x46: //F   Finternal ,for example "F1,"
 
          counter=1; 
           NoComma=1;       
          FlagMode=MODE_PREPSETFREQLFO; 
          FlagEndMsg=0;
          break;
 
 
default :
 
           counter=0;
                 NoComma=1;    
           FlagMode=MODE_NOCMD; 
           FlagEndMsg=1 ;    
           break;
  
    
    
}
//fix problem with stack management 
 
//SendDataAcceptedStrobe();  //fix place of this subroutine ,fix name of subroutine 
 //asm("sei");
return; 
}
  //ExecCMD(FlagMode) выставляет необходимые флаги команд  в регистрах главных флагов основной "среды", 
//когда ОД введен,
// запуская режим на выполнение  вместо клавиш по флагам 
//  в стеке цифр и буфере положения запятой  временно хранятся цифры и запятая  числа
//  если  режим введен неправильно , команда игнорируется , 
// если команда режима введена без цифр , цифры берутся из предыдущего 
// состояния массива(структуры) байтов  цифр и запятой  текущего  состояния прибора
Добавлено через 3 минуты
Это только для приборных сообщений ,УП=0 (высокое или от внутренних подтягивающих вверх резисторов )

Добавлено через 5 часов 30 минут
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#include <stdio.h>
#include <stdint.h>
 
 uint8_t remain_digits=0;   
 uint8_t FlagEndMsg=0;
 uint8_t flagLFO=0; 
 uint8_t NoComma=0;
 uint8_t FlagMode=0;
#define MODE_NOCMD 0
#define MODE_TURN_OFF_OUT 1
#define MODE_TURN_OFF_6dB   2
#define MODE_TURN_ON_6dB     3
 
#define MODE_INT_AM  4  
#define MODE_EXT_AM 5
#define MODE_INT_FM 6
#define MODE_EXT_FM 7
#define MODE_TURN_ON_EXT_PM 8
#define MODE_TURN_ON_INT_PM 9
 
 
#define MODE_TURN_OFF_EXT_AM 10
#define MODE_TURN_OFF_INT_AM 11
#define MODE_TURN_OFF_EXT_FM 12
#define MODE_TURN_OFF_INT_FM 13 
#define MODE_TURN_OFF_PM  14
//#define MODE_TURN_OFF_EXT_PM  15
 
#define MODE_FREQ   16
#define MODE_PREP_EXT_MOD 17
#define MODE_TURN_ON_OUT 18
#define MODE_TURN_ON_OUT_dB 19
#define MODE_TURN_ON_OUT_mV 20
#define MODE_TURN_ON_OUT_mkV 21
#define MODE_PREPSETFREQLFO  22
 
#define MODE_SETFREQLFO0 30
#define MODE_SETFREQLFO1 31
#define MODE_SETFREQLFO2 32
#define MODE_SETFREQLFO3 33
#define MODE_SETFREQLFO4 34
#define MODE_SETFREQLFO5 35
#define MODE_SETFREQLFO6 36
#define MODE_SETFREQLFO7 37
 
 
#define  NUM_DIGITS_FREQ 7
#define  NUM_DIGITS_FM 3 
#define  NUM_DIGITS_AM 2
#define  NUM_DIGITS_OUT 4
 
 
uint8_t  GetByte()
{
uint8_t byte; 
printf("\n Input byte char (0...9, A,B,C,D,E,F,I, K,L,\x22,M,N,O ):   ");
scanf("%s",&byte);
//printf("\n      Send active signal  on Interrupt 3  ");
return byte; 
}
 
 
void ExecCMD(uint8_t mode)
{
 
switch (mode){
case MODE_NOCMD: 
 
              printf("\n No CMD  or error  ");
 
 
                             break;
case MODE_TURN_OFF_OUT: 
                printf("\n turn Off Out  "); 
                             break;
case MODE_TURN_OFF_6dB: 
                 printf("\n TURN OFF 6dB  "); 
                             break;
 
case MODE_TURN_ON_6dB: 
                 printf("\n TURN ON 6dB  "); 
                             break;
                             
case MODE_INT_AM: 
                 printf("\n TURN ON INT AM  "); 
                             break;
case MODE_EXT_AM: 
                 printf("\n TURN ON EXT AM  ");    
                             break;    
case MODE_INT_FM: 
                  printf("\n TURN INT FM  "); 
                             break;
case MODE_EXT_FM:  
                  printf("\n TURN EXT FM  "); 
                             break;                                                                               
 
case MODE_TURN_ON_EXT_PM:  
                  printf("\n TURN ON EXT PM  "); 
                             break; 
case MODE_TURN_ON_INT_PM:  
                  printf("\n TURN ON INT PM  "); 
                             break;
 case MODE_TURN_OFF_EXT_AM:  
                  printf("\n TURN ON EXT AM  "); 
                             break;
 case MODE_TURN_OFF_INT_AM:  
                  printf("\n TURN ON INT AM  "); 
                             break;
 case MODE_TURN_OFF_EXT_FM:  
                  printf("\n TURN ON EXT FM  "); 
                             break;
 case MODE_TURN_OFF_INT_FM:  
                  printf("\n TURN ON INT FM  "); 
                             break;                            
                             
 case MODE_TURN_OFF_PM:  
                  printf("\n MODE TURN OFF PM  "); 
                             break;                                    
 case MODE_FREQ:  
                  printf("\n MODE FREQ  "); 
                             break;  
                             
 case MODE_TURN_ON_OUT: 
                  printf("\n TURN ON OUT  ");                    
                 break; 
                     
                             
 case MODE_TURN_ON_OUT_dB:  
                  printf("\n TURN ON OUT dB  ");                     
                 break; 
 case MODE_TURN_ON_OUT_mV:  
                  printf("\n TURN ON OUT mV  ");                     
                 break; 
 case MODE_TURN_ON_OUT_mkV: 
                  printf("\n TURN ON OUT mkV  ");                    
                 break;                          
 case MODE_SETFREQLFO0: 
                  printf("\n MODE_SETFREQLFO0  ");                   
                 break;              
                 
 case MODE_SETFREQLFO1: 
                  printf("\n MODE_SETFREQLFO1  ");                   
                 break;              
                 
 case MODE_SETFREQLFO2: 
                  printf("\n MODE_SETFREQLFO2  ");                   
                 break;
 case MODE_SETFREQLFO3: 
                  printf("\n MODE_SETFREQLFO3 ");                    
                 break;              
 case MODE_SETFREQLFO4: 
                  printf("\n MODE_SETFREQLFO4  ");                   
                 break;              
 case MODE_SETFREQLFO5: 
                  printf("\n MODE_SETFREQLFO5  ");                   
                 break; 
 case MODE_SETFREQLFO6: 
                  printf("\n MODE_SETFREQLFO6  ");                   
                 break; 
 case MODE_SETFREQLFO7: 
                  printf("\n MODE_SETFREQLFO7  ");                   
                 break;                                                                  
                 
                                                                                                             
default :
 break;
 
 
}
 
 
return;
}
 
 
uint8_t GetNumDigitsMode(uint8_t counter,uint8_t FlagMode)
{
if(FlagMode==MODE_FREQ) {return 7; }
if(FlagMode==MODE_INT_AM) {return 2; } 
if(FlagMode==MODE_EXT_AM) {return 2; }  
if(FlagMode==MODE_INT_FM) {return 3; }  
if(FlagMode==MODE_EXT_FM) { return 3; }  
if(FlagMode==MODE_TURN_ON_OUT_dB) { return 4; } 
if(FlagMode==MODE_TURN_ON_OUT_mV) { return 4; }      
if(FlagMode==MODE_TURN_ON_OUT_mkV) { return 4; }    
    return 0;
}
 
 
void ParseCommaPos(uint8_t counter,uint8_t FlagMode)
{
uint8_t position ;
position=GetNumDigitsMode( counter, FlagMode)-counter-1;
printf ( "\n comma posistion in %d digit     ", position  );        
return; 
}
 
 
 
uint8_t digits[7] ; 
 
PutDigitToGPIBStackIfByte(uint8_t count, uint8_t  byte,   uint8_t FlagMode  )
{
uint8_t position ;
position=GetNumDigitsMode( count , FlagMode)-count ;
 
 
digits[position]=byte-0x30;  //fix
printf ( "\n %d digit is %d   ",   position, digits[position]  );
 
}
 
uint8_t GetModeLFOIfDigit(uint8_t byte)
{
 
if (byte==0x30) {    return MODE_SETFREQLFO0;   }
if (byte==0x31) {    return MODE_SETFREQLFO1;    }
if (byte==0x32) {    return MODE_SETFREQLFO2;    }
if (byte==0x33) {    return MODE_SETFREQLFO3;    }
if (byte==0x34) {    return MODE_SETFREQLFO4;    }
if (byte==0x35) {    return MODE_SETFREQLFO5;    }
if (byte==0x36) {    return MODE_SETFREQLFO6;    }
if (byte==0x37) {    return MODE_SETFREQLFO7;    }
if (byte==0x38) {    return MODE_NOCMD;   }
if (byte==0x39) {    return MODE_NOCMD;   }     
return 0;   
    
}   
    
 
 
 
void ResetLastDigits(uint8_t FlagMode, uint8_t count )
{
uint8_t nextpos ;
nextpos=GetNumDigitsMode( count  , FlagMode)-count +1   ;
    
for (uint8_t i=nextpos;i<=6;i++)    {  digits[i]=0; }
 
 
 
 
for (uint8_t i=0;i<=6;i++)  { printf("\n%d", digits[i] );   }
 
return ;    
}
 
/*
 
 7  0  digits[0] = 5
 6  1  digits[1] = 2
 5  2  digits[2] = 0    CommaPos=2
           
 4  3  digits[3] =1  
 3  4  digits[4]=0     auto 0 
 2  5  digits[5]=0     auto 0
 1  6  digits[6]=0     auto 0
 0  7  end
 
 3  0  
 2  1 
 1  2
 0  3  end
 
 2  0 digits[0]=8
 1  1 digits[1]=0
 0  2  end
 
 
 4  0 digits[0]=1
 3  1 digits[0]=0 CommaPos=1
 2  2 digits[0]=0
 1  3 digits[0]=0
 0  4  end
 
 
 
 
 
*/
 
 
 
 
 
void ParseCommand()
{
     
    
 //if GPIB, no blinking     , update after delimitter of the  command  was received 
 
uint8_t byte;
//byte=GetGPIBByte ();  //gets  TTL code from inverse code for LD bus  bits 
 
byte=GetByte ();
 
// asm("cli");
 
 
 
 
if (byte==0x2e)  {   // '.'            
 if ((FlagEndMsg==0)&&(NoComma==0) ) { ParseCommaPos(remain_digits, FlagMode);   NoComma=1; goto  SwitchLabelbreak; } 
 
 ResetLastDigits(FlagMode, remain_digits);
 ExecCMD(FlagMode);               
 remain_digits=0;   
 FlagEndMsg= 0;
 FlagMode=MODE_NOCMD; 
 goto  SwitchLabelbreak;             
}
                
 
                 
 if (byte==0x2c){   //  ','                           
 ResetLastDigits(FlagMode, remain_digits);
 ExecCMD(FlagMode);                
 remain_digits=0;   
 FlagEndMsg= 0;
 FlagMode=MODE_NOCMD;  
 goto  SwitchLabelbreak;              
} 
 
if ((byte>=0x30)&&(byte<=0x39)) { //'0'...'9'
            
 if ( remain_digits>0) 
  {  
 if (FlagMode==MODE_PREPSETFREQLFO)  {  FlagMode=  GetModeLFOIfDigit(byte);   FlagEndMsg=1; remain_digits=0;     }          
 if (FlagMode==MODE_TURN_ON_OUT) { FlagMode= MODE_TURN_ON_OUT_dB;  } 
 else {   PutDigitToGPIBStackIfByte( remain_digits , byte, FlagMode  );    }   // put byte-0x30 to stack
 remain_digits--;
 }
 else { remain_digits=0;  FlagEndMsg=1;   printf("\n  remain_digits=0 FlagEnd=1");          }
goto  SwitchLabelbreak; }
 
 
if(byte==0x49) {//I   turn off output
                 remain_digits=0;         
                 FlagMode=MODE_TURN_OFF_OUT; 
                 FlagEndMsg=1;
                goto  SwitchLabelbreak;   }                 
 
             
if(byte==0x48){ //H  6 dB off
                 remain_digits=0; 
                FlagMode=MODE_TURN_OFF_6dB; 
                FlagEndMsg=1;
                goto  SwitchLabelbreak; }
if(byte==0x4F){ //O   turn on 6 dB  
                remain_digits=0; 
                FlagMode=MODE_TURN_ON_6dB; 
                FlagEndMsg=1;
                goto  SwitchLabelbreak;}    
 
if(byte==0x44){ //D   PM on ; off for ND  
 
                
                remain_digits=0; 
                if(MODE_PREP_EXT_MOD) {  FlagMode=MODE_TURN_ON_EXT_PM; }  else {  FlagMode=MODE_TURN_ON_INT_PM; }
                FlagEndMsg=1;
                goto  SwitchLabelbreak;}
 
 
if(byte==0x45){ //E  PM off, end for BE,CE     
                remain_digits=0; 
                if(FlagMode==MODE_EXT_AM) {   FlagMode=MODE_TURN_OFF_EXT_AM; }
                if(FlagMode==MODE_INT_AM) {   FlagMode=MODE_TURN_OFF_INT_AM; }
                if(FlagMode==MODE_EXT_FM) {   FlagMode=MODE_TURN_OFF_EXT_FM; }
                if(FlagMode==MODE_INT_FM) {   FlagMode=MODE_TURN_OFF_INT_FM; } else  {   FlagMode=MODE_TURN_OFF_PM; }             
                FlagEndMsg=1;
                goto  SwitchLabelbreak;}
 
if(byte==0x41) {  //A      freq  , for example "A520.100,B80." or "A520.100," <=7 digits + comma
                  //fix problem with init stack if mode was changed 
                     remain_digits=7;
                     FlagMode=MODE_FREQ; 
                     NoComma=0;
                     FlagEndMsg=0 ;                                       
                     goto  SwitchLabelbreak;}
 
if(byte==0x4e){ //N , for example "NB,","NB20,",  "NС,","ND" ,"NC100,"
 
               remain_digits=1;
               FlagMode=MODE_PREP_EXT_MOD;    
               FlagEndMsg=0 ;
               goto  SwitchLabelbreak;}   
            
 
 
if(byte==0x42){ //B    end of  NB, NC,    begin of BE        AM,% for example  "B80." or "B80," , <=2 digits
  //fix problem with init stack if mode was changed and leave digits if  no digis in message
             remain_digits=2;
             NoComma=1;           
              if (FlagMode==MODE_PREP_EXT_MOD) {  FlagMode=MODE_EXT_AM ; }       else  {  FlagMode=MODE_INT_AM ;  } 
               FlagEndMsg=0 ; 
               goto  SwitchLabelbreak;}
    
if(byte==0x43){ //C    end of  NB, NC,    begin of CE         , FM, kHz , <=3  digits 
  //fix problem with init stack if mode was changed and leave digits if  no digis in message 
                remain_digits=3; 
                NoComma=0;          
                if (FlagMode==MODE_PREP_EXT_MOD)   {  FlagMode=MODE_EXT_FM ; }   else  {  FlagMode=MODE_INT_FM ;  } 
                FlagEndMsg=0 ; 
                goto  SwitchLabelbreak;}
 
 
if(byte==0x4B){ //K   turn on output , 
 //fix problem with init stack if mode was changed and leave digits if  no digis in message 
                 remain_digits=4;
                 NoComma=0;    
                FlagMode=MODE_TURN_ON_OUT ;   /*  if  only K , turn on output            */
                FlagEndMsg=0 ;
                goto  SwitchLabelbreak;}
 
if((byte==0x4C)||(byte==0x22)){     // L           output, mV, <=3.5 digits + comma
  // "  
//fix problem with init stack if mode was changed and leave digits if  no digis in message 
                 remain_digits=4;
                 NoComma=0;    
                FlagMode=MODE_TURN_ON_OUT_mV;
                FlagEndMsg=0 ;
               goto  SwitchLabelbreak;  }               
if(byte==0x4D) //M  , for example,"M10.00",<=3.5 digits + comma
//fix problem with init stack if mode was changed and leave digits if  no digis in message 
{
               remain_digits=4; 
               NoComma=0;    
               FlagMode=MODE_TURN_ON_OUT_mkV;            
               FlagEndMsg=0 ;
               goto  SwitchLabelbreak;      
}
if(byte==0x46) //F   Finternal ,for example "F1,"
{
           remain_digits=1; 
           NoComma=1;       
          FlagMode=MODE_PREPSETFREQLFO; 
          FlagEndMsg=0;
          goto  SwitchLabelbreak;
}
 
 
           remain_digits=0;
           NoComma=1;    
           FlagMode=MODE_NOCMD; 
           
           FlagEndMsg=1 ;
           ExecCMD(FlagMode);    
           
 
SwitchLabelbreak:
//fix problem with stack management 
 
//SendDataAcceptedStrobe();  //fix place of this subroutine ,fix name of subroutine 
 //asm("sei");
return; 
}
 
 
 
 
int main()
{
 
label1:
printf("\n Input command  bytes (  A520.1,B80,F1,M15.   ) ");  //fix 0x2e problem for end of message 
 
ParseCommand(); //A 0x41
ParseCommand(); //5 0x35
ParseCommand(); //2 0x32
ParseCommand(); //0 0x30
ParseCommand(); //.0x2e
ParseCommand(); //1 0x31
ParseCommand(); //, 0x2c
ParseCommand(); //B 0x42
ParseCommand(); //8 0x38
ParseCommand(); //0 0x30
ParseCommand(); //, 0x2c
ParseCommand(); //F 0x46
ParseCommand(); //1 0x31
ParseCommand(); //, 0x2c
ParseCommand(); //M 0x46
ParseCommand(); //1 0x31
ParseCommand(); //5 0x35
ParseCommand(); //. 0x2e   // or 0x2c fix or check  
printf ("\n Inpuit 1 for exit or 0 for next command ");
int key;
scanf("%d",&key);
if (key==0) {goto label1; }
 
 
 
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
23.03.2020, 00:15  [ТС]
Возможный текст программы обработки сообщений GPIB на ассемблере (переделать , исправить баги , встроить , правильно заполнять нулями регистры, в которые не вводили , но в сообщении предусмотрены , адаптировав под память с регистров )
Assembler
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
GetNumDigitsMode:
 
cpi r18, MODE_FREQ
breq LabelFreqNumDigits
cpi r18, MODE_INT_AM
breq LabelAMNumDigits
cpi r18, MODE_EXT_AM
breq LabelAMNumDigits
cpi r18, MODE_INT_FM
breq LabelFMNumDigits
cpi r18,MODE_EXT_FM
breq LabelFMNumDigits
 
cpi r18, MODE_TURN_ON_OUT_dB
breq LabelOutNumDigits
cpi r18,MODE_TURN_ON_OUT_mV
breq  LabelOutNumDigits
cpi r18,MODE_TURN_ON_OUT_mkV
breq  LabelOutNumDigits
ldi r16,0 
ret
Label1FreqNumDigits:
ldi r16,0x07 
ret
LabelAMNumDigits:
ldi r16,0x02 
ret
LabelFMNumDigits:
ldi r16,0x03 
ret
LabelOutNumDigits:
ldi r16,0x04 
ret
;***********************
GetModeLFOIfDigit: ; to r18 
mov r16,r17
cpi  r16, 0x30
breq LabelSetLFO0
cpi  r16, 0x31
breq LabelSetLFO1
cpi  r16, 0x32
breq LabelSetLFO2
cpi  r16, 0x33
breq LabelSetLFO3
cpi  r16, 0x34
breq LabelSetLFO4
cpi  r16, 0x35
breq LabelSetLFO5
cpi  r16, 0x36
breq LabelSetLFO6
cpi  r16, 0x37
breq LabelSetLFO7
ldi r18,  MODE_NOCMD
LabelSetLFO0:
ldi r18,  MODE_SETFREQLFO0
ret
LabelSetLFO1:
ldi r18,  MODE_SETFREQLFO1
ret
LabelSetLFO2:
ldi r18,  MODE_SETFREQLFO2
ret
LabelSetLFO3:
ldi r18,  MODE_SETFREQLFO3
ret
LabelSetLFO4:
ldi r18,  MODE_SETFREQLFO4
ret
LabelSetLFO5:
ldi r18,  MODE_SETFREQLFO5
ret
LabelSetLFO6:
ldi r18,  MODE_SETFREQLFO6
ret
LabelSetLFO7:
ldi r18,  MODE_SETFREQLFO7
ret
;******************
 
 
  
 
ParseCommaPos:  ; remain_digits r19 , FlagMode r18 ; 
 call GetNumDigitsMode  ; r18  , result  in the  r16 
 sub r16, r18
 dec r16 
 mov  r8, r16
ret
 
PutDigitToGPIBStackIfByte:  ;fix 
 
mov r16,r17 
subi r16, 0x30
mov r10, r16
 
call GetNumDigitsMode  ; r18  FlagMode, r19  count,  result  in the  r16 
sub r16,  r19
cpi r16, 0
breq LabelNumDigit0
cpi r16, 1
breq LabelNumDigit1
cpi r16, 2
breq LabelNumDigit2
cpi r16, 3
breq LabelNumDigit3
cpi r16, 4
breq LabelNumDigit4
cpi r16, 5
breq LabelNumDigit5
cpi r16, 6
breq LabelNumDigit6
 
LabelNumDigit0:
mov  r0,r10
ret
LabelNumDigit1:
mov  r1,r10
ret
LabelNumDigit2:
mov  r2,r10
ret
LabelNumDigit3:
mov  r3,r10
ret
LabelNumDigit4:
mov  r4,r10
ret
LabelNumDigit5:
mov  r5,r10   
ret
 
ResetLastDigits:
;fix subroutine
 
;nextpos=GetNumDigitsMode( count  , FlagMode)-count +1   ;  
;for (uint8_t i=nextpos;i<=6;i++)   {  digits[i]=0; }
ret
 
 
ParseCommand: 
 
 
; r0
; r1
; r2
; r3
; r4
; r5
; r6
 
; r8
 
 
     
call   GetGPIBByte;  fix reg    
 
mov r16, r17
cpi  r16, 0x2e 
breq LabelGPIBCase_dot 
cpi  r16, 0x2c 
breq LabelGPIBCase_comma 
mov r16, r17
cpi  r16, 0x30
brge  LabelGPIBtest_if_digit2
jmp LabelGPIBif_nodigits2
LabelGPIBtest_if_digit2:
mov r16, r17
cpi  r16, 0x3a 
brlo  LabelGPIBCase_digits  
if_nodigits2:
mov r16, r17
cpi  r16, 0x49
breq LabelGPIBCase_I
cpi  r16, 0x48
breq LabelGPIBCase_H
cpi  r16, 0x4F
breq LabelGPIBCase_O
cpi  r16, 0x44
breq LabelGPIBCase_D
cpi  r16, 0x45
breq LabelGPIBCase_E
cpi  r16, 0x41
breq LabelGPIBCase_A
cpi  r16, 0x4e
breq LabelGPIBCase_N
cpi  r16, 0x42
breq LabelGPIBCase_B
cpi  r16, 0x43
breq LabelGPIBCase_C
cpi  r16, 0x4b
breq LabelGPIBCase_K
cpi  r16, 0x4c
breq LabelGPIBCase_L
cpi  r16, 0x22
breq LabelGPIBCase_L
cpi  r16, 0x4d
breq LabelGPIBCase_M
cpi  r16, 0x46
breq LabelGPIBCase_F
jmp   LabelGPIBCase_default
;ret
 
 
; r16 tmp 
; r17 GPIB byte 
; r18   FlagMode  
; r19    remain_digits    
; r20  FlagEndMsg
; r21  NoComma
 
LabelGPIBCase_dot :    // '.'     
 
cpi  r20, 0    
brne LabelNoComma
cpi  r21, 0    
brne LabelNoComma
 
call ParseCommaPos ; remain_digits, FlagMode ;   
ldi r21, 0x01  
jmp SwitchLabelbreak; 
 
LabelNoComma:
call ResetLastDigits ; FlagMode, remain_digits ;
call ExecCMD           ;ExecCMD(FlagMode);               
ldi r19, 0 
ldi r20, 0  
 
ldi r18, MODE_NOCMD; 
jmp SwitchLabelbreak;            
 
                 
LabelGPIBCase_comma: ;  ','                           
 call ResetLastDigits ; FlagMode, remain_digits ;
 call ExecCMD  ; r18 FlagMode, ExecCMD(FlagMode);                
ldi r19, 0; 
ldi r20, 0;  
ldi r18, MODE_NOCMD;  
jmp SwitchLabelbreak; 
 
LabelGPIBCase_digits:   ; '0'...'9'
 
cpi  r19, 0 ; if ( remain_digits>0)
brne LabelGPIB_EndNumMsg ;
 
cpi r18, MODE_PREPSETFREQLFO
brne   LabelGPIB_NotLFOMode
call GetModeLFOIfDigit ; FlagMode=  GetModeLFOIfDigit(byte)
ldi r20, 1; FlagEndMsg=1;
ldi r19, 0; remain_digits=0; 
 
LabelGPIB_NotLFOMode:
cpi r18, MODE_TURN_ON_OUT
brne  LabelPutDigitToGPIB
ldi r18, MODE_TURN_ON_OUT_dB
jmp LabelDecRem  
LabelPutDigitToGPIB:
call PutDigitToGPIBStackIfByte ; ( remain_digits , byte, FlagMode  );
 
LabelDecRem:      
dec r19; remain_digits--;
 jmp SwitchLabelbreak;
 
 
LabelGPIB_EndNumMsg:
 ldi r19, 0;      remain_digits  
ldi r20 , 0x01; FlagEndMsg=1
  
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_I:  ;I   turn off output
ldi r19, 0;         
ldi r18, MODE_TURN_OFF_OUT; 
ldi r20 , 0x01;   FlagEndMsg=1;
jmp SwitchLabelbreak;                   
 
             
LabelGPIBCase_H:  ; H  6 dB off
ldi r19, 0; remain_digits=0; 
ldi r18, MODE_TURN_OFF_6dB; 
ldi r20 , 0x01;  FlagEndMsg=1;
jmp SwitchLabelbreak;
 
LabelGPIBCase_O: ; O   turn on 6 dB  
ldi r19, 0; remain_digits=0; 
ldi r18, MODE_TURN_ON_6dB; 
ldi r20 , 0x01; FlagEndMsg=1;
jmp SwitchLabelbreak;   
 
LabelGPIBCase_D:  ; D   PM on ; off for ND  
ldi r19, 0; 
cpi r18, MODE_PREP_EXT_MOD
breq LabelGPIBExtMod
ldi r18, MODE_TURN_ON_INT_PM
ldi r20 , 0x01; FlagEndMsg=1;
jmp SwitchLabelbreak;
LabelGPIBExtMod:
ldi r18, MODE_TURN_ON_EXT_PM
ldi r20 , 0x01; FlagEndMsg=1;
jmp SwitchLabelbreak;                
 
 
 
LabelGPIBCase_E: ; E  PM off, end for BE,CE     
ldi r19, 0;  remain_digits=0; 
ldi r20 , 0x01; FlagEndMsg=1;
cpi r18, MODE_EXT_AM
breq  LabelGPIB_EXT_AM
cpi r18, MODE_INT_AM
breq  LabelGPIB_INT_AM
cpi r18, MODE_EXT_FM
breq  LabelGPIB_EXT_FM
cpi r18, MODE_INT_FM
breq  LabelGPIB_INT_FM
ldi r18, MODE_TURN_OFF_PM
jmp SwitchLabelbreak;
 
LabelGPIB_EXT_AM:
ldi r18, MODE_TURN_OFF_EXT_AM
jmp SwitchLabelbreak;
 
LabelGPIB_INT_AM:
ldi r18, MODE_TURN_OFF_INT_AM
jmp SwitchLabelbreak;
LabelGPIB_EXT_FM:
ldi r18, MODE_TURN_OFF_EXT_FM
jmp SwitchLabelbreak;
 
LabelGPIB_INT_FM:
ldi r18, MODE_TURN_OFF_INT_FM
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_A: ; A      freq  , for example "A520.100,B80." or "A520.100," <=7 digits + comma
                                  ;fix problem with init stack if mode was changed 
ldi r19,  0x07  ;  remain_digits=7;
ldi r18,  MODE_FREQ; 
ldi r21 , 0x00       ;  NoComma=0;
ldi r20 , 0x00       ;   FlagEndMsg=0 ;                                       
jmp SwitchLabelbreak;
 
LabelGPIBCase_N: ; N , for example "NB,","NB20,",  "NС,","ND" ,"NC100,"
 
ldi r19,  0x01  ;   remain_digits=1;
ldi r18,  MODE_PREP_EXT_MOD ;    
ldi r20 , 0x00 ;     FlagEndMsg=0 ;
jmp SwitchLabelbreak;
            
 
 
LabelGPIBCase_B: ; B    end of  NB, NC,    begin of BE        AM,% for example  "B80." or "B80," , <=2 digits
                                  ;fix problem with init stack if mode was changed and leave digits if  no digis in message
ldi r19,  0x02  ;   remain_digits=2;
ldi r21 , 0x01  ;             NoComma=1;  
ldi r20 , 0x00 ;       
cpi r18,  MODE_PREP_EXT_MOD 
breq   LabelEXT_AM:
ldi r18, MODE_INT_AM
jmp SwitchLabelbreak;
LabelEXT_AM:
ldi r18, MODE_EXT_AM
jmp SwitchLabelbreak;
 
LabelGPIBCase_C:    ; C    end of  NB, NC,    begin of CE         , FM, kHz , <=3  digits 
                                    ;fix problem with init stack if mode was changed and leave digits if  no digis in message 
 
 
ldi r19,  0x03  ;  remain_digits=3; 
ldi r21 , 0x00  ;  NoComma=0;      
ldi r20 , 0x00 ;    FlagEndMsg=0 ;    
cpi r18, MODE_PREP_EXT_MOD
breq LabelGPIBExtFM
ldi r18, MODE_INT_FM
jmp SwitchLabelbreak;
LabelGPIBExtFM:
ldi r18, MODE_EXT_FM
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_K:  ; K   turn on output , 
                                    ; fix problem with init stack if mode was changed and leave digits if  no digis in message 
ldi r19,  0x04  ; remain_digits=4;
ldi r21 , 0x00  ;   NoComma=0;    
ldi r20 , 0x00 ;    FlagEndMsg=0 ;
ldi r18, MODE_TURN_ON_OUT ;   
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_L:      ; L  or "  output, mV, <=3.5 digits + comma
                                       ; fix problem with init stack if mode was changed and leave digits if  no digis in message 
ldi r19,  0x04  ;  remain_digits=4;
ldi r21 , 0x00  ;  NoComma=0;    
ldi r20 , 0x00 ;  FlagEndMsg=0 ;
ldi r18, MODE_TURN_ON_OUT_mV;
jmp SwitchLabelbreak;
                
LabelGPIBCase_M:  ; M  , for example,"M10.00",<=3.5 digits + comma
                                    ; fix problem with init stack if mode was changed and leave digits if  no digis in message 
 
ldi r19,  0x04   ;  remain_digits=4; 
ldi r21 , 0x00  ;  NoComma=0;    
ldi r20 , 0x00 ;  FlagEndMsg=0 ;
ldi r18, MODE_TURN_ON_OUT_mkV;            
jmp SwitchLabelbreak;
 
LabelGPIBCase_F: ; F   Finternal ,for example "F1,"
 
ldi r19,  0x01   ;            remain_digits=1; 
ldi r21 , 0x01  ;           NoComma=1;    
ldi r20 , 0x00 ;  FlagEndMsg=0 ;   
ldi r18, MODE_PREPSETFREQLFO; 
jmp SwitchLabelbreak;
 
LabelGPIBCase_default :
ldi r19,  0x00   ;
ldi r21 , 0x01  ; 
ldi r20 , 0x01;    
ldi r18, MODE_NOCMD; 
 call ExecCmd     ;  ExecCMD(FlagMode);         
 
SwitchLabelbreak:
  //fix problem with stack management 
 
//call SendDataAcceptedStrobe ;  //fix place of this subroutine ,fix name of subroutine 
ret
Добавлено через 3 часа 35 минут
https://www.avrfreaks.net/foru... n?page=all

Добавлено через 32 минуты
C++
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
#include <iostream>
#include <stdint.h>
using namespace std; 
struct divmod10_t
{
    uint32_t quot;
    uint8_t rem;
};
 
 
inline static divmod10_t divmodu10(uint32_t n)
{
    divmod10_t res;
// mul 0.8
    res.quot = (n >> 1);
    res.quot += res.quot >> 1;
    res.quot += res.quot >> 4;
    res.quot += res.quot >> 8;
    res.quot += res.quot >> 16;
    uint32_t qq = res.quot;
// div 8
    res.quot >>= 3;
// rem
    res.rem = uint8_t(n - ((res.quot << 1) + (qq & ~7ul)));
// corr rem , quot
    if(res.rem > 9)
    {
        res.rem -= 10;
        res.quot++;
    }
    
    
    return res;
}
 
int main ()
{
 
uint32_t i; 
for ( i=0; i<0xFFFFFFFF;i++ )
{
uint32_t delta=  divmodu10(i).quot -(i/10);
if (delta!=0) 
{
    
  cout<< "\n x= "<<hex<<i;
   cout<< " delta "<<hex<<delta;
    
}
 
}
 
 cout<< " end ";
 
 
 
}
Добавлено через 1 минуту
C++
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
#include <iostream>
#include <stdint.h>
using namespace std; 
struct divmod10_t
{
    uint32_t quot;
    uint8_t rem;
};
 
 
inline static divmod10_t divmodu10(uint32_t n)
{
    divmod10_t res;
// mul 0.8
    res.quot = (n >> 1);
    res.quot += res.quot >> 1;
    res.quot += res.quot >> 4;
    res.quot += res.quot >> 8;
    res.quot += res.quot >> 16;
    uint32_t qq = res.quot;
// div 8
    res.quot >>= 3;
// rem
    res.rem = uint8_t(n - ((res.quot << 1) + (qq & ~7ul)));
// corr rem , quot
    if(res.rem > 9)
    {
        res.rem -= 10;
        res.quot++;
    }
    
    
    return res;
}
 
int main ()
{
 
uint32_t i; 
for ( i=0; i<0xFFFFFFFF;i++ )
{
uint32_t delta=  divmodu10(i).quot -(i/10);
if (delta!=0) 
{
    
  cout<< "\n x= "<<hex<<i;
   cout<< " delta "<<hex<<delta;
    
}
 
}
 
 cout<< " end ";
 
 
 
}
Добавлено через 1 минуту
С http://we.easyelectronics.ru/S... hisla.html , на основе книги Уоррена «Алгоритмические трюки для программистов», проверка на вычисление .

Добавлено через 2 минуты
Code
1
cout<<hex<<(~7ul);   ->0x ff ff ff f8
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
23.03.2020, 19:19  [ТС]
В программу обработчика команд добавить обработчик кода пробела 0x20, на который программа не изменяет счетчик цифр, не добавляет запятой(если после цифр перед запятой ), не выполняет команды , но не переходит в режим выполнения команды , если ввести первой или перед командой .
На точку программа не выполняет команды , если введена в ТД первый раз , определяет положение запятой , в дальнейшем до ОД (запятая) не изменяет счетчик оставшихся цифр и байт положения децимальной точки (запятой в числе).
Несмотря на отсутствие в конце текста тестовой строки и нечеткое ( особенно в инструкции на Г4-176 )
отображение пробелов
Code
1
A520.1, B80, F1, M15.
в инструкции последняя команда не выполняется, пока не введут 0x2c , даже если после нее пробел (по точке второй раз не выполняется, хотя в тексте далее и в алгоритме об этом сказано (выполнение по запятой), но в Г4-176 в тексте это сказано с кавычками, которые не надо воспринимать как символ )

Code
1
2
3
4
5
6
7
8
A520.1, B80, F1, M15. ,
 
 
0x41 0x35 0x32 0x30  0x2e 0x31 0x2c  0x20 0x42 0x38 0x30 0x2c 0x20 0x46 0x31 0x2c 0x20 0x4D 0x31 0x35 0x2e 0x20 0x2c
 
или  
A520.1,B80,F1,M15.,
0x41 0x35 0x32 0x30  0x2e 0x31 0x2c    0x42 0x38 0x30 0x2c   0x46 0x31 0x2c   0x4D 0x31 0x35 0x2e   0x2c
Код 0x22 (' " 'для Г4-164) обычно выполняется в Г4-164 как и 0x4C ('L', по инструкции на РГ4-17-01) , записывать через дизъюнкцию условий (в некоторых партиях приборов после 1991 года инструкция бывает другой).


На самом деле алгоритм добавления в стек и исполнения по запятой может быть другим, а сортировка по одной команде из стека после приема запятой (как в алгоритме), но возможны варианты, пользовательски тождественные алгоритму в инструкции на случай замены микросхемы .

Добавлено через 29 секунд
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#include <stdio.h>
#include <stdint.h>
 
 uint8_t remain_digits=0;   
 uint8_t FlagEndMsg=0;
 uint8_t flagLFO=0; 
 uint8_t NoComma=0;
 uint8_t FlagMode=0;
#define MODE_NOCMD 0
#define MODE_TURN_OFF_OUT 1
#define MODE_TURN_OFF_6dB   2
#define MODE_TURN_ON_6dB     3
 
#define MODE_INT_AM  4  
#define MODE_EXT_AM 5
#define MODE_INT_FM 6
#define MODE_EXT_FM 7
#define MODE_TURN_ON_EXT_PM 8
#define MODE_TURN_ON_INT_PM 9
 
 
#define MODE_TURN_OFF_EXT_AM 10
#define MODE_TURN_OFF_INT_AM 11
#define MODE_TURN_OFF_EXT_FM 12
#define MODE_TURN_OFF_INT_FM 13 
#define MODE_TURN_OFF_PM  14
//#define MODE_TURN_OFF_EXT_PM  15
 
#define MODE_FREQ   16
#define MODE_PREP_EXT_MOD 17
#define MODE_TURN_ON_OUT 18
#define MODE_TURN_ON_OUT_dB 19
#define MODE_TURN_ON_OUT_mV 20
#define MODE_TURN_ON_OUT_mkV 21
#define MODE_PREPSETFREQLFO  22
 
#define MODE_SETFREQLFO0 30
#define MODE_SETFREQLFO1 31
#define MODE_SETFREQLFO2 32
#define MODE_SETFREQLFO3 33
#define MODE_SETFREQLFO4 34
#define MODE_SETFREQLFO5 35
#define MODE_SETFREQLFO6 36
#define MODE_SETFREQLFO7 37
 
 
#define  NUM_DIGITS_FREQ 7
#define  NUM_DIGITS_FM 3 
#define  NUM_DIGITS_AM 2
#define  NUM_DIGITS_OUT 4
 
 
uint8_t  GetByte()
{
uint8_t byte; 
printf("\n Input byte (0x41)  :   ");
scanf("%x",&byte);
//printf("\n      Send active signal  on Interrupt 3  ");
return byte; 
}
 
 
void ExecCMD(uint8_t mode)
{
 
switch (mode){
case MODE_NOCMD: 
 
              printf("\n No CMD  or error  ");
 
 
                             break;
case MODE_TURN_OFF_OUT: 
                printf("\n turn Off Out  "); 
                             break;
case MODE_TURN_OFF_6dB: 
                 printf("\n TURN OFF 6dB  "); 
                             break;
 
case MODE_TURN_ON_6dB: 
                 printf("\n TURN ON 6dB  "); 
                             break;
                             
case MODE_INT_AM: 
                 printf("\n TURN ON INT AM  "); 
                             break;
case MODE_EXT_AM: 
                 printf("\n TURN ON EXT AM  ");    
                             break;    
case MODE_INT_FM: 
                  printf("\n TURN INT FM  "); 
                             break;
case MODE_EXT_FM:  
                  printf("\n TURN EXT FM  "); 
                             break;                                                                               
 
case MODE_TURN_ON_EXT_PM:  
                  printf("\n TURN ON EXT PM  "); 
                             break; 
case MODE_TURN_ON_INT_PM:  
                  printf("\n TURN ON INT PM  "); 
                             break;
 case MODE_TURN_OFF_EXT_AM:  
                  printf("\n TURN ON EXT AM  "); 
                             break;
 case MODE_TURN_OFF_INT_AM:  
                  printf("\n TURN ON INT AM  "); 
                             break;
 case MODE_TURN_OFF_EXT_FM:  
                  printf("\n TURN ON EXT FM  "); 
                             break;
 case MODE_TURN_OFF_INT_FM:  
                  printf("\n TURN ON INT FM  "); 
                             break;                            
                             
 case MODE_TURN_OFF_PM:  
                  printf("\n MODE TURN OFF PM  "); 
                             break;                                    
 case MODE_FREQ:  
                  printf("\n MODE FREQ  "); 
                             break;  
                             
 case MODE_TURN_ON_OUT: 
                  printf("\n TURN ON OUT  ");                    
                 break; 
                     
                             
 case MODE_TURN_ON_OUT_dB:  
                  printf("\n TURN ON OUT dB  ");                     
                 break; 
 case MODE_TURN_ON_OUT_mV:  
                  printf("\n TURN ON OUT mV  ");                     
                 break; 
 case MODE_TURN_ON_OUT_mkV: 
                  printf("\n TURN ON OUT mkV  ");                    
                 break;                          
 case MODE_SETFREQLFO0: 
                  printf("\n MODE_SETFREQLFO0  ");                   
                 break;              
                 
 case MODE_SETFREQLFO1: 
                  printf("\n MODE_SETFREQLFO1  ");                   
                 break;              
                 
 case MODE_SETFREQLFO2: 
                  printf("\n MODE_SETFREQLFO2  ");                   
                 break;
 case MODE_SETFREQLFO3: 
                  printf("\n MODE_SETFREQLFO3 ");                    
                 break;              
 case MODE_SETFREQLFO4: 
                  printf("\n MODE_SETFREQLFO4  ");                   
                 break;              
 case MODE_SETFREQLFO5: 
                  printf("\n MODE_SETFREQLFO5  ");                   
                 break; 
 case MODE_SETFREQLFO6: 
                  printf("\n MODE_SETFREQLFO6  ");                   
                 break; 
 case MODE_SETFREQLFO7: 
                  printf("\n MODE_SETFREQLFO7  ");                   
                 break;                                                                  
                 
                                                                                                             
default :
 break;
 
 
}
 
 
return;
}
 
 
uint8_t GetNumDigitsMode(uint8_t counter,uint8_t FlagMode)
{
if(FlagMode==MODE_FREQ) {return 7; }
if(FlagMode==MODE_INT_AM) {return 2; } 
if(FlagMode==MODE_EXT_AM) {return 2; }  
if(FlagMode==MODE_INT_FM) {return 3; }  
if(FlagMode==MODE_EXT_FM) { return 3; }  
if(FlagMode==MODE_TURN_ON_OUT_dB) { return 4; } 
if(FlagMode==MODE_TURN_ON_OUT_mV) { return 4; }      
if(FlagMode==MODE_TURN_ON_OUT_mkV) { return 4; }    
    return 0;
}
 
 
void ParseCommaPos(uint8_t counter,uint8_t FlagMode)
{
uint8_t position ;
position=GetNumDigitsMode( counter, FlagMode)-counter-1;
printf ( "\n comma posistion in %d digit     ", position  );        
return; 
}
 
 
 
uint8_t digits[7] ; 
 
PutDigitToGPIBStackIfByte(uint8_t count, uint8_t  byte,   uint8_t FlagMode  )
{
uint8_t position ;
position=GetNumDigitsMode( count , FlagMode)-count ;
 
 
digits[position]=byte-0x30;  //fix
printf ( "\n %d digit is %d   ",   position, digits[position]  );
 
}
 
uint8_t GetModeLFOIfDigit(uint8_t byte)
{
 
if (byte==0x30) {    return MODE_SETFREQLFO0;   }
if (byte==0x31) {    return MODE_SETFREQLFO1;    }
if (byte==0x32) {    return MODE_SETFREQLFO2;    }
if (byte==0x33) {    return MODE_SETFREQLFO3;    }
if (byte==0x34) {    return MODE_SETFREQLFO4;    }
if (byte==0x35) {    return MODE_SETFREQLFO5;    }
if (byte==0x36) {    return MODE_SETFREQLFO6;    }
if (byte==0x37) {    return MODE_SETFREQLFO7;    }
if (byte==0x38) {    return MODE_NOCMD;   }
if (byte==0x39) {    return MODE_NOCMD;   }     
return 0;   
    
}   
    
 
 
 
void ResetLastDigits(uint8_t FlagMode, uint8_t count )
{
uint8_t nextpos ;
nextpos=GetNumDigitsMode( count  , FlagMode)-count +1   ;
    
for (uint8_t i=nextpos;i<=6;i++)    {  digits[i]=0; }
 
 
 
 
for (uint8_t i=0;i<=6;i++)  { printf("\n%d", digits[i] );   }
 
return ;    
}
 
/*
 
 7  0  digits[0] = 5
 6  1  digits[1] = 2
 5  2  digits[2] = 0    CommaPos=2
           
 4  3  digits[3] =1  
 3  4  digits[4]=0     auto 0 
 2  5  digits[5]=0     auto 0
 1  6  digits[6]=0     auto 0
 0  7  end
 
 3  0  
 2  1 
 1  2
 0  3  end
 
 2  0 digits[0]=8
 1  1 digits[1]=0
 0  2  end
 
 
 4  0 digits[0]=1
 3  1 digits[0]=0 CommaPos=1
 2  2 digits[0]=0
 1  3 digits[0]=0
 0  4  end
 
 
 
 
 
*/
 
 
 
 
 
void ParseCommand()
{
     
    
 //if GPIB, no blinking     , update after delimitter of the  command  was received 
 
uint8_t byte;
//byte=GetGPIBByte ();  //gets  TTL code from inverse code for LD bus  bits 
 
byte=GetByte ();
 
// asm("cli");
 
 if (byte==0x20)  {   // 'space'  
                     
                       
                       goto  SwitchLabelbreak;  
 
                      }
 
 
if (byte==0x2e)  {   // '.'            
 if ((FlagEndMsg==0)&&(NoComma==0) ) { ParseCommaPos(remain_digits, FlagMode);   NoComma=1; goto  SwitchLabelbreak; } 
 NoComma=1; 
 //ResetLastDigits(FlagMode, remain_digits);
 //ExecCMD(FlagMode);               
 //remain_digits=0;   
 //FlagEndMsg= 0;
 //FlagMode=MODE_NOCMD; 
 
 goto  SwitchLabelbreak;             
}
                
 
                 
 if (byte==0x2c){   //  ','                           
 ResetLastDigits(FlagMode, remain_digits);
 ExecCMD(FlagMode);                
 remain_digits=0;   
 FlagEndMsg= 0;
 FlagMode=MODE_NOCMD;  
 goto  SwitchLabelbreak;              
} 
 
if ((byte>=0x30)&&(byte<=0x39)) { //'0'...'9'
            
 if ( remain_digits>0) 
  {  
 if (FlagMode==MODE_PREPSETFREQLFO)  {  FlagMode=  GetModeLFOIfDigit(byte);   FlagEndMsg=1; remain_digits=0;     }          
 if (FlagMode==MODE_TURN_ON_OUT) { FlagMode= MODE_TURN_ON_OUT_dB;  } 
 else {   PutDigitToGPIBStackIfByte( remain_digits , byte, FlagMode  );    }   // put byte-0x30 to stack
 remain_digits--;
 }
 else { remain_digits=0;  FlagEndMsg=1;   printf("\n  remain_digits=0 FlagEnd=1");          }
goto  SwitchLabelbreak; }
 
 
if(byte==0x49) {//I   turn off output
                 remain_digits=0;         
                 FlagMode=MODE_TURN_OFF_OUT; 
                 FlagEndMsg=1;
                goto  SwitchLabelbreak;   }                 
 
             
if(byte==0x48){ //H  6 dB off
                 remain_digits=0; 
                FlagMode=MODE_TURN_OFF_6dB; 
                FlagEndMsg=1;
                goto  SwitchLabelbreak; }
if(byte==0x4F){ //O   turn on 6 dB  
                remain_digits=0; 
                FlagMode=MODE_TURN_ON_6dB; 
                FlagEndMsg=1;
                goto  SwitchLabelbreak;}    
 
if(byte==0x44){ //D   PM on ; off for ND  
 
                
                remain_digits=0; 
                if( FlagMode==MODE_PREP_EXT_MOD) {  FlagMode=MODE_TURN_ON_EXT_PM; }  else {  FlagMode=MODE_TURN_ON_INT_PM; }
                FlagEndMsg=1;
                goto  SwitchLabelbreak;}
 
 
if(byte==0x45){ //E  PM off, end for BE,CE     
                remain_digits=0; 
                if(FlagMode==MODE_EXT_AM) {   FlagMode=MODE_TURN_OFF_EXT_AM; }
                if(FlagMode==MODE_INT_AM) {   FlagMode=MODE_TURN_OFF_INT_AM; }
                if(FlagMode==MODE_EXT_FM) {   FlagMode=MODE_TURN_OFF_EXT_FM; }
                if(FlagMode==MODE_INT_FM) {   FlagMode=MODE_TURN_OFF_INT_FM; } else  {   FlagMode=MODE_TURN_OFF_PM; }             
                FlagEndMsg=1;
                goto  SwitchLabelbreak;}
 
if(byte==0x41) {  //A      freq  , for example "A520.100,B80." or "A520.100," <=7 digits + comma
                  //fix problem with init stack if mode was changed 
                     remain_digits=7;
                     FlagMode=MODE_FREQ; 
                     NoComma=0;
                     FlagEndMsg=0 ;                                       
                     goto  SwitchLabelbreak;}
 
if(byte==0x4e){ //N , for example "NB,","NB20,",  "NРЎ,","ND" ,"NC100,"
 
               remain_digits=1;
               FlagMode=MODE_PREP_EXT_MOD;    
               FlagEndMsg=0 ;
               goto  SwitchLabelbreak;}   
            
 
 
if(byte==0x42){ //B    end of  NB, NC,    begin of BE        AM,% for example  "B80." or "B80," , <=2 digits
  //fix problem with init stack if mode was changed and leave digits if  no digis in message
             remain_digits=2;
             NoComma=1;           
              if (FlagMode==MODE_PREP_EXT_MOD) {  FlagMode=MODE_EXT_AM ; }       else  {  FlagMode=MODE_INT_AM ;  } 
               FlagEndMsg=0 ; 
               goto  SwitchLabelbreak;}
    
if(byte==0x43){ //C    end of  NB, NC,    begin of CE         , FM, kHz , <=3  digits 
  //fix problem with init stack if mode was changed and leave digits if  no digis in message 
                remain_digits=3; 
                NoComma=0;          
                if (FlagMode==MODE_PREP_EXT_MOD)   {  FlagMode=MODE_EXT_FM ; }   else  {  FlagMode=MODE_INT_FM ;  } 
                FlagEndMsg=0 ; 
                goto  SwitchLabelbreak;}
 
 
if(byte==0x4B){ //K   turn on output , 
 //fix problem with init stack if mode was changed and leave digits if  no digis in message 
                 remain_digits=4;
                 NoComma=0;    
                FlagMode=MODE_TURN_ON_OUT ;   /*  if  only K , turn on output            */
                FlagEndMsg=0 ;
                goto  SwitchLabelbreak;}
 
if((byte==0x4C)||(byte==0x22)){     // L           output, mV, <=3.5 digits + comma
  // "  
//fix problem with init stack if mode was changed and leave digits if  no digis in message 
                 remain_digits=4;
                 NoComma=0;    
                FlagMode=MODE_TURN_ON_OUT_mV;
                FlagEndMsg=0 ;
               goto  SwitchLabelbreak;  }               
if(byte==0x4D) //M  , for example,"M10.00",<=3.5 digits + comma
//fix problem with init stack if mode was changed and leave digits if  no digis in message 
{
               remain_digits=4; 
               NoComma=0;    
               FlagMode=MODE_TURN_ON_OUT_mkV;            
               FlagEndMsg=0 ;
               goto  SwitchLabelbreak;      
}
if(byte==0x46) //F   Finternal ,for example "F1,"
{
           remain_digits=1; 
           NoComma=1;       
          FlagMode=MODE_PREPSETFREQLFO; 
          FlagEndMsg=0;
          goto  SwitchLabelbreak;
}
 
//fix 
           remain_digits=0;
           NoComma=1;    
           FlagMode=MODE_NOCMD; 
           
           FlagEndMsg=1 ;
           ExecCMD(FlagMode);    
           
 
SwitchLabelbreak:
//fix problem with stack management 
 
//SendDataAcceptedStrobe();  //fix place of this subroutine ,fix name of subroutine 
 //asm("sei");
return; 
}
 
 
 
 
int main()
{
 
label1:
printf("\n Input command  bytes (  A520.1, B80, F1, M15. ,  ) ");  //fix 0x2e problem for end of message 
printf("\n Input command  bytes \n(  0x41 0x35 0x32 0x30  0x2e 0x31 0x2c"); 
ParseCommand(); //A 0x41
ParseCommand(); //5 0x35
ParseCommand(); //2 0x32
ParseCommand(); //0 0x30
ParseCommand(); //.0x2e
ParseCommand(); //1 0x31
ParseCommand(); //, 0x2c
printf("\n Input command   0x20 0x42 0x38 0x30 0x2c 0x20 0x46 0x31 0x2c 0x20 0x4D 0x31 0x35 0x2e 0x20 0x2c ) ");  //fix 0x2e problem for end of message 
ParseCommand(); //  0x20
ParseCommand(); //B 0x42
ParseCommand(); //8 0x38
ParseCommand(); //0 0x30
ParseCommand(); //, 0x2c
 
 
ParseCommand(); //  0x20
ParseCommand(); //F 0x46
ParseCommand(); //1 0x31
ParseCommand(); //, 0x2c
ParseCommand(); //  0x20
ParseCommand(); //M 0x4D
ParseCommand(); //1 0x31
ParseCommand(); //5 0x35
ParseCommand(); //. 0x2e    
ParseCommand(); // 0x20  
ParseCommand(); // 0x2c
    
printf ("\n Inpuit 1 for exit or 0 for next command ");
int key;
scanf("%d",&key);
if (key==0) {goto label1; }
 
 
 
}
Добавлено через 6 минут
Assembler
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
ParseCommand: 
 
 
; r0
; r1
; r2
; r3
; r4
; r5
; r6
 
; r8
 
 
     
call   GetGPIBByte;  fix reg    
 
mov r16, r17
 
cpi  r16, 0x20
breq LabelGPIBCase_space 
 cpi  r16, 0x2e
breq LabelGPIBCase_dot 
cpi  r16, 0x2c 
breq LabelGPIBCase_comma 
mov r16, r17
cpi  r16, 0x30
brge  LabelGPIBtest_if_digit2
jmp LabelGPIBif_nodigits2
LabelGPIBtest_if_digit2:
mov r16, r17
cpi  r16, 0x3a 
brlo  LabelGPIBCase_digits  
if_nodigits2:
mov r16, r17
cpi  r16, 0x49
breq LabelGPIBCase_I
cpi  r16, 0x48
breq LabelGPIBCase_H
cpi  r16, 0x4F
breq LabelGPIBCase_O
cpi  r16, 0x44
breq LabelGPIBCase_D
cpi  r16, 0x45
breq LabelGPIBCase_E
cpi  r16, 0x41
breq LabelGPIBCase_A
cpi  r16, 0x4e
breq LabelGPIBCase_N
cpi  r16, 0x42
breq LabelGPIBCase_B
cpi  r16, 0x43
breq LabelGPIBCase_C
cpi  r16, 0x4b
breq LabelGPIBCase_K
cpi  r16, 0x4c
breq LabelGPIBCase_L
cpi  r16, 0x22
breq LabelGPIBCase_L
cpi  r16, 0x4d
breq LabelGPIBCase_M
cpi  r16, 0x46
breq LabelGPIBCase_F
jmp   LabelGPIBCase_default
;ret
 
 
; r16 tmp 
; r17 GPIB byte 
; r18   FlagMode  
; r19    remain_digits    
; r20  FlagEndMsg
; r21  NoComma
 
LabelGPIBCase_space:
 
jmp SwitchLabelbreak; 
 
 
 
 
LabelGPIBCase_dot :    // '.'     
 
cpi  r20, 0    
brne LabelNoComma
cpi  r21, 0    
brne LabelNoComma
 
call ParseCommaPos ; remain_digits, FlagMode ;   
ldi r21, 0x01  
jmp SwitchLabelbreak; 
 
LabelNoComma:
 
jmp SwitchLabelbreak;            
 
                 
LabelGPIBCase_comma: ;  ','                           
 call ResetLastDigits ; FlagMode, remain_digits ;
 call ExecCMD  ; r18 FlagMode, ExecCMD(FlagMode);                
ldi r19, 0; 
ldi r20, 0;  
ldi r18, MODE_NOCMD;  
jmp SwitchLabelbreak; 
 
LabelGPIBCase_digits:   ; '0'...'9'
 
cpi  r19, 0 ; if ( remain_digits>0)
brne LabelGPIB_EndNumMsg ;
 
cpi r18, MODE_PREPSETFREQLFO
brne   LabelGPIB_NotLFOMode
call GetModeLFOIfDigit ; FlagMode=  GetModeLFOIfDigit(byte)
ldi r20, 1; FlagEndMsg=1;
ldi r19, 0; remain_digits=0; 
 
LabelGPIB_NotLFOMode:
cpi r18, MODE_TURN_ON_OUT
brne  LabelPutDigitToGPIB
ldi r18, MODE_TURN_ON_OUT_dB
jmp LabelDecRem  
LabelPutDigitToGPIB:
call PutDigitToGPIBStackIfByte ; ( remain_digits , byte, FlagMode  );
 
LabelDecRem:      
dec r19; remain_digits--;
 jmp SwitchLabelbreak;
 
 
LabelGPIB_EndNumMsg:
 ldi r19, 0;      remain_digits  
ldi r20 , 0x01; FlagEndMsg=1
  
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_I:  ;I   turn off output
ldi r19, 0;         
ldi r18, MODE_TURN_OFF_OUT; 
ldi r20 , 0x01;   FlagEndMsg=1;
jmp SwitchLabelbreak;                   
 
             
LabelGPIBCase_H:  ; H  6 dB off
ldi r19, 0; remain_digits=0; 
ldi r18, MODE_TURN_OFF_6dB; 
ldi r20 , 0x01;  FlagEndMsg=1;
jmp SwitchLabelbreak;
 
LabelGPIBCase_O: ; O   turn on 6 dB  
ldi r19, 0; remain_digits=0; 
ldi r18, MODE_TURN_ON_6dB; 
ldi r20 , 0x01; FlagEndMsg=1;
jmp SwitchLabelbreak;   
 
LabelGPIBCase_D:  ; D   PM on ; off for ND  
ldi r19, 0; 
cpi r18, MODE_PREP_EXT_MOD
breq LabelGPIBExtMod
ldi r18, MODE_TURN_ON_INT_PM
ldi r20 , 0x01; FlagEndMsg=1;
jmp SwitchLabelbreak;
LabelGPIBExtMod:
ldi r18, MODE_TURN_ON_EXT_PM
ldi r20 , 0x01; FlagEndMsg=1;
jmp SwitchLabelbreak;                
 
 
 
LabelGPIBCase_E: ; E  PM off, end for BE,CE     
ldi r19, 0;  remain_digits=0; 
ldi r20 , 0x01; FlagEndMsg=1;
cpi r18, MODE_EXT_AM
breq  LabelGPIB_EXT_AM
cpi r18, MODE_INT_AM
breq  LabelGPIB_INT_AM
cpi r18, MODE_EXT_FM
breq  LabelGPIB_EXT_FM
cpi r18, MODE_INT_FM
breq  LabelGPIB_INT_FM
ldi r18, MODE_TURN_OFF_PM
jmp SwitchLabelbreak;
 
LabelGPIB_EXT_AM:
ldi r18, MODE_TURN_OFF_EXT_AM
jmp SwitchLabelbreak;
 
LabelGPIB_INT_AM:
ldi r18, MODE_TURN_OFF_INT_AM
jmp SwitchLabelbreak;
LabelGPIB_EXT_FM:
ldi r18, MODE_TURN_OFF_EXT_FM
jmp SwitchLabelbreak;
 
LabelGPIB_INT_FM:
ldi r18, MODE_TURN_OFF_INT_FM
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_A: ; A      freq  , for example "A520.100,B80." or "A520.100," <=7 digits + comma
                                  ;fix problem with init stack if mode was changed 
ldi r19,  0x07  ;  remain_digits=7;
ldi r18,  MODE_FREQ; 
ldi r21 , 0x00       ;  NoComma=0;
ldi r20 , 0x00       ;   FlagEndMsg=0 ;                                       
jmp SwitchLabelbreak;
 
LabelGPIBCase_N: ; N , for example "NB,","NB20,",  "NС,","ND" ,"NC100,"
 
ldi r19,  0x01  ;   remain_digits=1;
ldi r18,  MODE_PREP_EXT_MOD ;    
ldi r20 , 0x00 ;     FlagEndMsg=0 ;
jmp SwitchLabelbreak;
            
 
 
LabelGPIBCase_B: ; B    end of  NB, NC,    begin of BE        AM,% for example  "B80." or "B80," , <=2 digits
                                  ;fix problem with init stack if mode was changed and leave digits if  no digis in message
ldi r19,  0x02  ;   remain_digits=2;
ldi r21 , 0x01  ;             NoComma=1;  
ldi r20 , 0x00 ;       
cpi r18,  MODE_PREP_EXT_MOD 
breq   LabelEXT_AM:
ldi r18, MODE_INT_AM
jmp SwitchLabelbreak;
LabelEXT_AM:
ldi r18, MODE_EXT_AM
jmp SwitchLabelbreak;
 
LabelGPIBCase_C:    ; C    end of  NB, NC,    begin of CE         , FM, kHz , <=3  digits 
                                    ;fix problem with init stack if mode was changed and leave digits if  no digis in message 
 
 
ldi r19,  0x03  ;  remain_digits=3; 
ldi r21 , 0x00  ;  NoComma=0;      
ldi r20 , 0x00 ;    FlagEndMsg=0 ;    
cpi r18, MODE_PREP_EXT_MOD
breq LabelGPIBExtFM
ldi r18, MODE_INT_FM
jmp SwitchLabelbreak;
LabelGPIBExtFM:
ldi r18, MODE_EXT_FM
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_K:  ; K   turn on output , 
                                    ; fix problem with init stack if mode was changed and leave digits if  no digis in message 
ldi r19,  0x04  ; remain_digits=4;
ldi r21 , 0x00  ;   NoComma=0;    
ldi r20 , 0x00 ;    FlagEndMsg=0 ;
ldi r18, MODE_TURN_ON_OUT ;   
jmp SwitchLabelbreak;
 
 
LabelGPIBCase_L:      ; L  or "  output, mV, <=3.5 digits + comma
                                       ; fix problem with init stack if mode was changed and leave digits if  no digis in message 
ldi r19,  0x04  ;  remain_digits=4;
ldi r21 , 0x00  ;  NoComma=0;    
ldi r20 , 0x00 ;  FlagEndMsg=0 ;
ldi r18, MODE_TURN_ON_OUT_mV;
jmp SwitchLabelbreak;
                
LabelGPIBCase_M:  ; M  , for example,"M10.00",<=3.5 digits + comma
                                    ; fix problem with init stack if mode was changed and leave digits if  no digis in message 
 
ldi r19,  0x04   ;  remain_digits=4; 
ldi r21 , 0x00  ;  NoComma=0;    
ldi r20 , 0x00 ;  FlagEndMsg=0 ;
ldi r18, MODE_TURN_ON_OUT_mkV;            
jmp SwitchLabelbreak;
 
LabelGPIBCase_F: ; F   Finternal ,for example "F1,"
 
ldi r19,  0x01   ;            remain_digits=1; 
ldi r21 , 0x01  ;           NoComma=1;    
ldi r20 , 0x00 ;  FlagEndMsg=0 ;   
ldi r18, MODE_PREPSETFREQLFO; 
jmp SwitchLabelbreak;
 
LabelGPIBCase_default :   //fix 
ldi r19,  0x00   ;
ldi r21 , 0x01  ; 
ldi r20 , 0x01;    
ldi r18, MODE_NOCMD; 
 call ExecCmd     ;  ExecCMD(FlagMode);         
 
SwitchLabelbreak:
  //fix problem with stack management 
 
//call SendDataAcceptedStrobe ;  //fix place of this subroutine ,fix name of subroutine 
ret
Добавлено через 4 минуты
Для ускорения обработки данных в момент приема байтов приборных сообщений по КОП по алгоритму "рукопожатия" до символа ОД(запятая) скорее всего вначале команду (байты ) переписывают в стек по запятой (ОД), после чего сортируют по признакам , как в инструкции , стек ограничить 10...15 байтами , очищать при приеме новой команды (правильно как в алгоритме из инструкции, но там обобщенно и упрощенно об этом сказано ).

Добавлено через 18 минут
При вводе в ТД после ЗД вначале точки без нуля перед ней , а потом цифр правильно автозаполнять нуль перед запятой (дорабатывать ).

Добавлено через 4 минуты
Изменить направление счета счетчика цифр и доработать программу (в 0 позиции если вначале запятая , выдает 255 ячейку , должен ноль и автозаполнить нулем перед ним (нулевую ячейку ) , кажется так, уточню потом ).

Добавлено через 55 секунд
Тогда ,кажется, еще один регистр или зависимость от вводимого режима требуется .
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
23.03.2020, 21:26  [ТС]
C++
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#include <stdio.h>
#include <stdint.h>
 
 uint8_t  inputdigitnum=0;   
 uint8_t FlagMsg=0;
 uint8_t flagLFO=0; 
 uint8_t FlagGetComma=0;
 uint8_t FlagMode=0;
#define MODE_NOCMD 0
#define MODE_TURN_OFF_OUT 1
#define MODE_TURN_OFF_6dB   2
#define MODE_TURN_ON_6dB     3
 
#define MODE_INT_AM  4  
#define MODE_EXT_AM 5
#define MODE_INT_FM 6
#define MODE_EXT_FM 7
#define MODE_TURN_ON_EXT_PM 8
#define MODE_TURN_ON_INT_PM 9
 
 
#define MODE_TURN_OFF_EXT_AM 10
#define MODE_TURN_OFF_INT_AM 11
#define MODE_TURN_OFF_EXT_FM 12
#define MODE_TURN_OFF_INT_FM 13 
#define MODE_TURN_OFF_PM  14
//#define MODE_TURN_OFF_EXT_PM  15
 
#define MODE_FREQ   16
#define MODE_PREP_EXT_MOD 17
#define MODE_TURN_ON_OUT 18
#define MODE_TURN_ON_OUT_dB 19
#define MODE_TURN_ON_OUT_mV 20
#define MODE_TURN_ON_OUT_mkV 21
#define MODE_PREPSETFREQLFO  22
 
#define MODE_SETFREQLFO0 30
#define MODE_SETFREQLFO1 31
#define MODE_SETFREQLFO2 32
#define MODE_SETFREQLFO3 33
#define MODE_SETFREQLFO4 34
#define MODE_SETFREQLFO5 35
#define MODE_SETFREQLFO6 36
#define MODE_SETFREQLFO7 37
 
 
#define  NUM_DIGITS_FREQ 7
#define  NUM_DIGITS_FM 3 
#define  NUM_DIGITS_AM 2
#define  NUM_DIGITS_OUT 4
 
 
uint8_t  GetByte()
{
uint8_t byte; 
printf("\n Input byte (0x41)  :   ");
scanf("%s",&byte);
//printf("\n      Send active signal  on Interrupt 3  ");
return byte; 
}
 
 
void ExecCMD(uint8_t mode)
{
 
switch (mode){
case MODE_NOCMD: 
 
              printf("\n\t\t\t\t  No CMD  or error  ");
 
 
                             break;
case MODE_TURN_OFF_OUT: 
                printf("\n\t\t\t\t  turn Off Out  "); 
                             break;
case MODE_TURN_OFF_6dB: 
                 printf("\n\t\t\t\t  TURN OFF 6dB  "); 
                             break;
 
case MODE_TURN_ON_6dB: 
                 printf("\n\t\t\t\t  TURN ON 6dB  "); 
                             break;
                             
case MODE_INT_AM: 
                 printf("\n\t\t\t\t  TURN ON INT AM  "); 
                             break;
case MODE_EXT_AM: 
                 printf("\n\t\t\t\t  TURN ON EXT AM  ");    
                             break;    
case MODE_INT_FM: 
                  printf("\n\t\t\t\t  TURN INT FM  "); 
                             break;
case MODE_EXT_FM:  
                  printf("\n\t\t\t\t  TURN EXT FM  "); 
                             break;                                                                               
 
case MODE_TURN_ON_EXT_PM:  
                  printf("\n\t\t\t\t  TURN ON EXT PM  "); 
                             break; 
case MODE_TURN_ON_INT_PM:  
                  printf("\n\t\t\t\t  TURN ON INT PM  "); 
                             break;
 case MODE_TURN_OFF_EXT_AM:  
                  printf("\n\t\t\t\t  TURN ON EXT AM  "); 
                             break;
 case MODE_TURN_OFF_INT_AM:  
                  printf("\n\t\t\t\t  TURN ON INT AM  "); 
                             break;
 case MODE_TURN_OFF_EXT_FM:  
                  printf("\n\t\t\t\t  TURN ON EXT FM  "); 
                             break;
 case MODE_TURN_OFF_INT_FM:  
                  printf("\n\t\t\t\t  TURN ON INT FM  "); 
                             break;                            
                             
 case MODE_TURN_OFF_PM:  
                  printf("\n\t\t\t\t  MODE TURN OFF PM  "); 
                             break;                                    
 case MODE_FREQ:  
                  printf("\n\t\t\t\t  MODE FREQ  "); 
                             break;  
                             
 case MODE_TURN_ON_OUT: 
                  printf("\n\t\t\t\t  TURN ON OUT  ");                   
                 break; 
                     
                             
 case MODE_TURN_ON_OUT_dB:  
                  printf("\n\t\t\t\t  TURN ON OUT dB  ");                    
                 break; 
 case MODE_TURN_ON_OUT_mV:  
                  printf("\n\t\t\t\t  TURN ON OUT mV  ");                    
                 break; 
 case MODE_TURN_ON_OUT_mkV: 
                  printf("\n\t\t\t\t  TURN ON OUT mkV  ");                   
                 break;                          
 case MODE_SETFREQLFO0: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO0  ");                      
                 break;              
                 
 case MODE_SETFREQLFO1: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO1  ");                      
                 break;              
                 
 case MODE_SETFREQLFO2: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO2  ");                      
                 break;
 case MODE_SETFREQLFO3: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO3 ");                   
                 break;              
 case MODE_SETFREQLFO4: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO4  ");                      
                 break;              
 case MODE_SETFREQLFO5: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO5  ");                      
                 break; 
 case MODE_SETFREQLFO6: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO6  ");                      
                 break; 
 case MODE_SETFREQLFO7: 
                  printf("\n\t\t\t\t  MODE_SETFREQLFO7  ");                      
                 break;                                                                  
                 
                                                                                                             
default :
 break;
 
 
}
 
 
return;
}
 
 
uint8_t GetNumDigitsMode( uint8_t FlagMode)
{
if(FlagMode==MODE_FREQ) {return 7; }
if(FlagMode==MODE_INT_AM) {return 2; } 
if(FlagMode==MODE_EXT_AM) {return 2; }  
if(FlagMode==MODE_INT_FM) {return 3; }  
if(FlagMode==MODE_EXT_FM) { return 3; }  
if(FlagMode==MODE_TURN_ON_OUT_dB) { return 4; } 
if(FlagMode==MODE_TURN_ON_OUT_mV) { return 4; }      
if(FlagMode==MODE_TURN_ON_OUT_mkV) { return 4; }    
    return 0;
}
 
 
 
 
 
 
uint8_t digits[7] ;
 
void ParseCommaPos(uint8_t   counter, uint8_t FlagMode)
{
 
printf ( "\n\t\t\t\t comma posistion in %d digit     ",   counter  );       
return; 
}
 
 
 
 
 
PutDigitToGPIBStackIfByte(uint8_t count, uint8_t  byte,   uint8_t FlagMode  )
{
 
 
 
 
digits[count]=byte-0x30;     
printf ( "\n\t\t\t\t %d digit is %d   ",   count , digits[count ]  );
 
}
 
uint8_t GetModeLFOIfDigit(uint8_t byte)
{
 
if (byte==0x30) {    return MODE_SETFREQLFO0;   }
if (byte==0x31) {    return MODE_SETFREQLFO1;    }
if (byte==0x32) {    return MODE_SETFREQLFO2;    }
if (byte==0x33) {    return MODE_SETFREQLFO3;    }
if (byte==0x34) {    return MODE_SETFREQLFO4;    }
if (byte==0x35) {    return MODE_SETFREQLFO5;    }
if (byte==0x36) {    return MODE_SETFREQLFO6;    }
if (byte==0x37) {    return MODE_SETFREQLFO7;    }
if (byte==0x38) {    return MODE_NOCMD;   }
if (byte==0x39) {    return MODE_NOCMD;   }     
return 0;   
    
}   
    
 
 
 
void SetLastDigitsZero(uint8_t FlagMode, uint8_t count )
{
 
if( GetNumDigitsMode(   FlagMode)!=0) { 
 
    
 for (uint8_t i=count;i<=6;i++) {  digits[i]=0; }   //clear temp GPIB stack 
}
 
 
 
 for (uint8_t i=0;i<GetNumDigitsMode(FlagMode); i++)    { printf("\n%d", digits[i] );   }
 
return ;    
}
 
/*
 
    0  digits[0] = 5
    1  digits[1] = 2
    2  digits[2] = 0    CommaPos=2
           
    3  digits[3] =1  
    4  digits[4]=0     auto 0 
    5  digits[5]=0     auto 0
    6  digits[6]=0     auto 0
    7  end
 
    0  digits[0]  
    1  digits[1]   
    2  digits[2]  
    3  end
 
 2  0 digits[0]=8
 1  1 digits[1]=0
 0  2  end
 
 
 4  0 digits[0]=1
 3  1 digits[0]=0 CommaPos=1
 2  2 digits[0]=0
 1  3 digits[0]=0
 0  4  end
 
 
 
 
 
*/
 
 
 
 
 
void ParseCommand()
{
     
    
 
 
uint8_t byte;
//byte=GetGPIBByte ();  //gets  TTL code from inverse code for LD bus  bits 
 
byte=GetByte ();
 
 
 
 if (byte==0x20)  {   // 'space'     
                       goto  SwitchLabelbreak;  
 
                      }
 
 
if (byte==0x2e)  {   // '.' 
           
if ((FlagMsg==1)&&(FlagGetComma==1) )  
{ 
 
if(inputdigitnum==0) { PutDigitToGPIBStackIfByte( inputdigitnum, 0x30, FlagMode  ); ParseCommaPos( inputdigitnum, FlagMode);  inputdigitnum++;   }
else { ParseCommaPos( ( inputdigitnum-1), FlagMode); }
 
FlagGetComma=0; 
goto  SwitchLabelbreak; 
} 
 
FlagGetComma=0;
 
 goto  SwitchLabelbreak;             
}
                
 
                 
 if (byte==0x2c){   //  ','  
                         
SetLastDigitsZero(FlagMode, inputdigitnum);
 ExecCMD(FlagMode);                
 inputdigitnum=0;   
 FlagMsg= 0;
 FlagMode=MODE_NOCMD;  
 goto  SwitchLabelbreak;              
} 
 
if ((byte>=0x30)&&(byte<=0x39)) { //'0'...'9'
 
  
if (FlagMode==MODE_PREPSETFREQLFO)  {  FlagMode=  GetModeLFOIfDigit(byte);   FlagMsg=0; goto  SwitchLabelbreak;}        
if (FlagMode==MODE_TURN_ON_OUT) { FlagMode= MODE_TURN_ON_OUT_dB;  } 
if  ((inputdigitnum+1)>GetNumDigitsMode(FlagMode)  )  { FlagMsg=0;   goto  SwitchLabelbreak;    }
if ( FlagMsg==1){  PutDigitToGPIBStackIfByte( inputdigitnum , byte, FlagMode  ); inputdigitnum++;      goto  SwitchLabelbreak;    }
 
goto  SwitchLabelbreak; 
}
 
 
if(byte==0x49) {//I   turn off output
                 FlagMsg=0 ;     
                 FlagMode=MODE_TURN_OFF_OUT; 
                 
                goto  SwitchLabelbreak;   }                 
 
             
if(byte==0x48){ //H  6 dB off
                FlagMsg=0 ;
                FlagMode=MODE_TURN_OFF_6dB; 
                
                goto  SwitchLabelbreak; }
if(byte==0x4F){ //O   turn on 6 dB  
                FlagMsg=0 ;
                FlagMode=MODE_TURN_ON_6dB; 
                
                goto  SwitchLabelbreak;}    
 
if(byte==0x44){ //D   PM on ; off for ND  
  FlagMsg=0 ;
  if( FlagMode==MODE_PREP_EXT_MOD) 
  {  FlagMode=MODE_TURN_ON_EXT_PM; }  else {  FlagMode=MODE_TURN_ON_INT_PM; }
                
                goto  SwitchLabelbreak;}
 
 
if(byte==0x45){ //E  PM off, end for BE,CE     
                FlagMsg=0 ;  
                if(FlagMode==MODE_EXT_AM) {   FlagMode=MODE_TURN_OFF_EXT_AM; }
                if(FlagMode==MODE_INT_AM) {   FlagMode=MODE_TURN_OFF_INT_AM; }
                if(FlagMode==MODE_EXT_FM) {   FlagMode=MODE_TURN_OFF_EXT_FM; }
                if(FlagMode==MODE_INT_FM) {   FlagMode=MODE_TURN_OFF_INT_FM; } else  {   FlagMode=MODE_TURN_OFF_PM; }             
                
                goto  SwitchLabelbreak;}
 
if(byte==0x41) {  //A      freq  , for example "A520.100,B80." or "A520.100," <=7 digits + comma
                  FlagGetComma=1;
                  FlagMsg=1 ; 
                  inputdigitnum=0;
                  FlagMode=MODE_FREQ; 
                                                       
                   goto  SwitchLabelbreak;}
 
if(byte==0x4e){ //N , for example "NB,","NB20,",  "NС,","ND" ,"NC100,"
 
               FlagGetComma=1; 
               FlagMode=MODE_PREP_EXT_MOD;    
               FlagMsg=1 ;
               goto  SwitchLabelbreak;}   
            
 
 
if(byte==0x42){ //B    end of  NB, NC,    begin of BE        AM,% for example  "B80." or "B80," , <=2 digits
             FlagMsg=1 ;   
             inputdigitnum=0;
             FlagGetComma=1;           
               if (FlagMode==MODE_PREP_EXT_MOD) {  FlagMode=MODE_EXT_AM ; }  else  {  FlagMode=MODE_INT_AM ;  } 
                
               goto  SwitchLabelbreak;}
    
if(byte==0x43){ //C    end of  NB, NC,    begin of CE         , FM, kHz , <=3  digits 
 
                inputdigitnum=0;
                FlagGetComma=1;  
                FlagMsg=1 ;         
                if (FlagMode==MODE_PREP_EXT_MOD)   {  FlagMode=MODE_EXT_FM ; }   else  {  FlagMode=MODE_INT_FM ;  } 
                
                goto  SwitchLabelbreak;}
 
 
if(byte==0x4B){ //K   turn on output , 
 
                inputdigitnum=0; 
                FlagGetComma=1; 
                FlagMsg=1 ;   
                FlagMode=MODE_TURN_ON_OUT ;   /*  if  only K , turn on output            */
                
                goto  SwitchLabelbreak;}
 
if((byte==0x4C)||(byte==0x22)){     // L           output, mV, <=3.5 digits + comma
                
                 inputdigitnum=0;
                 FlagGetComma=1; 
                 FlagMsg=1 ;   
                 FlagMode=MODE_TURN_ON_OUT_mV;
                
               goto  SwitchLabelbreak;  }               
if(byte==0x4D){ //M  , for example,"M10.00," 
               inputdigitnum=0;                
               FlagGetComma=1; 
               FlagMsg=1 ;   
               FlagMode=MODE_TURN_ON_OUT_mkV;            
               
               goto  SwitchLabelbreak;      
}
if(byte==0x46) //F   Finternal ,for example "F1,"
{
           inputdigitnum=0;  
           FlagGetComma=0; 
           FlagMsg=1;      
          FlagMode=MODE_PREPSETFREQLFO; 
          
          goto  SwitchLabelbreak;
}
 
//fix 
           inputdigitnum=0; 
           FlagGetComma=0; 
           FlagMsg=0 ;   
           FlagMode=MODE_NOCMD; 
           
           
           ExecCMD(FlagMode);    
           
 
SwitchLabelbreak:
//fix problem with stack management 
 
//SendDataAcceptedStrobe();  //fix place of this subroutine ,fix name of subroutine 
  
return; 
}
 
 
 
 
int main()
{
 
label1:
printf("\n Input command  bytes (  A520.1, B80, F1, M10.2 ,  ) ");  //fix 0x2e problem for end of message 
//printf("\n Input command  bytes \n(  0x41 0x35 0x32 0x30  0x2e 0x31 0x2c"); 
ParseCommand(); //A 0x41
ParseCommand(); //5 0x35
ParseCommand(); //2 0x32
ParseCommand(); //0 0x30
ParseCommand(); //.0x2e
ParseCommand(); //1 0x31
ParseCommand(); //, 0x2c
//printf("\n Input command   0x20 0x42 0x38 0x30 0x2c 0x20 0x46 0x31 0x2c 0x20 0x4D 0x31 0x35 0x2e 0x20 0x2c ) ");  //fix 0x2e problem for end of message 
ParseCommand(); //  0x20
ParseCommand(); //B 0x42
ParseCommand(); //8 0x38
ParseCommand(); //0 0x30
ParseCommand(); //, 0x2c
 
 
ParseCommand(); //  0x20
ParseCommand(); //F 0x46
ParseCommand(); //1 0x31
ParseCommand(); //, 0x2c
ParseCommand(); //  0x20
ParseCommand(); //M 0x4D
ParseCommand(); //1 0x31
ParseCommand(); //5 0x35
ParseCommand(); //. 0x2e    
ParseCommand(); // 0x20  
ParseCommand(); // 0x2c
    
printf ("\n Inpuit 1 for exit or 0 for next command ");
int key;
scanf("%d",&key);
if (key==0) {goto label1; }
 
 
 
}
0
10 / 10 / 0
Регистрация: 29.06.2018
Сообщений: 1,536
27.03.2020, 21:06  [ТС]
Деление на 5 и на 10 через ряды вида
Code
1
data= (n>>3)-(n>>5)+(n>>7)-(n>>9)+(n>>11)-(n>>13)+(n>>15)- (n>>17)+(n>>19)-(n>>21)+(n>>23)-(n>>25)+(n>>27)-(n>>29)+(n>>31) ;
дает погрешность +/- 1..3 единицы младшего разряда , с

C++
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
inline static divmod10_t divmodu10(uint32_t n)
{
    divmod10_t res;
// mul 0.8     (   n*8/10)
    res.quot = n >> 1;
    res.quot += res.quot >> 1;
    res.quot += res.quot >> 4;
    res.quot += res.quot >> 8;
    res.quot += res.quot >> 16;
    uint32_t qq = res.quot;
// div 8
    res.quot >>= 3;
// rem
    //res.rem = uint8_t(n - ((res.quot << 1) + (qq & ~7ul)));
    res.rem = uint8_t(n - ((res.quot << 1) + (qq & 0xfffffff8))); 
// corr rem , quot
    if(res.rem > 9)
    {
        res.rem -= 10;
        res.quot++;
    }
    
    
    return res;
}
давало нулевую погрешность для положительных чисел при четырехбайтном кодировании делимого (uint32_t) от 0x0000 до 0xFFFF при делении на 10, для деления на 5 результат сдвинуть на 1 разряд вправо (умножить на 2 с нулем в младшеим разряде из переноса ).

Добавлено через 48 секунд
Нам нужна только нулевая погрешность для цифр ДДПКД (потом их преобразовывают в BCD -форму или используют иначе ), иначе ввести алгоритм корректировки для рядов .

Добавлено через 15 минут
уточнение: 0x00000000 до 0xFFFFFFFF

Добавлено через 18 минут
Для случая с рядами вводить программу коррекции частного и остатка из-за усечения ряда обязательно
C++
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
    
uint32_t ftmp=n;
ftmp=(uint32_t)ftmp>>3;
uint32_t data=0ul;
/*
 data+=ftmp;
 
ftmp=(uint32_t)ftmp>>2;  //5
data-=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //7
data+=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //9
data-=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //11
data+=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //13
data-=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //15
data+=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //17 
data-=(uint32_t)ftmp;  
ftmp=(uint32_t)ftmp>>2;  //19 
data+=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //21 
data-=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //23 
data+=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //25 
data-=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //27 
data+=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //29 
data-=(uint32_t)ftmp;
ftmp=(uint32_t)ftmp>>2;  //31 
data+=(uint32_t)ftmp;
Добавлено через 2 часа 7 минут
Варианты программ для деления на 10 и на 5 (подставить байты ) ,с циклами , могут не подойти по производительности , если подставить числа , могут выполнять функцию деления на константу, проверить правильность


Assembler
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
; ------------------------------------------------------------------------------
; Деление двойного слова на байт (32 / 8 -> 32.8) //////////////////////////////
; ------------------------------------------------------------------------------
; --> R_TmpA1, R_TmpA2 -- делимое младшие два байта
;     R_TmpB1, R_TmpB2 -- делимое старшие два байта
;     R_Dat -- делитель
; <-- R_TmpA1, R_TmpA2 -- частное младшие два байта
;     R_TmpB1, R_TmpB2 -- частное старшие два байта
;     R_OprA -- остаток
; Меняет: R_TmpA1, R_TmpA2, R_TmpB1, R_TmpB2, R_OprA, XL
S_Div_DWordByte:
    ldi        XL, 33                    ; Количество разрядов + бит C
    clr        R_OprA                    ; Остаток
    clc
S_Div_DWordByte_Loop:
    rol        R_OprA
    sub        R_OprA, R_Dat             ; Остаток минус делитель
    brcc    S_Div_DWordByte_1
        add        R_OprA, R_Dat
S_Div_DWordByte_1:
    rol        R_TmpA1
    rol        R_TmpA2
    rol        R_TmpB1
    rol        R_TmpB2
    dec        XL
    brne    S_Div_DWordByte_Loop
    com        R_TmpA1
    com        R_TmpA2
    com        R_TmpB1
    com        R_TmpB2
    ret
 
; ------------------------------------------------------------------------------
; Деление двойного слова на слово (32 / 16 -> 32.16) ///////////////////////////
; ------------------------------------------------------------------------------
; --> R_TmpA1, R_TmpA2 -- делимое младшие два байта
;     R_TmpB1, R_TmpB2 -- делимое старшие два байта
;     R_Dat1, R_Dat2 -- делитель мл. и ст. байты
; <-- R_TmpA1, R_TmpA2 -- частное младшие два байта
;     R_TmpB1, R_TmpB2 -- частное старшие два байта
;     R_OprA1, R_OprA2 -- остаток мл. и ст. байты
; Меняет: R_TmpA1, R_TmpA2, R_TmpB1, R_TmpB2, R_OprA1, R_OprA2, XL
S_Div_DWordWord:
    ldi        XL, 33                    ; Количество разрядов + бит C
    clr        R_OprA1                   ; Остаток мл.
    clr        R_OprA2                   ; Остаток ст.
    clc
S_Div_DWordWord_Loop:
    rol        R_OprA1
    rol        R_OprA2
    sub        R_OprA1, R_Dat1
    sbc        R_OprA2, R_Dat2
    brcc    S_Div_DWordWord_1
        add        R_OprA1, R_Dat1
        adc        R_OprA2, R_Dat2
S_Div_DWordWord_1:
    rol        R_TmpA1
    rol        R_TmpA2
    rol        R_TmpB1
    rol        R_TmpB2
    dec        XL
    brne    S_Div_DWordWord_Loop
    com        R_TmpA1
    com        R_TmpA2
    com        R_TmpB1
    com        R_TmpB2
    ret
 
; ------------------------------------------------------------------------------
; Деление двойного слова на двойное слово (32 / 32 -> 32.32) ///////////////////
; ------------------------------------------------------------------------------
S_Div_DWordDWord:
; --> R_TmpA1, R_TmpA2 -- делимое младшие два байта,
;     R_TmpB1, R_TmpB2 -- делимое старшие два байта;
;     R_Dat1, R_Dat2   -- делитель младшие два байта,
;     XL, XH           -- делитель старшие два байта;
; <-- R_TmpA1, R_TmpA2 -- частное младшие два байта,
;     R_TmpB1, R_TmpB2 -- частное старшие два байта;
;     R_OprA1, R_OprA2 -- остаток младшие два байта,
;     R_OprB1, R_OprB2 -- остаток старшие два байта.
; Меняет: R_TmpA1, R_TmpA2, R_TmpB1, R_TmpB2,
;     R_OprA1, R_OprA2, R_OprB1, R_OprB2
; Может и не очень хорошо исп. регистр Z
    push    ZL
    ldi        ZL, 33                     ; Количество разрядов + бит C
    clr        R_OprA1                    ; Остаток мл.слово мл.байт
    clr        R_OprA2                    ; Остаток мл.слово ст.байт
    clr        R_OprB1                    ; Остаток ст.слово мл.байт
    clr        R_OprB2                    ; Остаток ст.слово ст.байт
    clc
S_Div_DWordDWord_Loop:
    rol        R_OprA1
    rol        R_OprA2
    rol        R_OprB1
    rol        R_OprB2
    sub        R_OprA1, R_Dat1            ; Остаток минус делитель
    sbc        R_OprA2, R_Dat2
    sbc        R_OprB1, XL
    sbc        R_OprB2, XH
    brcc    S_Div_DWordDWord_1
        add        R_OprA1, R_Dat1
        adc        R_OprA2, R_Dat2
        adc        R_OprB1, XL
        adc        R_OprB2, XH
S_Div_DWordDWord_1:
    rol        R_TmpA1
    rol        R_TmpA2
    rol        R_TmpB1
    rol        R_TmpB2
    dec        ZL
    brne    S_Div_DWordDWord_Loop
    com        R_TmpA1
    com        R_TmpA2
    com        R_TmpB1
    com        R_TmpB2
    pop        ZL
    ret
Добавлено через 36 секунд
https://www.dropbox.com/s/8owl... v_uint.txt

Добавлено через 1 час 17 минут
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 uint32_t divmod10(uint32_t in,  uint32_t *mod)
{
 uint32_t q = (in >> 1) + (in >> 2);
 q = q + (q >> 4);
 q = q + (q >> 8);
 q = q + (q >> 16);
 q = q >> 3;
 uint32_t  r = in - ((q << 3) + (q << 1)); // r = in - q*10;
 uint32_t div = q + (r > 9); //if  r>9 div=q+1, else div=q
 if (r > 9) *mod = r - 10;
 else *mod = r;
 
return div ;
}
Добавлено через 26 минут
div 10 считает нормально , при предсдвиге влево аргумента до 6399990 на 5 делит без ошибки , а вот с mod проблема , смотреть предыдущий со структурой .

Добавлено через 48 минут
Для деления на 10 проблем не возникает в нашем интервале
C++
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
118
119
120
#include <iostream>
#include <stdint.h>
using namespace std; 
 
 
//Divide by 10: (((uint32_t)A * (uint32_t)0xCCCD) >> 16) >> 3
//Divide by 5: (((uint32_t)A * (uint32_t)0xCCCD) >> 16) >> 2
 
struct divmod10_t
{
    uint32_t quot;
    uint8_t rem;
};
 
inline static divmod10_t divmodu10(uint32_t n)
{
    divmod10_t res;
// mul 0.8
    res.quot = n >> 1;
    res.quot += res.quot >> 1;
    res.quot += res.quot >> 4;
    res.quot += res.quot >> 8;
    res.quot += res.quot >> 16;
    uint32_t qq = res.quot;
// div 8
    res.quot >>= 3;
// rem
     res.rem = uint8_t(n - ((res.quot << 1) + (qq & ~7ul)));
    //res.rem = uint8_t(n - ((res.quot << 1) + (qq & 0xfffffff8)));  
// corr rem , quot
    if(res.rem > 9)
    {
        res.rem -= 10;
        res.quot++;
    }
    
    
    return res;
}
 
 
 
static  uint32_t divmod10(uint32_t in,  uint32_t *mod)
{
 uint32_t q = (in >> 1) + (in >> 2);
 q = q + (q >> 4);
 q = q + (q >> 8);
 q = q + (q >> 16);
   
 q = q >> 3;
uint32_t  r = in - ((q << 3) + (q << 1)); // r = in - q*10;
 uint32_t div = q + (r > 9); //if  r>9 div=q+1, else div=q
 if (r > 9) *mod  = r - 10;     else {  *mod = r; }
 
 
return div ;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
int main ()
{
 
uint32_t i; 
 
//cout<<hex<<(~7ul);
 
for ( i=0; i<6399990;i++    )
//for ( i=1600000; i<639990;i++ )
{
// uint32_t delta=  divmodu10(i).quot -(i/10);
 //uint32_t delta=  div10(i)  -(i/10);
uint32_t mod;
//uint32_t delta= ( divmodu10((i) ).quot )  -(i/10);  //if f<=6399990
//  mod=divmodu10((i) ).rem;
   
//uint32_t delta= ( divmodu10((i ) ).quot )  -(i/10);  //if f<=6399990
//uint32_t deltamod=divmodu10((i) ).rem  -(i)%10 ;
 
    uint32_t delta= ( divmod10(   (i   ),&mod )  )  -(i/10);  //if f<=6399990
    
    uint32_t deltamod= mod    -(i )  %10 ;
 
 
 
  if(  (delta!=0)||(deltamod!=0) )
{
    
  cout<< "\n x= " <<i;
   cout<< " delta x_div10 "<<hex<<delta;
   cout<< " delta x_mod10 "<<mod-i%10;
   
     //cout<< " delta x_div5 "<<hex<<delta;
      //cout<< " delta x_mod5 "<<deltamod;
   
   
   
   
   
    
}
 
}
 
 cout<< " end ";
 
 
 
}
Добавлено через 4 минуты
При вычислении остатка при делении на 5 проблемы возникают (нужно определиться, нужно ли это нам, для индикации нужно деление нацело на 10 и только остаток от деления на 10 нужен), для ДПКД нужно умножать на нужное предсдвинутое число в пределах ОДЗ, а потом пропускать через подпрограмму в упрощенной редакции (без остатка , правильные числа у нас делятся без остатка при дополнении нулем в седьмой (младшей) цифре и преобразовании BCD4bit[7] ->uint32_t) .

Добавлено через 4 минуты
Для частоты у нас будет ОДЗ для подпрограммы проверки логики работы подпрограмм деления 32 -битных чисел (неполное использование типа, но учитывать при сдвиге влево перед делениеми )
C++
1
2
3
4
5
uint32_t i;
 
( i=1000; i<6399990;i++ ) {}
или для результирующего при переключении поддиапазонов  (ориентировочно, уточнить для  поддиапазонов)
( i=3200000; i<6399999;i++  ) {}
Добавлено через 10 минут
C++
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
#include <iostream>
#include <stdint.h>
using namespace std; 
 
 
 
static  uint32_t divmod10(uint32_t in,  uint32_t *mod)
{
 uint32_t  r;   
 uint32_t q = (in >> 1) ;
 q+= (in >> 2);
 q +=  (q >> 4);
 q +=  (q >> 8);
 q +=  (q >> 16);
  
 q = q >> 3;
  
r = in - ((q << 1) + (q << 3)); // r = in - q*10;
 
 uint32_t div = q + (r > 9); //if  r>9 div=q+1, else div=q
 if (r > 9) *mod  = r - 10;     else {  *mod = r; }
 
 
return div ;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
int main ()
{
 
uint32_t i; 
 
//cout<<hex<<(~7ul);
 
for ( i=0; i<6399990;i++    )
//for ( i=1600000; i<639990;i++ )
{
// uint32_t delta=  divmodu10(i).quot -(i/10);
 //uint32_t delta=  div10(i)  -(i/10);
uint32_t mod;
//uint32_t delta= ( divmodu10((i) ).quot )  -(i/10);  //if f<=6399990
//  mod=divmodu10((i) ).rem;
   
//uint32_t delta= ( divmodu10((i ) ).quot )  -(i/10);  //if f<=6399990
//uint32_t deltamod=divmodu10((i) ).rem  -(i)%10 ;
 
    uint32_t delta= ( divmod10(   (i<<1   ),&mod )  )  -(i<<1)/10 ;  //if f<=6399990
    
    uint32_t deltamod= mod    -(i<<1 )  %10 ;
 
 
 
  if(  (delta!=0)||(deltamod!=0) )
{
    
  cout<< "\n x= " <<i;
  // cout<< " delta x_div10 "<<hex<<delta;
   //cout<< " delta x_mod10 "<<deltamod;
   
     cout<< " delta x<<1 _div5 "<<hex<<delta;
      cout<< " delta x<<1_mod10 "<<deltamod;
   
   
   
   
   
    
}
 
}
 
 cout<< " end ";
 
 
 
}
Добавлено через 3 минуты
Для результатов, обрабатываемых компьютерно на Си++ и с помощью нашей модели на сдвигах при сдвиге влево на 1 разряд для деления на 5 и проверки одинаковости остатков двумя методами (в отличие от требуемого результата при делении на результирующее нецелое число в некоторых подпрограммах, где остаток не используется ) , разность была равна нулю в пределах ОДЗ .
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
27.03.2020, 21:06

Замена микросхемы на аналоговую
Привет всем. Какой микросхемой можно заменить микросхему FBBHAQ DM0265RB ? Она с платы 'SMPS 888 VER1.1', которая с...

Hp pavilion g6 замена микросхемы видео-чипа
Здравствуйте, может кто-то есть из сервисного центра? Какой срок гарантии дается при замене микросхемы видео-чипа? Отдал в сервисный центр,...

Acer Aspire One D255. Замена микросхемы U13
Здравствуйте форумчане. Имеется Ноут Acer Aspire One D255 (PAV70 LA-6221P Rev:1.0) , у него выгорела микросхема: U13 - G547H2 она же...

Acer aspire 5602wlmi замена сгоревшей микросхемы PG1AY 6900AS
помогите пожалуйста в ноутбуке Acer aspire 5602wlmi сгорела микросхема &quot;PG1AY 6900AS&quot; найти такую же мне не удалось, у меня есть материнка...

СМА Samsung Q1235, Замена микросхемы STK621-015. Есть аналог!!!
Здравствуйте! Подскажите возможна ли замена Микросхемы STK621-015 на STK621-140 трёхфазный инвертор двигателя? На плате MFS-Q1235-00


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
160
Ответ Создать тему
Новые блоги и статьи
мат медиц модель 30. презентация проекта
anaschu 27.08.2026
хоп хоп хоп хидахоп, а я кладую))
Как у меня протекала болезнь
zorxor 27.08.2026
Здравствуйте, друзья! Эта запись блога предназначена именно для вас - для моих дорогих друзей, которые знали меня лично. Чтобы ответить на вопрос - а что же со мной произошло на самом деле? Я учился. . .
Нашел вот забавное видео о измерениях. Лучшее что я видел на эту тему
kumehtar 26.08.2026
ILETXiw9bMQ Основная суть и тезисы по измерениям: 0D (Нулевое измерение): точка, не имеющая длины, ширины, высоты или объема. Объект не может перемещаться в 0D. 1D (Первое измерение):. . .
[EasyBuilder Pro] Памятка по разработке для панелей Weintek
ФедосеевПавел 26.08.2026
Памятка по разработке для панелей Weintek ВВЕДЕНИЕ Ранее, при реализации проектов основное внимание уделял разработке управляющей программы для контроллера, а панели оператора доставалось время. . .
Модель по догадкам
anaschu 25.08.2026
Прошло две недели. Я уже рассказывал, как разговаривал с сотрудниками у сортировки и как понял, что главная ветка — не про приёмку, а про отбор. Но тогда я думал, что понял механику. На этой неделе я. . .
Запись в регистр сведений независимо от заполненности табличной части
Maks 25.08.2026
Реализация из решения ниже выполнена на нетиповом документе с несколькими табличными частями, разработанного в КА2. Задача: Обеспечить запись документа в регистр сведений независимо от. . .
Ноутбук Альфария
kumehtar 24.08.2026
Встретился тут в сети ноутбук Альфария, примарха Альфа-Легиона. Хотя возможно, это ноутбук Омегона, разумеется. Ну как вам?
Мастера простых решений
DevAlt 23.08.2026
В сишарп стэках winforms, да и wpf существует сложная система связывания источниках данных и элементов формы(текстовые поля и метки), опирается все это на технологию событий и мета. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru