Shop OBEX P1 Docs P2 Docs Learn Events
Question About Using SEROUT Instruction with PIC Processor — Parallax Forums

Question About Using SEROUT Instruction with PIC Processor

bobledouxbobledoux Posts: 187
edited 2004-12-17 16:09 in BASIC Stamp
I’m using the Serout instruction to send a data byte to a PIC microprocessor. The PIC has 8 LED’s wired to display the data byte. Communication is working, but I’m not getting the expected results.

My question is: Am I using the right format to send the binary value 10000000, which is decimal value 128? I want the 8 LEDS, powered by the PIC, to all be off except the one at the high bit end. The instruction I am using at 2400 baud is:

Serout 12, 396, [noparse][[/noparse]BIN8 128]

Comments

  • NewzedNewzed Posts: 2,503
    edited 2004-12-17 01:01
    That's fine, but what does the serin on the PIC end say?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    4 digit serial LED

    http://hometown.aol.com/newzed/index.html
    ·
  • NewzedNewzed Posts: 2,503
    edited 2004-12-17 01:04
    I just noticed.· Baud 396 is TRUE.· You should be using 16780.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    4 digit serial LED

    http://hometown.aol.com/newzed/index.html
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-17 01:32
    And I believe the 'BIN8' modifier changes the output value to the 'string' "1" "0" ...

    You probably just want to send the 128 by itself.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-17 03:04
    Allan's right, your PIC probably wants just one byte. Change your command to

    SEROUT 12, Baud, [noparse][[/noparse]leds]

    Where Baud is a constant defining speed and mode (true or inverted), and leds is a value that corresponds to the desired output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobledouxbobledoux Posts: 187
    edited 2004-12-17 15:25
    Thanks for the responses.

    It works. when I change [noparse][[/noparse]BIN 128] to [noparse][[/noparse]128]



    Here is the basic process in case others want to try:

    This is a one way communication with the Stamp transmitting at 2400 baud to a PIC 12F508. The bit width at this baudrate is 417 microseconds.

    The link between the Stamp and PIC has a pullup resistor-4.7K.

    The PIC program is written in assembly language so let me describe the steps:

    A. The program sits in a loop waiting for the Stamp to pull the serial line low. Pulling the line low signifies the beginning of the serial start bit.

    B. The PIC delays 208 microseconds to place it into the middle of the start bit. It then tests the line to see if it is still low. If the line has gone high, a false start has taken place and the PIC program returns to step A.

    C. If the line remains low after the 208 microseconds in step B, the PIC begins 9 loops. In each loop the following steps are performed.

    C1 the data line is read and its high (1) or low (0) status is placed in the data output byte.

    C2 the data output byte is rotated right 1 bit.

    C3 a delay of 417 microseconds is made to move to the next bit.

    The loop beginning at step C1 is repeated a total of 9 times because the first bit read is the start bit. The 9th loop passes the start bit out of the data output byte.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-17 15:51
    The pull-up on the serial line indicates true (idle = high, start = 0) mode.

    There is a demo in the SX/B help file that shows how to receive a byte like this in an interrupt and place that byte into a 16-byte circular buffer. SX/B is very similar to PBASIC, and allows assembly instructions to be mixed in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-17 16:09
    Very nice bob. That's a nice, concise description of how a PIC can get an RS-232 byte by 'listening' to an input pin. Glad you got it working.

    If you are using an external pull-up resistor, then you may want to experiment with the 'open' mode (add $8000 to the BaudMode value) of the BS2 SEROUT command. The 'open' modes only drive the pin to one state, and let it 'float' to the other state. This 'float' part requires the external pull-up resistor. Check out the manual for inverted vs non-inverted and 'open' to find which state is driven vs. floated.
Sign In or Register to comment.