Beruflich Dokumente
Kultur Dokumente
;
;
;
;
;
;
;
;
;
;
;
;
;
;
LeftPeak
EQU
16
RightPeak
EQU
17
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
LeftSample
---------0
4
3
7
0
-5
-8
new LeftPeak
-----------0
4
4
7
7
7
8
We see that the "excursion from quiet" is just the absolute value
of the sample. Some microprocessors have an absolute value
operation built in but the 8051 does not. We can compute the
absolute value by negating the sample when we detect that the
sample is negative. To "negate" a signed number means to take
its "twos complement". The 8051 does not have an instruction
that computes the twos complement but the CPL instruction computes
the "ones complement". You get the ones complement by
complementing each individual bit. You get the twos complement
; We need two data memory locations to hold the left and right
; "excursions from quiet" so we arbitrarily choose the following
; data memory addresses:
LeftSample EQU
RightSample EQU
18
19
ORG 0
LJMP Start
Ext0Int:
ORG 0x03
LJMP Ext0ISR
Tmr0Int:
ORG 0x0b
SJMP Tmr0Int
Ext1Int:
ORG 0x13
LJMP Ext1ISR
Tmr1Int:
ORG 0x1b
SJMP Tmr1Int
; infinite loop
SerInt:
ORG 0x23
SJMP SerInt
; infinite loop
Start:
SJMP Loop
Ext1ISR:
; This interrupt signals that a new left and right audio sample are
; available.
MOV LeftSample,P0 ; read the new left channel sample from P0
MOV A,LeftSample
JNB ACC.7,ItsPositive ; test the MSBit
ItsNegative:
; so we need to negate the value
CPL A
; form the "ones complement"...
INC A
; ...and then add 1 to form "twos comp"
MOV LeftSample,A
ItsPositive:
; at this point LeftSample will hold the
; "excursion from quiet" which is an
; unsigned (i.e., positive) number.
MOV
A,LeftSample ;
;
CLR C
;
;
SUBB A,LeftPeak
;
;
;
JC
Ahead1
;
;
NewLeftPeak:
MOV
LeftPeak,LeftSample
Ahead1:
MOV
MOV
JNB
RightIsNegative:
CPL
INC
MOV
RightIsPositive:
MOV
RETI
Ahead2:
Ext0ISR:
; This interrupt signals that it's time to update the LED bar graph
; and then to reset the detected left and right peak reading.
MOV P2,LeftPeak ; write the left-channel peak reading to
; the left-channel peak meter
MOV P3,RightPeak ; write to the right-channel peak meter