View previous topic :: View next topic |
Author |
Message |
Sophi
Joined: 14 Jun 2005 Posts: 64
|
Syntax Help |
Posted: Tue Jun 14, 2005 10:12 am |
|
|
Hi-
I want to send a 16-bit command to a D/A from a PIC. The D/A accepts data MSB first.
My line of code to do this looks like this:
output_bit (PIN_B1, shift_left (valve, 1,0)
- the 1 and 0 are borrowed from another code and I don't know what it means.
Any info on what this syntax means and/or suggestions for coding this?
Thanks-
Sophi |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 14, 2005 11:02 am |
|
|
Go here and get the current compiler manual.
http://www.ccsinfo.com/download.shtml
Or look for the CCS Help file in this folder:
c:\Program Files\Picc
You will find CCSC.HLP and CCSC.CHM. |
|
|
bfemmel
Joined: 18 Jul 2004 Posts: 40 Location: San Carlos, CA.
|
|
Posted: Tue Jun 14, 2005 1:48 pm |
|
|
Sophi,
You can also use the SPI to write the data out to the DAC. I do that with a 12 bit DAC sending the high byte first and then the low byte. Here is my subroutine to do that.
Code: |
void SetDacVoltage(unsigned int16 voltage) {
output_low (DAC_LD); // Pulling this bit low allows new numbers to be accepted
spi_write(MAKE8(voltage,1)); // Write out high byte first
spi_write(MAKE8(voltage,0)); // Write out low byte next
output_high(DAC_LD); // Pull bit back high to latch data into device
}
|
I use an 18F6520 and this code has worked fine with the 12bit DAC, it should work just fine with the 16 bit DAC.
- Bruce |
|
|
Sophi
Joined: 14 Jun 2005 Posts: 64
|
|
Posted: Tue Jun 14, 2005 5:25 pm |
|
|
Thanks to PCM programmer for the link to the manual. All is well.
Thanks also to Bruce for the suggestion and the code.
Sophi |
|
|
|