Serial Output 10 Bits


Closed Thread
Results 1 to 5 of 5
  1. #1
    GEEZER's Avatar
    GEEZER Guest

    Default Serial Output 10 Bits

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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]
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Thumbs up

    Geezer you're tha best! Great to know it's working as this fine!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Need clever way to convert 10 bits to 8 bits
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd September 2005, 15:13
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts