Académique Documents
Professionnel Documents
Culture Documents
USING MATLAB
1. Generation of Signals
2. Linear and circular convolution of two
sequences
3. Sampling and effect of aliasing
4. Design of FIR filters
5. Design of IIR filters
6. Calculation of FFT of a signal
7. Decimation by polyphase decomposition.
1. MATLAB PROGRAMS
1. LINEAR CONVOLUTION
3. To implement a causal IIR filter implemented in the Direct Form II structure, the
function direct2 given below can be employed.
function [y,sf] = direct2(p,d,x,si);
% Y = DIRECT2(P,D,X) filters input data vector X with
% the filter described by vectors P and D to create the
% filtered data Y. The filter is a "Direct Form II"
% implementation of the difference equation:
% y(n) = p(1)*x(n) + p(2)*x(n-1) + ... + p(np+1)*x(n-np)
% - d(2)*y(n-1) - ... - d(nd+1)*y(n-nd)
% [Y,SF] = DIRECT2(P,D,X,SI) gives access to initial and
% final conditions, SI and SF, of the delays.
dlen = length(d); plen = length(p);
N = max(dlen,plen); M = length(x);
sf = zeros(1,N-1); y = zeros(1,M);
if nargin ~= 3,
sf = si;
end
if dlen < plen,
d = [d zeros(1,plen - dlen)];
else
p = [p zeros(1, dlen - plen)];
end
p = p/d(1); d = d/d(1);
for n = 1:M;
wnew = [1 -d(2:N)]*[x(n) sf]’;
K = [wnew sf];
y(n) = K*p’;
sf = [wnew sf(1:N-2)];
end
4. Program illustrates the design of a causal IIR filter, its simulation in transposed
Direct Form II, and its application in filtering a signal.
% Program P8_3
% Illustration of Filtering by an IIR Filter
%
clf;
% Generate the input sequence
k = 0:50;
w2 = 0.7*pi;w1 = 0.2*pi;
x1 = 1.5*cos(w1*k); x2 = 2*cos(w2*k);
x = x1+x2;
% Determine the filter transfer function
[N, Wn] = ellipord(0.25, 0.55, 0.5, 50);
[num, den] = ellip(N,0.5, 50,Wn);
% Generate the output sequence
y = filter(num,den,x);
% Plot the input and the output sequences
subplot(2,1,1);
stem(k,x); axis([0 50 -4 4]);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Input Sequence’);
subplot(2,1,2);
stem(k,y); axis([0 50 -4 4]);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Output Sequence’);
5. Program up-sampler.
clf;
n = 0: 49;
m = 0: 50*3 - 1;
x = sin(2*pi*0.042*m);
y = x([1: 3: length(x)]);
subplot(2,1,1)
stem(n, x(1:50)); axis([0 50 -1.2 1.2]);
title(’Input Sequence’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
subplot(2,1,2)
stem(n, y); axis([0 50 -1.2 1.2]);
title(’Output Sequence’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
clc;
clear all;
close all;
g=input('1 sequence');
h=input('2 sequence');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>=0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
end
y(n)=[y(n)+g(i)*h(j)];
stem(y)
end
clc;
close all;
clear all;
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
wp=input('enter the pass band freq');
ws=input('enter the stop band freq');
fs=input('enter the sampling feq');
w1=2*wp/fs;
w2=2*ws/fs;
[h,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(h,wn);
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db....>');
xlabel('(a) normalised frequency>');
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b) normalised frequency');
ylabel('phase in radian');
DSP PROGRAMS
.include "5416_iv.asm"
.def start
.data
con1 .word 0555h ;1/3!
con2 .word 0044h ;1/5!
con3 .word 0001h ;1/7!
con4 .word 0fffh ;1/2!
con5 .word 0155h ;1/4!
con6 .word 000bh ;1/6!
fs .word 7d00h
fm .word 07cfh
pi .word 0c8ch
ms .word 0
mx .word 0
CNT .word 256
.text
start LD #con1,DP
RSBX INTM
LD #022Bh,0,A
STLM A,PMST
;------------------------Serial Port Initializations-------------------------
;--------------------------McBSP0 Initializations----------------------------
SSBX INTM
STM SPCR1,McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP1 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP1_SPSA
STM #0091h,McBSP1_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP1_SPSA
STM #00A1h,McBSP1_SPSD
RSBX INTM
LD #02Fh,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP1_SPSA
STM #00E1h,McBSP1_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
;----------------------------------------------------------------------------
STM #256,BK
STM #2000h,AR5
SSBX SXM
WAIT NOP
NOP
LD CNT,A
BC WAVE,AEQ
NOP
B WAIT
_XINT0_ISR
LD *AR5+%,A
LD CNT,A
SUB #1,A
STL A,CNT
RETE
WAVE LD #0,A
STLM A,IMR
LD #con1,DP
STM #1508h,AR2
LD fm,T
MPY *AR2,A
STM #1506h,AR2
RPT #15
SUBC *AR2,A
STL A,ms
;COSINE APPROX
LD ms,T ;X
STM #1509h,AR2
MPY *AR2+,A
SFTA A,-5
STL A,*AR2 ;X^2
STM #150Ah,AR2
MPY *AR2+,A ;X^3
SFTA A,-9
STL A,*AR2
STM #150Bh,AR2
MPY *AR2+,A ;X^4
SFTA A,-9
STL A,*AR2
STM #150Ch,AR2
MPY *AR2+,A ;X^5
SFTA A,-9
STL A,*AR2
STM #150Dh,AR2
MPY *AR2+,A ;X^6
SFTA A,-9
STL A,*AR2
STM #150Eh,AR2
MPY *AR2+,A ;X^7
SFTA A,-9
STL A,*AR2
STM #150Ah,AR2
LD con4,T
MPY *AR2,A
SFTA A,-13
LD #1FFFh,B
SUB A,B
STM #150ch,AR2
LD con5,T
MPY *AR2,A
SFTA A,-13
ADD A,B
STM #150eh,AR2
LD con6,T
MPY *AR2,A
SFTA A,-13
SUB A,B
STM #1600h,AR1
STL B,*AR1+
LD #0,A
RPT #1
STL A,*AR1+
STM #150Bh,AR2
LD con1,T
MPY *AR2,A
SFTA A,-13
STM #1509h,AR2
LD *AR2,4,B
SUB A,B
STM #150Dh,AR2
LD con2,T
MPY *AR2,A
SFTA A,-13
ADD A,B
STM #150Fh,AR2
LD con3,T
MPY *AR2,A
SFTA A,-13
SUB A,B
STL B,*AR1
;WAVE GENERATION
STM #2000h,AR7
STM #256,BRC
RPTB wave1
STM #1602h,AR2
STM #1600h,AR3
MPY *AR2,*AR3,A
SFTA A,-12
STM #1602h,AR4
STM #1601h,AR5
MVDD *AR4,*AR5
STM #1603h,AR6
LD *AR6,B
SUB B,A
STL A,*AR7+
STM #1602h,AR6
STL A,*AR6
STM #1601h,AR4
STM #1603h,AR5
MVDD *AR4,*AR5
NOP
wave1 NOP
STM #2000h,AR5
NOP
NOP
LD #256,A
STL A,CNT
NOP
NOP
LD #02Fh,0,A
STLM A,IMR
NOP
NOP
B WAIT
2. Square wave generation
.include "5416_iv.asm"
.def start
.data
POS .word 30 ;Positive Count value
NEG .word 30 ;Negative Count Value
P .word 0 ;Dummy 1
N .word 0 ;Dummy 2
.word 07fffh,08001h ;Maximum Positive and Negative Values
CNT .word 128 ;Total No.of Samples
E .word 45h ;Display Character 'E'
.text
start LD #POS,DP
; Data Page Pointer
RSBX INTM
LD #022Bh,0,A
STLM A,PMST
SSBX INTM
STM SPCR1,McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP2_SPSA
STM #0091h,McBSP2_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP2_SPSA
STM #00A1h,McBSP2_SPSD
RSBX INTM
LD #027h,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
;----------------------------------------------------------------------------
;--------------------------Square Wave Generation Program-------------------
;--------------------------Initialisation-------------------------------------------------------
STM #128,BK
SSBX SXM
WAIT NOP
NOP
LD CNT,B
BC WAVE,BEQ ;Jump to WAVE if Count Equals to zero
NOP
B WAIT
_XINT0_ISR
NOP
NOP
LD *AR4+%,A ;Transmitting Square Wave Output to
CODEC
STLM A,McBSP0_DXR1
STLM A,McBSP0_DXR2
LD CNT,B ;Count=Count-1
SUB #1h,B
STL B,CNT
RETE
NOP
NOP
PORTW E,0
STM #1504h,AR2
STM #1505h,AR3
STM #2000h,AR4
STM #6,BRC
LD POS,A
STL A,P
LD NEG,B
STL B,N
LD P,B
SUB #1h,B
STL B,P
BC L2,BNEQ
LD N,B
SUB #1,B
STL B,N
BC L3,BNEQ
NOP
L1 NOP
.include "5416_IV.asm"
.data
COEFF .word 086eh,0b9eh,0e5fh,1064h,1176h,1064h,0e5fh,0b9eh,086eh
;Filter Co-efficients in data ;
memory
.text
SSBX INTM
STM SPCR1,McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP2_SPSA
STM #0091h,McBSP2_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP2_SPSA
STM #00A1h,McBSP2_SPSD
RSBX INTM
LD #02Fh,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
;----------------------------------------------------------------------------
;----------------Program Starts -----------------------------------------
;------------------------Algorithm-------------------------------------
;-----FIR filter needs three buffers for Implementation
;-----One Buffer stores Input samples (128)
;-----Second Buffer is an Temporary buffer (Initially zero) (Size should be equal to the
order of the filter)
;-----Third Buffer Stores the output
;------Implementation-------------------------------------------------
;------First the Input sample from the CODEC is loaded to an accumulator.
;------The accumulator value is loaded to an Input Buffer (1600h Memory Location).
;------Initialize the temporary buffer.
;------Move the first Input sample to the Temporary buffer from Input buffer.
;------Modify the Temporary buffer to point out the last location (In this example the
modifier is 8 which is the order of ;the filter)
;-----Implementation of FIR filter is done by Using MACD Instruction
;-----Finally the output will be in Higher order. So Shift the output by -15.
;-----Store the Lower order value in Output buffer and transmit the output to CODEC.
SSBX SXM
RSBX FRCT
RSBX OVM
WAIT NOP
NOP
B WAIT
_XINT0_ISR
.include "5416_IV.asm"
.def start
.data
bpole .word 97e3h,154fh ;IIR Filter Co-efficients
azero .word 0b4ch,1698h,0b4ch
xin .word 0,0
xout .word 0
yin .word 0
S1 .word 00
E .word 45h
.text
SSBX INTM
STM SPCR1,McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP2_SPSA
STM #0091h,McBSP2_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP2_SPSA
STM #00A1h,McBSP2_SPSD
RSBX INTM
LD #02Fh,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
SSBX SXM
RSBX FRCT
RSBX OVM
WAIT NOP
NOP
NOP
NOP
NOP
B WAIT
_XINT0_ISR
STL A,0,xin
NOP
NOP
LD xin,A
STL A,0,*AR4+%
NOP
NOP
STM xout,AR2
SFTA A,-15
STL A,0,*AR6 ;Zero Output
RPT #01h
MACD *AR3-,bpole,A ;Multiplication of Output with Poles
SFTA A,-15
STL A,0,*AR7 ;Pole Output
NOP
NOP
LD *AR6,A
LD *AR7,B
SUB B,0,A ;Zero Output - Pole Output
STL A,0,*AR5
STL A,0,*AR1+%
.include "twi.asm"
.include "twr.asm"
.include "cos.asm"
.include "5416_iv.asm"
.def start
.data
R1 .word 0h ;Variables
I1 .word 0h
stages .word 7h
grp .word 64
grp1 .word 0h
but .word 1h
but1 .word 0h
R .word 0h
I .word 0h
A1 .word 0h
sizetw .word 40h
sizein .word 80h
bitr .word 40h
shi .word 7Fh
CNT .word 128
E .word 45h
.text
start LD #R1,DP
RSBX INTM
LD #022Bh,0,A
STLM A,PMST
SSBX INTM
STM SPCR1,McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP2_SPSA
STM #0091h,McBSP2_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP2_SPSA
STM #00A1h,McBSP2_SPSD
RSBX INTM
LD #017h,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
;----------------------------------------------------------------------------
;-----------------------------Program Starts----------------------
SSBX SXM
RSBX OVM
LD #0h,0,A
RPT #127
STL A,*AR1+
STM #1800h,AR1
STM #3500h,AR7
WAIT NOP
NOP
LD CNT,B
BC FFT,BEQ
NOP
NOP
B WAIT
_RINT0_ISR
PSHM AL
PSHM AH
PSHM AG
PSHM BL
PSHM BH
PSHM BG
LD *AR6+,0,A
STLM A,McBSP0_DXR1 ;o/p for R Channel
STLM A,McBSP0_DXR2 ;o/p for L Channel
LD CNT,B
SUB #1h,0,B
STL B,0,CNT
POPM BG
POPM BH
POPM BL
POPM AG
POPM AH
POPM AL
RETE
FFT NOP
NOP
LD #0,A
STLM A,IMR
STM #1000h,AR6
STM #1800h,AR1
STM #2000h,AR4
STM #1000h,AR3
RPT #127
MVDD *AR4+,*AR3+
LD #R1,DP
NOP
LD #80h,A
STL A,CNT
NOP
PORTW E,0
;------------Bit Reversal-----------------------
;------------For 128 pt FFT The Index value is
128/2=64(40H)-------------------
RPT #127
MVPD #2000h,*AR4+0B ;Bit Reversal
NOP
NOP
STM #2400h,AR5
LD #0h,0,A
STM #2800h,AR3
RPT #127
STL A,0,*AR3+
SU LD stages,0,A
LD grp,0,B
STL B,grp1
LD but,0,A
STM #2400h,AR5
STM #2800h,AR2
GU LD #40h,B
STLM B,BK
LD but,0,A
STL A,but1
LD #0h,0,B
SUB A,0,B
STL B,A1
STM #3000h,AR3
STM #3400h,AR4
BU LD #80h,B
STLM B,BK
LD *AR5,0,A
LD *AR2,0,B
STL A,0,R
STL B,0,I
LD but,0,A
STLM A,AR0
NOP
NOP
MAR *AR5+0%
MAR *AR2+0%
MPY *AR3,*AR5,A
MPY *AR4,*AR2,B
SUB B,0,A
STH A,R1
MPY *AR3,*AR2,A
MPY *AR4,*AR5,B
ADD A,0,B
STH B,I1
LD R,-1,A
LD R1,0,B
SUB B,0,A
STL A,*AR5
LD I,-1,A
LD I1,0,B
SUB B,0,A
STL A,*AR2
NOP
NOP
NOP
LD A1,0,B
STLM B,AR0
NOP
NOP
MAR *AR5+0%
MAR *AR2+0%
LD R,-1,A
LD R1,0,B
ADD B,0,A
STL A,*AR5+
LD I,-1,A
LD I1,0,B
ADD B,0,A
STL A,*AR2+ ;BUT
NOP
LD #40h,0,B
STLM B,BK
LD grp,0,A
STLM A,AR0
NOP
NOP
NOP
NOP
MAR *AR3+0%
MAR *AR4+0%
LD but1,0,B
SUB #1h,0,B
STL B,0,but1
BC BU,BNEQ ;;;;;Butterfly End
LD #80h,B
STLM B,BK
NOP
NOP
NOP
LD but,0,B
STLM B,AR0
NOP
NOP
MAR *AR5+0%
MAR *AR2+0%
LD grp1,0,B
SUB #1h,0,B
STL B,grp1
BC GU,BNEQ ;;;;;;;;Group End
NOP
LD but,0,B
SFTA B,1
STL B,but
STL B,but1
LD grp,0,B
SFTA B,-1
STL B,grp
STL B,grp1
LD stages,0,A
SUB #1h,0,A
STL A,stages
BC SU,ANEQ ;;;;;;;;;STAGES
LD #0h,0,A
LD #0h,0,B
;-------------------Initialization of Variables-----------------------
LD #7h,0,B
STL B,stages
LD #40h,0,A
STL A,grp
LD #1h,0,B
STL B,but
STM #2400h,AR3
STM #1800h,AR6
STM #7Fh,BRC
RPTB VE
LD *AR3+,A
ABS A
STL A,*AR6+
NOP
VE NOP
NOP
STM #1800h,AR6
LD #0017h,A
STLM A,IMR
NOP
NOP
B WAIT
6. FSK DESIGN
.include "5416_IV.asm"
.data
CNT .word 40h
VAR .word 0h
VAR2 .word 0h
.include "1000.asm"
.include "2000.asm"
.text
start
RSBX INTM
LD #022Bh,0,A
STLM A,PMST
SSBX INTM
STM SPCR1,McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP2_SPSA
STM #0091h,McBSP2_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP2_SPSA
STM #00A1h,McBSP2_SPSD
RSBX INTM
LD #02Fh,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
;----------------------------------------------------------------------------
STM #64,BK
STM #1700h,AR6
STM #1650h,AR7
LD #0h,A
RPT #1000h
STL A,*AR7+
STM #1650h,AR7
WAIT NOP
NOP
NOP
LD CNT,A
BC FSK,AEQ
NOP
NOP
B WAIT
_XINT0_ISR
LDM McBSP0_DRR1,A ;R Channel
LDM McBSP0_DRR2,A ;L Channel
PORTR 0h,VAR
LD *AR6+%,A
LD CNT,A
SUB #1h,A
STL A,CNT
RETE
FSK LD #40h,A
STL A,CNT
STM #1650h,AR1
STM #1700h,AR2 ;OUTPUT
STM #1600h,AR3 ;1000Hz
STM #1610h,AR4 ;2000Hz
LD VAR,A
AND #00FFh,A
NOP
NOP
STL A,VAR
STL A,VAR2
LD #8h,B;
HAI SUB #1h,B;
LD VAR2,A
AND #0001h,A
STL A,*AR1+
LD VAR2,B
SFTA B,-1
STL B,VAR2
BC HAI,BNEQ;
;--------------------------------------------------------------------------------------------------------
STM #1650h,AR1
STM #1700h,AR2 ;OUTPUT
STM #1658h,AR5
LD #8h,B
L5 LD *AR1+,A
BC ZERO,AEQ
PORTW VAR,0h
B WAIT