I'm using a PIC 16f877A with a D/A Converter (AD667) in order to transform the result of a count into a analogue output to use later, but I find my self incapable of sending this 12 bits from the PIC to the AD667, is there a way to do so using MikroC ?
here is the code I'm using:

// sbit tmr1 at RC0_bit;

void OutTimer1 (void)
    while (portc.b0==0)
        tmr1= porta= porte = TRISC.B2, TRISC.B3  ,TRISC.B4 ;
        if (TMR1L == 0XFF)
            TMR1H ++ ;
    } // end while
} /// end OutTimer1

void main() 

` am I on the right truck at least?
the encoder provides pulses for the pic to count, and then send the result of the count to the dac

in the simulation with proteus i couldn't find an AD667, so used what i found in the library dac 1219.

  • 1
    \$\begingroup\$ Welcome to EE.SE! Keep in mind that "Is it possible ...?" is a yes/no question. In this case, the answer is "Yes". If you're asking us to design it for you, that would be too broad. You would need to specify something about the level of performance you expect as well as what constraints you have on the implementation. What is your specific question? \$\endgroup\$ – Dave Tweed Mar 25 '18 at 15:23
  • \$\begingroup\$ I am pretty sure there is, but you need to tell us more about what you tried and where it failed. Some code snippets would be a good start. \$\endgroup\$ – Oldfart Mar 25 '18 at 15:23
  • \$\begingroup\$ Have you looked at the AD667 datasheet? There are several suggestions there. \$\endgroup\$ – Dave Tweed Mar 25 '18 at 15:31

The AD667 needs a SIPO register IC to interface from a serial bit banger on PIC but....

this ADC costs $32.

mouser However a serial 12 bit DAC from Microchip

MCP4921 only costs $3.16

So you use three I/O pins to send out serial data to the DAC : SCK, CS, SDI from PIC using say RB1, RB0, SDO.

  • The LDAC (latch DAC synchronization input) pin is used to transfer the input latch register to the DAC register (output latch, VOUT). When this pin is low, VOUT is updated with input register content. Hence we tie this pin to low (VSS) so that VOUT is updated at the rising edge of the CS pin.

  • VREF is the voltage reference input for MCP4921. This pin is tied to VDD so that the input voltage will range from VSS(ground) to VDD(5V).

  • Connect a high value register to VOUT of MCP4921 so that the current requirements are low.

    #pragma config FOSC = HS   //High Speed Crystal Oscillator
    #pragma config WDT=OFF     //Watch Dog Timer disabled
    #pragma config LVP=OFF     //Single-Supply ICSP disabled
    #pragma config MCLRE = OFF //RE3 input pin enabled; MCLR pin disabled.  
     //So now we dont need to give High Logic on this pin to keep the PIC functioning
    #define  cs PORTBbits.RB0  
    void dac(unsigned int);
     void delay(unsigned int time);
    void main()
     int i;
     TRISB=0;      // PORTB is configured as an output port
     TRISC=0;      // PORTC is configured as an output port
     SSPSTAT=0xC0; //Status Register SSPSTAT=11000000
     SSPCON1=0x20; //Enables serial port pins & set the SPI clock as clock = FOSC/4
        dac(255);  delay(1000);
        dac(127);  delay(1000);
        dac(63);   delay(1000);
     void dac(unsigned int data)
     unsigned int c ;
     unsigned int lower_bits;
     unsigned int upper_bits; 
     c = ((data+1)*16) -1; // here we obtain 12 bit data
                           //first obtain the upper 8 bits
     upper_bits = c/256;   // obtain the upper 4 bits
     upper_bits = (48) | upper_bits; // append 0011 to the above 4 bits
                           //now obtain the lower 8 bits
     lower_bits = 255 & c; // ANDing separates the lower 8 bits
     SSPBUF=upper_bits;    // sending the upper 8 bits serially    
     while(!SSPSTATbits.BF);  // wait until the upper 8 bits are sent
     SSPBUF=lower_bits;       // sending the lower 8 bits serially  
     while(!SSPSTATbits.BF);  // wait until the lower 8 bits are sent
      void delay(unsigned int time)
      unsigned int i,j;
  • \$\begingroup\$ The question is 'how can I send 12 bits from a PIC16f877A to the AD667?' and your answer is 'don't use an AD667'? \$\endgroup\$ – Bruce Abbott Mar 26 '18 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.