Looking for Basic Pic-to-Pic Serial Example


Results 1 to 17 of 17

Threaded View

  1. #5
    Join Date
    Aug 2008
    Location
    British Columbia, Canada
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    So this is what I have so far, <b>it works</b>. When I press a button the corresponding LED lights up and stays alight until another button is pressed.

    I'm not so sure why each LED goes out when the next one is lighted, following the code it seems like it should stay lit until eventually after pressing all the buttons all are alight, at which point the device would have to be reset to turn them off.

    The PIC with Buttons
    Code:
    '****************************************************************
    '*  Name    : Output1.pbp                                       *
    '*  Author  : Greensasquatch                                    *
    '*  Date    : 10/11/2008                                        *
    '*  Chip    : PIC16F628A                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : To output a number corresponding to which button  *
    '*          : was pressed via serial communication              *
    '****************************************************************
    '*  This Program is part 1 of 2.  The other half receives a 
    '*  number and lights a corresponding LED.
    '****************************************************************
    '*
    '*  Connections are as follows:
    '*                         
    '*                N/C  -01-|####|-18-  Green Power LED
    '*                N/C  -02-|####|-17-  SEROUT Line
    '*                N/C  -03-|####|-16-   N/C
    '*      MCLR 10K to V+ -04-|####|-15-   N/C
    '*                 Gnd -05-|####|-14-  V+
    '*               Butt1 -06-|####|-13-   N/C
    '*               Butt1 -07-|####|-12-   N/C
    '*               Butt1 -08-|####|-11-   N/C
    '*               Butt1 -09-|####|-10-   N/C
    '*
    '****************************************************************
    
    INCLUDE "MODEDEFS.BAS"
    
    'uses internal oscillator (should use crystal but I ran out)
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT      
    
    GreenLED var PORTB.4
    
    Butt1 var PORTB.0                             
    Butt2 var PORTB.1
    Butt3 var PORTB.2
    Butt4 var PORTB.3
    
    Pause 2000        'wait to begin
    high greenled     'turn on status light
    
    Loop:
    IF BUTt1 = 1 THEN SEROUT PORTA.0,T1200,[9,1]  'sends 9 and 1 if butt1 is high
    IF BUTt2 = 1 THEN SEROUT PORTA.0,T1200,[9,2]  'sends 9 and 2 if butt2 is high
    IF BUTt3 = 1 THEN SEROUT PORTA.0,T1200,[9,3]  'sends 9 and 3 if butt3 is high
    IF BUTt4 = 1 THEN SEROUT PORTA.0,T1200,[9,4]  'sends 9 and 4 if butt4 is high
    GOTO LOOP
    
    end
    The PIC with LEDs
    Code:
    '****************************************************************
    '*  Name    : Input1.pbp                                        *
    '*  Author  : Greensasquatch                                    *
    '*  Date    : 10/11/2008                                        *
    '*  Chip    : PIC16F628A                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : To read a number via serial communication and     *
    '*          : light a corresponding LED                         *
    '****************************************************************
    '*  This Program is part 2 of 2.  The other half sends a 
    '*  number corresponding to a button state.
    '****************************************************************
    '*
    '*  Connections are as follows:
    '*                         
    '*                LED3 -01-|####|-18-  LED2
    '*                LED4 -02-|####|-17-  LED1
    '*                N/C  -03-|####|-16-   N/C
    '*      MCLR 10K to V+ -04-|####|-15-   N/C
    '*                 Gnd -05-|####|-14-  V+
    '*           Serial In -06-|####|-13-   N/C
    '*     Green Power LED -07-|####|-12-   N/C
    '*                N/C  -08-|####|-11-   N/C
    '*                N/C  -09-|####|-10-   N/C
    '*
    '****************************************************************
    
    INCLUDE "MODEDEFS.BAS"
    
    'uses internal oscillator (should use crystal but ran out)
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT      
    
    GreenLED var PORTB.1   
    
    LED1 var PORTA.0                             
    LED2 var PORTA.1
    LED3 var PORTA.2
    LED4 var PORTA.3
    
    NET var byte                  'holding variable for input
    
    Pause 2000                    'wait to begin
    high greenled                 'turn on status light
    
    Loop:
    SERIN PORTB.0,T1200,[9],NET   'waits for a "9" and writes the next value to NET
    IF NET = 1 THEN HIGH led1  
    IF NET = 2 THEN HIGH led2
    IF NET = 3 THEN HIGH led3
    IF NET = 4 THEN HIGH led4
    GOTO LOOP
    
    end
    Now I'm just going to look into how to make it so that the LED only stays lit as long as the button is held down.


    Any comments would be great as the finished code will be posted in code examples (with proper credits of course).

    In response to Steve's comment:
    I left out setting the idle state for now, it works, so I won't change anything until I fully understand why. I had always thought that TTL idle was low and Inverted (and RS232) idle was high. I'm hoping to make this into a wireless setup somewhere down the road, in which case I would want the idle state to be low so the device does not transmit when there is now data. I see I have more research to do.
    Last edited by greensasquatch; - 11th November 2008 at 08:24.
    -Justin

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