Log in

View Full Version : Serial Output 10 Bits



GEEZER
- 14th May 2005, 18:39
I am way over my head here. Pic 16F877A sending data to a dual DAC. Any ideas or referrals to information will be appreciated.

I need a 10 bit signal, first 2 bits select the pot, 00, or 01. The next 8 are data bits.

[a1][a0][d7][d6][d5][d4][d3][d2][d1][d0]

The first two bit select pot 1 or 2. Here is the code. Keep in mind that I am a novice.

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 10
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTC 'defines
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 100
DEFINE OSC 20
DEFINE BUTTON_PAUSE 250
DEFINE CHAR_PACING 1000

SSPCON = 5

INCLUDE "MODEDEFS.BAS"

'symbols
SYMBOL UP = PORTD.1:SYMBOL DOWN = PORTD.3:SYMBOL CS = PORTD.4
SYMBOL RS = PORTD.6:SYMBOL SDO = PORTC.5:SYMBOL SHDN = PORTD.5

'VARIABLES
B0 VAR BYTE:ADJ1 VAR BYTE

ADJ1 = 0
HIGH SHDN
HIGH RS

LOOP:

BUTTON UP,1,250,250,b0,1, PLUSVOLTS
BUTTON DOWN,1,250,250,b0,1, MINUSVOLTS
GOTO MON

MON:

LCDOUT $FE, 1
lcdout $FE, 2
lcdout DEC ADJ1
PAUSE 25
GOTO LOOP

POTCHANGE: 'CHANGES POT SETTING
LOW CS
SEROUT SDO, 0, [01, ADJ1]
HIGH CS
GOTO LOOP

PLUSVOLTS:
adj1 = adj1 + 1
IF ADJ1 > 255 THEN ADJ1 = 255
GOTO POTCHANGE

MINUSVOLTS:
adj1 = adj1 - 1
IF ADJ1 < 1 THEN ADJ1 = 0
GOTO POTCHANGE
END

mister_e
- 14th May 2005, 18:55
For sure your DAC don't work with pure serial communication. It can be an I2C or SPI (some company use other notation as 2-wire, 3- wire, serial, Microwire...)

By reading your code, your DAC is certainely an SPI one. In this case you'll have to use SHIFTIN and SHIFTOUT.

With the above you'll be able to shift your 10 bits

Will look something like SHIFTOUT DI,CLK,mode,[Myvar\10]

GEEZER
- 14th May 2005, 21:40
Yes, Steve it's a 3 wire SPI. Thanks for giving me a place to start. I'll study up on the shift commands. I'm new at this, but conquering, little by little.

Thanks again,

The Geezer

GEEZER
- 17th May 2005, 00:08
Thanks again, steve.

With the SHIFTOUT command i'm not only talking to the dual DAC, but both pots are responding with precision.

The Geezer

mister_e
- 17th May 2005, 02:14
Geezer you're tha best! Great to know it's working as this fine!