serial in parallel out using PIC


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Posts
    5

    Default serial in parallel out using PIC

    Hi there!
    This program I intend to convert serial to parallel. Say, serial input is 101, I want it convert to parallel by lighting 3 LEDs. I use 16F628 with RB0 the clock input (60hz square wave) and RB1 as data input which is a 1ms pulse right after the zero crossing of clock. When I simulate this, 4 LEDs are just blinking at the same time very fast instead of blinking 101 as I would expect. What could be wrong? Thanks...

    INCLUDE "modedefs.bas"

    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF


    CMCON = 7 'Comparators off
    VRCON = 0 ' Vref off
    TRISB.0 = 1
    TRISB.1=1
    TRISA =%00000
    DIPIN var byte
    wvar var byte
    CLPIN VAR bit
    here:
    PORTA=0

    SHIFTIN DIPIN,CLPIN,MSBPRE,[wvar\6]

    PORTA=wvar
    pauseus 500
    PORTA=0
    goto here
    end

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by daxki View Post
    INCLUDE "modedefs.bas"

    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF

    CMCON = 7 : VRCON = 0 : TRISB.0 = 1 : TRISB.1=1 : TRISA = 0 : DIPIN var byte : wvar var byte : CLPIN VAR bit

    here:






    PORTA=0








    SHIFTIN DIPIN,CLPIN,MSBPRE,[wvar\6] : PORTA=wvar : pauseus 500 : PORTA=0 : goto here
    end
    You keep shutting off everything on PortA every time thru the loop...
    Last edited by skimask; - 4th April 2007 at 00:54.

  3. #3


    Did you find this post helpful? Yes | No

    Default Its too!! Fast

    500 us shouldn´t let you see much of it, do you remember how we humans can hardly see 1/60 seconds events (light bulb), well 500 us is much less than that, maybe 500 ms is easier to watch.

    Try Pause 500 instead uf pauseus 500.

    Of course you could also avoid turning the leds of as the previous post said and then the leds would only change when data is recieved.
    Last edited by Josuetas; - 4th April 2007 at 03:00.

  4. #4
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Serial to Parallel

    Hi there!
    I edited portion of the program and incorporate both of your comments as shown:

    here:
    'PORTA=0

    SHIFTIN DIPIN,CLPIN,MSBPRE,[wvar\6]

    PORTA=wvar
    'pauseUS 500
    'PORTA=0
    goto here

    What happened is all LEDS on RA0 to RA3 are all lighted continuously, no change whatsoever.
    I expect that LEDs will be lighted as data comes in. For example, if data in is 1011, then I expect RA0 and RA1 to be high, RA2 to be low and RA3 to be high. And this should happen at the same time AFTER the last bit of serial input is received.

    What could be wrong?

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    How can you be sure that the data you are receiving into wvar is really what you want in the first place? Maybe, after the shiftin, wvar is actually all 1's.
    Don't automatically assume everything is working according to plan...'cause usually it doesn't...

    Also, you said in post #1, that RB0 is the 60hz clock input. Shiftin generates it's own clock pulse for output to another device. So, Shiftin might not be what you're looking for.

    Try this:

    INCLUDE "modedefs.bas"

    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF

    CMCON = 7 : VRCON = 0 : TRISB.0 = 1 : TRISB.1 = 1 : TRISA = 0 : porta = 0
    DIPIN var byte : wvar var byte : CLPIN VAR bit
    x var byte

    'blink leds 5 times for test
    for x = 1 to 5
    porta.0 = 1 : porta.1 = 1 : porta.2 = 1 : pause 500
    porta.0 = 0 : porta.1 = 0 : porta.2 = 0 : pause 500
    next x
    pause 5000 'pause 5 seconds before starting main program

    here:

    SHIFTIN DIPIN,CLPIN,MSBPRE,[wvar\6]

    'blink a.0 with hundreds digit of wvar
    for x = 1 to ( wvar dig 2 ) 'hundreds digit of wvar
    porta.0 = 1 : pause 500 : porta.0 = 0 : pause 500
    next x

    'blink a.1 with tens digit of wvar
    for x = 1 to ( wvar dig 1 ) 'tens digit of wvar
    porta.1 = 1 : pause 500 : porta.1 = 0 : pause 500
    next x

    'blink a.2 with ones digit of wvar
    for x = 1 to ( wvar dig 0 ) 'ones digit of wvar
    porta.2 = 1 : pause 500 : porta.2 = 0 : pause 500
    next x

    goto here
    end

Similar Threads

  1. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  2. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  3. Serial Com Pic to Pic
    By uludere72 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st May 2005, 10:06
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14
  5. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 15:45

Members who have read this thread : 0

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