Создание частотного радиодальномера с цифровым анализатором спектра сигнала биений, страница 12

ADD                        A, R4

MOV                       R4,A

MOV                       B, #00H

MOV                       R1#00H

JZ                            M23

JB                            ACC.7, 24

M26 MOV                       A, R3

CLR                         C

SUBB                      A, R7

MOV                       R5, A

MOV                       A, R2

SUBB                      A, R6

JC                            M25

MOV                       R2, A

MOV                       A, R5

MOV                       R3,A

M25 CPL                         C

MOV                       A, B

RLC                         A

MOV                       B, A

MOV                       A, R3

RLC                         A

MOV                       R3, A

MOV                       A, R2

RLC                         A

MOV                       R2, A

DJNZ                       R4, M26

M23 MOV                       A, R2

MOV                       C, ACC.6

CLR                         A

ADDC                     A, B

MOV                       R1, A

M24 MOV                       A, 58H                           

MOV                       B, #240

MUL                        A13

JNB                         7FH, M27

SUBB                      A, #00H

MOV                       R3, A

        MOV                             A, B

SUBB                      A, #00H

MOV                       R2, A

SJMP                       M28

M27ADD                A, R1

MOV                       R3, A

CLR                         A

ADDC                     A, B

MOV                       R2, A

; Коррекция числа для вывода

M28 MOV                       R6, #10H

MOV                       R7, #27H

CLR                         P3.0

ACALL                   M31

SETB                       P3.0

MOV                       R6, #E8H

MOV                       R7, #03H

CLR                         P3.1

ACALL                   M3.1

SETB                       P3.1  

MOV                       R6, #64H

MOV                       R7, #00H

CLR                         P3.2

ACALL                   M31

SETB                       P3.2

MOV                       B, #0AH

MOV                       A, R3

DIV                         AB

CLP                        P3.3

MOV                       P1, A

SETB                       P3.3

MOV                       A, B

CLR                         P3.4

MOV                       P1,A

SETB                       P3.4

AJMP                      M33

M29 MOV                       R2, B

MOV                       R3, A

CLR                         ACC.7

CLR                         B.7

MUL                        AB

XCH                        A, B

MOV                       C, B.7

ADDC                     A, #00H

MOV                       B, R2

XCH                        A, B

XRL                         A, R3

XCH                        A, B

JNB                         B.7, M30

CPL                         A

INC                          A

M30 RET

M31 MOV                       R4, #00H

MOV                       A, R3

CLR                         C

SUBB                      A, R6

MOV                       R5, A

MOV                       A, R2

SUBB                      A, R7

JC                            M32

INC                          R4

MOV                       R2, A

MOV                       A, R5

MOV                       R3, A

M32 MOV                       P1, R4

RET

00BH  CPL                     P3.5

MOV                       TH0, #3DH

MOV                       TL0, #05H

RETI

01BH  DJNZ                  70H, V42   

CPL                         P2.7

MOV                       TH1, #F4H

MOV                       TL1, #24H

MOV                       70H, #02H

M42 RETI

Приложение 2.

Программа моделирования

10        DIM   A1(256), A2(256)

20        INPUT  “Введите TI”; TI

30        Q=FIX (256/TI)

40        DH=CINT(30000/(127-Q))

50        INPUT “Введите Н”; H

60        FOR I=1 to 256

70        A2(I)=0

80        IF      I > TI   THEN 110

90        A1(I) =CINT(128cos(0.10220648*H*(I-1)))

100      GOTO 120

110      A1(I)=0

120      NEXT I

130      REM      ПЕРЕСТАНОВКИ

140      J=1

150      FOR  I=1 to 255

160      IF   I >=J  THEN 200

170      D1=A1(J)

180      A1(J)=A1(I)

190      A1(I)=D1

200      K=128

210      IF   K>=J THEN 250

220      J=J-K

230      K=K/2

240      GOTO 210

250      J=J+K

260      NEXT  I

270      REM   БПФ

280      FOR  L=1 to M

290      L1=FIX(2^L+1)

300      L2=L1/2

310      U1=1 : U2=0

320      W1=cos(3.1415926/L2)  :W2=-sin(3.1415926/L2)

330      FOR  J=1 to L2

340      FOR  I=J  to256     STEP L1

350      I1=I+L2

360      T1=CINT((A1(I1)*U1-A2(I1)*U2)/2)

370      T2=CINT((A2(I1)*U1=A1(I1)*U2)/2)

380      D1=CINT(A1(I)/2)

390      D2=CINT(A2(I)/2)

400      A1(I)=D1+T1  :  A2(I)=D2+T2

410      A1(J)=D1-T1  :   A2(J)=D2-T2

420      NEXT  I

430      U3=U1: U1=U1*W19+U2*W2: U2=U2*W1=U3*W2

440      U1=CINT(128*U1)/128

450      U2=CINT(128*U2)/128

460      NEXT J

470      NEXT L

480      REM   ЭНЕРГЕТИЧЕСКИЙ СПЕКТР

490      FOR I=2 to 128

500      A1(I)=CINT((A1(I)*A1(I)+A2(I)*A2(I))/256)

510      NEXT I

520      Поиск максимума

530      D1=A1(10): D2=10

540      FOR  I=2  to 128

550      IF  A1(I)<D1   THEN 570

560      D1=A1(I): D2=I

570      NEXT I

580      REM  УТОЧНЕНИЕ

590      T1=0; T2=0

600      FOR  I=D2-Q  to D2=Q

610      T1=T1+I*A1(I)

620      T2=T2+A(I)

630      NEXT  I

640      OH=CINT(DH*T1/T2)

650      PRINT   “OH=”; OH

660      0=H*1000-OH

670      PRINT  “ОШ=”; 0

680      STOP

690      END.