program to generate triangular wave in 8086

program to generate triangular wave in 8086


Program 1 


TRIANGULAR WAVE GENERATOR with 8086 using 8255

MODEL SMALL
.STACK 100
.DATA
CONTROL EQU 0FFC6H ; Control port address for 8255
PORTA EQU 0FFC0H ; Port A address for 8255
PORTB EQU 0FFC2H ; Port B address for 8255
PORTC EQU 0FFC4H ; Port C address for 8255

.CODE
START:
MOV DX,CONTROL
MOV AL,80H ; Initialize all ports as output
OUT DX,AL ; Ports

BEGIN:
MOV DX,PORTB
MOV AL,00H ; Output 00 for 0V level
UP: CALL OUTPUT
INC AL ; To raise wave from 0V to 5V increment AL
CMP AL,00H
JNZ UP ; Jump UP till rising edge is reached i.e. 5V

MOV AL,0FFH
UP1: CALL OUTPUT
DEC AL ; To fall wave from 5V to 0V decrement AL
CMP AL,0FFH
JNZ UP1 ; Jump UP till falling edge is reached i.e. 0V
JMP BEGIN

OUTPUT:
OUT DX,AL
CALL DELAY
INT 21H

DELAY:
MOV CX,07H ;To vary the frequency alter the delay count
LUP1:LOOP LUP1
INT 21H

END START

Program 2


DA00: MOV DX, PORTB
      MOV AL, 00H    ;outport 00 for 0V level
UP: CALL OUTPUT
    INC AL
    CMP AL, 00H
    JNZ UP
    MOV AL, 0FFH       ;to change amplitude change count
UP1: CALL OUTPUT
     DEC AL
     CMP AL, 0FFH
     JNZ UP1   
     JMP DA00
;routine to output digital value
OUTPUT:    OUT DX, AL
    CALL DELAY
        RET
DELAY: MOV CX, 07H    ;to vary the frequency alter the delay count
LUP1: LOOP LUP1
      RET 

No comments: