Comparison of Triangular Waveform and DC Signal

To generate the pulses by comparing triangular waveform with a dc signal.

Assembly Program:

COMPARE_VALUE EQU 050H ; Directive to set ;COMPARE_VALUE = 050H
MOV P3,#COMPARE_VALUE ; Move COMPARE_VALUE to P3
AGAIN: MOV R0,#00H ; Move 00H to R0
HERE1: MOV A,R0 ; Move R0 to Accumulator
MOV P1,A ; Move Accumulator to P1
INC R0 ; Increment R0 by 1
CJNE R0, #COMPARE_VALUE, HERE1; Compare and jump to HERE1 if R0  COMPARE_VALUE
SETB P2.3 ; Make P2.3 = 1
HERE2: INC R0 ; Increment R0 by 1
MOV A,R0 ; Move R0 to Accumulator
MOV P1,A ; Move Accumulator to P1
CJNE R0,#0FFH, HERE2 ; Compare and jump to HERE2 if R0  FFH
HERE3: DEC R0 ; Decrement R0 by 1
MOV A,R0 ; Move R0 to Accumulator
MOV P1,A ; Move Accumulator to P1
CJNE R0, #COMPARE_VALUE, HERE3; Compare and jump to HERE3 if R0  COMPARE_VALUE
CLR P2.3 ; Make P2.3 = 0
HERE4: DEC R0 ; Decrement R0 by 1
MOV A,R0  ; Move R0 to Accumulator
MOV P1,A ; Move Accumulator to P1
CJNE R0,#00H, HERE4 ; Compare and jump to HERE4 if R0  00H
SJMP AGAIN ; Jump to AGAIN

 END ; End of asm file

Check waveform using Logic Analyzer window in Keil µVision C51.

Advertisements