How to Interface SPI DAC with 8051

SPI DAC Interfacing With 8051 Primer

Tags: spi DAC interface with 8051,8051 DAC interface,8051 DAC tutorial,circuit to interface 8051 DAC, DAC interfacing with 8051,Interfacing DAC with 8051,
Overall rating
8051 Primer Board

The 8051 Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s 8051 (AT89V51RD2), 8051 Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of speed 8-bit Microcontrollers.

DAC (Digital to Analog Converter):

The Microchip Technology Inc. MCP492X are 2.7 – 5.5V, low-power, low DNL, 12-Bit Digital-to-Analog Converters (DACs) with optional 2x buffered output and SPI interface.


  • 12-Bit Resolution
  • ±0.2 LSB DNL (typ), ±2 LSB INL (typ)
  • Single or Dual Channel
  • SPI™ Interface with 20 MHz Clock Support
  • Simultaneous Latching of the Dual DACs w/LDAC
  • Fast Settling Time of 4.5 μs
  • Selectable Unity or 2x Gain Output
  • 450 kHz Multiplier Mode
  • External VREF Input
  • Extended Temperature Range: -40°C to +125°C

Pin Assignment with 8051



8051 Lines


MCP 2491








Note:      Measure DAC output at J2 PTB connector.


Circuit Diagram to SPI DAC with 8051


Source Code

The Interfacing SPI ADC with 8051 program is very simple and straight forward, that uses a delay procedure loop based software delay. In C programs you cannot be sure of delay, because it depends on compiler how it optimizes the loops as soon as you make changes in the options the delay changes.

C Program to SPI DAC using 8051


Title : Program to display waveform





sbit CS =P3^5;        //chisp select port pin P3.5

sbit SCK=P3^6;        //SCK Port pin P3.6

sbit SDI=P3^7;        //SDI port pin P3.7

void SPI_out(unsigned char);

unsigned char x=0x80,i;



//         Main program Starts


void main()


            unsigned int Data=0x37FF; //Assing Data Here e.g 0x33ff, 0x37ff, 0x3fff                                                                                                            

            unsigned char data1;

            SCK = 0;                //sck pull to low                    

            while(1)               //loop forever



                        Data--;          //make cs to low

                        data1=(Data>>8); //shift and send to spiout

                        SPI_out(data1);   //send high byte


                                   SPI_out(data1); //send low byte                                                                 CS=1;

                        if (Data == 0)

                                    Data = 0x77FF; //make cs to high





//         SPI Data out routine


void SPI_out(unsigned char Data_val)




                                    SDI=(Data_val & x)?1:0;                                     

                                    SCK=1;                 //make sck high


                                    SCK=0;                //make sck low




Join the World's Largest Technical Community

we respect your privacy.