EXP 3 MA PRACTICAL

ALP to generate SQUARE waveform
ORG 0000H ;start
SJMP MAIN
ORG 0045H
MAIN:MOV TMOD,#20H ;mode 1 of timer 1
MOV TH1,#0A4H ;to generate required delay
CLR A ;clear accumulator
MOV P1,A
AGAIN:SETB TR1 ;start the timer
CPL A ;take complement of accumulator data
MOV P1,A ;move data from A to P1
BACK:JNB TF1,BACK ;jump till time is completed
CLR TR1 ;clear bit
CLR TF1 ;clear bit
SJMP AGAIN ;start again to obtain square wave
END

ALP to generate STAIRCASE waveform
ORG 0000H ;start
SJMP MAIN
ORG 0045H
MAIN:MOV R1,#055H ;step of 55H
MOV A.#00H
UP:MOV P0,A
ACALL DELAY
ADD A,R1 ;add step of 55H to A and pass it to port P0
SJMP UP
DELAY:MOV R2,#0FFFH ;delay
L1:MOV R3,#0FFH
L2:DJNZ R3,L2
DJNZ R2,L1
RET
END

ALP to generate TRIANGULAR waveform
ORG 0000H ;start
SJMP MAIN
0RG 0045H
MAIN:UP:MOV A,#00H
UP1:MOV P0,A ;increment A till it reaches 0FFH value
INC A ;increment A
CJNE A,#0FFH,UP1 ;compare A with 0FFH
UP2:DEC A ;decrement A till it reaches 00H value
MOV P0,A
CJNE A,#00H,UP2 ;compare A with 00H
SJMP UP ;for obtaining continuous waveform
END

ALP to generate SAWTOOTH waveform
ORG 0000H ;start
SJMP MAIN
0RG 0045H
MAIN:UP:MOV A,#00H
UP1:MOV P0,A ;increment A till it reaches 0FFH value
INC A ;increment A
CJNE A,#0FFH,UP1 ;compare A with 0FFH
CLR A ;clear accumulator
MOV P0,A ;to obtain one cycle of sawtooth wave
SJMP UP ;to obtain sawtooth wave continously
END
Previous Post Next Post