Digital to Analog converter – DAC interfacing with 8051

If you are looking for an assembly code for DAC interfacing with 8051 then you are at the right place. Below is the Sample code for the Digital to Analog converter – DAC interfacing with 8051.

DAC converts the Digital data received on its input pins to the respective Analog output.

Assembly code

The following code can be used for 8051 and 8052 ICs like 89c51, 89c52, 89s51, 89s52, and 89c2051. It can also be used for interfacing 89v51rd2 with DAC.

Sine wave generation using 8051, Triangle wave generation using 8051, and square wave generation using 89s51 can be done by using the following given code. The amplitude of the output wave and the duration of the output wave depends on the digital input provided to the DAC.

Assembly code for DAC interfacing with 8051

;=========================================================
;    Downloaded from www.projectsof8051.com
;    MicroTronics Technologies
;=========================================================

                     ORG 0000h
                     mov P1,#00H
repeat:              call squarwave      ; generate square wave
                    call triwave           ; generate triangular wave
                    call stairwave       ; generate staircase wave
                    jmp repeat

squarwave:          mov P1,#FFH
                    call delay2sec
                    mov P1,#00H
                    call delay2sec
                    ret

triwave:         mov R7,#00H
triwave1:        mov P1,R7
                    inc R7
                    cjne R7,#FFH,triwave1
                    
                    mov R7,#FFH
triwave2:        mov P1,R7
                    djnz R7,triwave2
                    ret

stairwave:         mov P1,#00H
                    call delay2sec
                    mov P1,#20H
                    call delay2sec
                    mov P1,#40H
                    call delay2sec
                    mov P1,#80H
                    call delay2sec
                    ret

delay1sec:        mov r0,#10
del2:             mov r1,#250
del1:             mov r2,#250
                    djnz r2,$
                    djnz r1,del1
                    djnz r0,del2
                    ret

delay2sec:         mov r0,#20
del22:             mov r1,#250
del21:            mov r2,#250
                    djnz r2,$
                    djnz r1,del21
                    djnz r0,del22
                    ret

           END

;=========================================================
;    Downloaded from www.projectsof8051.com
;    MicroTronics Technologies
;=========================================================

Digital to analog converters has applications in various electronic circuits including digital music players and audio amplifiers.

Share