PIC to PIC communication problem


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89

    Default PIC to PIC communication problem

    this code is for length measurements with encoder. Main aim is to count pulse from encoder and Synchronously shift out counter Var on ClockPin and Data Pin to another PIC.
    Problem is, counter section and SHIFOUT is working but SHIFTIN on another PIC not working.

    @Config = _XT_OSC & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _BODEN_OFF
    Define PIC16F877A
    DEFINE OSC 4
    INCLUDE "MODEDEFS.BAS"
    CMCON = 7
    ADCON1 = 7
    CVRCON = %00000000 'CVref turned off

    TRISA = %11111111
    TRISB = %11111111 ' Portb.0 = Encoder input
    TRISC = %11111111
    TRISD = %11111111
    TRISE = %000

    Symbol HC_latch = PORTE.2 ' pin 10
    symbol HC_Data = PORTE.1 ' pin 9
    SYMBOL HC_Clk = PORTE.0 ' pin 8

    Dummy VAR WORD
    pitch var word
    pitch = 62206
    W1 var word

    B1 VAR BYTE
    B2 VAR BYTE
    B3 VAR BYTE
    B4 VAR BYTE
    B5 VAR BYTE
    W0 VAR WORD

    DIGIT1 VAR BYTE
    DIGIT2 VAR BYTE
    DIGIT3 VAR BYTE
    DIGIT4 VAR BYTE
    DIGIT5 VAR BYTE
    DIGIT6 VAR BYTE
    MASK VAR BYTE

    B1 = 0
    B2 = 0
    B3 = 0
    B4 = 0
    B5 = 0
    W0 = 0

    E1 VAR BYTE
    E2 VAR BYTE
    E3 VAR BYTE
    E4 VAR BYTE
    E5 VAR BYTE

    PAUSE 500

    OPTION_REG = %00000000
    On Interrupt Goto myint
    INTCON = $90

    LOOP: IF PORTA.0 = 1 THEN W0 = 0 'Reset Counter
    dummy = pitch * W0
    w1 = div32 1000
    w1 = w1/10
    w1 = w1/6

    B1 = W1 DIG 0
    B2 = W1 DIG 1
    B3 = W1 DIG 2
    B4 = W1 DIG 3
    B5 = W1 DIG 4

    '------------------------------------------
    DIGIT1 = B1
    LOOKUP DIGIT1,[$C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90],MASK
    E1 = MASK
    '------------------------------------------
    DIGIT2 = B2
    LOOKUP DIGIT2,[$C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90],MASK
    E2 = MASK
    '-------------------------------------------
    DIGIT3 = B3
    LOOKUP DIGIT3,[$C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90],MASK
    E3 = MASK
    '----------------------------------------
    DIGIT4 = B4
    LOOKUP DIGIT4,[$C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90],MASK
    E4 = MASK
    '---------------------------------------
    DIGIT5 = B5
    LOOKUP DIGIT5,[$C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90],MASK
    E5 = MASK
    '---------------------------------------
    HC_Latch=0
    shiftout HC_data, HC_Clk, MSBFIRST,[E1,E2,E3,E4,E5,$ff]
    pauseus 1
    HC_Latch=1
    '---------------------------------------
    GOTO LOOP

    Disable
    myint:
    W0 = W0 +1
    INTCON.1 = 0
    resume
    Enable



    __________________________________________________ ______________


    Recive data on another chip

    @Config = _XT_OSC & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _BODEN_OFF
    Define PIC16F877A
    DEFINE OSC 4
    INCLUDE "MODEDEFS.BAS"
    INCLUDE "MYLCD.BAS"
    CMCON = 7
    ADCON1 = 7
    CVRCON = %00000000 'CVref turned off

    TRISA = %11111111
    TRISB = %11111111
    TRISC = %11111111
    TRISD = %11111111
    TRISE = %111

    Symbol HC_latch = PORTE.2 ' pin 10
    symbol HC_Data = PORTE.1 ' pin 9
    SYMBOL HC_Clk = PORTE.0 ' pin 8

    E1 VAR BYTE
    E2 VAR BYTE
    E3 VAR BYTE
    E4 VAR BYTE
    E5 VAR BYTE

    main: HC_Latch=0
    shiftin HC_data, HC_Clk, MSBFIRST,[E1,E2,E3,E4,E5,$ff]
    pauseus 1
    HC_Latch=1

    lcdout $fe,1
    lcdout E5,E4,E3,E2,E1
    pause 500
    goto main



    .
    Attached Images Attached Images  
    Last edited by precision; - 20th June 2007 at 15:39.

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


    Did you find this post helpful? Yes | No

    Default

    That's for sure. SHIFTIN act as master, not slave. you'll need to roll your own.

    Possible to use the MSSP module as well. Have a look to SPISlave.bas
    http://www.melabs.com/resources/samp...p/spislave.bas

    You could still implement a simple serial communication with DEBUG/SEROUT2/HSEROUT... just an idea.

    PS:
    Code:
    @Config = _XT_OSC & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _BODEN_OFF
    Define PIC16F877A
    You don't need to define the PIC, and you config line is incorrect. it should be
    Code:
    @  __CONFIG _XT_OSC & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _BODEN_OFF
    further reference : http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

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

  3. #3
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Smile

    Thanks mister_e, its well working with SEROUT2 / SERIN2, My project is compleet.
    But for the knowledge i want to know, i have Load indicator that have same display ( 595 based display and AT 89c52 Chip ), I want to read it with PIC from spi line, Can i read it ? if yes what is the step to config. three ( clk,data,latch) line in pic. please.

    .
    Attached Images Attached Images  

Similar Threads

  1. 5v for PIC problem
    By financecatalyst in forum Schematics
    Replies: 4
    Last Post: - 24th August 2009, 16:04
  2. help for serial communication pic to pic
    By jasem700 in forum Serial
    Replies: 7
    Last Post: - 27th February 2009, 16:06
  3. serial communication between CMUcam and PIC 16F877
    By gengkeys in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th March 2007, 06:43
  4. PIC 2 PIC communication
    By Mario in forum Forum Requests
    Replies: 16
    Last Post: - 28th April 2006, 01:56
  5. PIC problem, ways to do reset
    By lab310 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th May 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