communicating pic18f452 with pic16f877a


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2006
    Posts
    21

    Default communicating pic18f452 with pic16f877a

    Dear Freinds ...

    I tried to make a serial communication between two mcu's which are pic18f452 with 10 mhz osc and a compiled at HSPLL and on the other side a pic16f877a With 20 mhz compiled at HS ... Note that i uses pic basic pro compiler and a MPASM assembler .... I defined the first mcu to have 40 Mhz speed and the other 20 mhz ... THe two mcu's are connected directly with no resistors . The pic 18f452 uses RA2 and RA3 to send and receive data while pic16f877a uses RE1 and RE2 ... I set these pins to digital using Adcon1 = 7 .... i really couldn't find anything wrong ... Could any body help?

    Here is the two piece of code that should communicate together ... Note that the message is sent first from PIC18f452 (master controller) with a qualifier "MS" and the first item = the 3rd one , also the 2nd item=the 4th ... this is made to let the pic16f877a evaluate the message and if true it gives a confirmation =250 to the master controller ... else it may give 0 or even no response if no message is received ... The master controller retries 3 more times if cnf received =0 or no response then it goes to a subroutine called "DN" which stops every thing .

    Here is the code :


    'PIC18F452 SUBROUTINE :

    DEFINE OSC 40
    DEFINE CHAR_PACING 100
    ADCON1=7
    SFVC VAR PORTA.2
    STVC VAR PORTA.3

    VC: I=0
    SR: IF I>3 THEN
    ERR=36
    GOTO DN 'GOTO DANGER SUBROUTINE IF COMMUNICATION FAILED 4 TIMES.
    ENDIF

    PAUSEUS 1000 'DELAY TO MAKE SURE THAT THE OTHER CONTROLLER IS WAITING THE SERIAL MESSAGE.
    serout STVC,4,["MS",V1V8,V9V11,V1V8,V9V11] 'SERIAL MESSAGE TO VALVES CONTROLLER.
    I=I+1
    CNF=0
    serin SFVC,4,100,SR,[CNF] 'RECEIVE CONFIRMATION.
    IF CNF <> 250 THEN GOTO SR
    RETURN


    ' PIC16F877A SUBROUTINE

    DEFINE OSC 20
    DEFINE CHAR_PACING 100
    ADCON1=%10001110 'ONLY AN0 IS ANALOG PIN.
    SR: CNF=0
    SERIN PORTE.2,4,1000,A,["MS"],V1V8,V9V11,C1C8,C9C11 'SERIAL MESSAGE FROM MASTER CONTROLLER.
    IF V1V8 = C1C8 AND V9V11 = C9C11 THEN
    PORTB=NOT(V1V8)
    PORTD=NOT(V9V11)
    CNF=250
    ENDIF
    PAUSEUS 1000 'DELAY TO MAKE SURE MASTER CONTROLLER IS WAITING.
    serout PORTE.1,4,[CNF ] 'SERIAL MESSAGE TO MASTER CONTROLLER.
    IF CNF <> 250 THEN SR
    Last edited by tamersoss; - 13th July 2007 at 10:47.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The first thing I notice is a 10 Mhz osc defined as 40 Mhz.

    Second is the SERIN/SEROUT commands.

    Should read something like
    Code:
    SEROUT PIN, BAUDE RATE,[DATA]
    Looks like the BAUD RATE (MODE) is missing.

    Third, you will need to have
    Code:
    INCLUDE "modedefs.bas
    at the beginning of your program.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think the problem might be on the TX side ...
    Code:
    CNF=0 
    serin SFVC,4,100,SR,[CNF] 'RECEIVE CONFIRMATION.
    The CNF is in the "qualifier" brackets, so SERIN will wait to receive a 0 byte.
    But 250 is what's being sent for confirmation, and it'll never see it.

    To receive the byte into the CNF variable, it should be without the brackets.
    Code:
    CNF=0 
    serin SFVC,4,100,SR,CNF 'RECEIVE CONFIRMATION.
    Then the

    IF CNF <> 250 THEN GOTO SR

    should work.
    DT

  4. #4
    Join Date
    Dec 2006
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Many Thanks ...

    Dear Taylor ....

    You were right ... It works now because of you ... It's really amazing to have a freind like you ... many thanks.

Similar Threads

  1. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  2. Replies: 11
    Last Post: - 6th November 2008, 10:27
  3. Replies: 9
    Last Post: - 4th February 2008, 19:12
  4. PIC16f877-20 to a PIC16f877A I/P Disaster
    By andyf in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 21st November 2005, 17:11
  5. PIC16F877A to DS1307
    By miniman in forum Schematics
    Replies: 1
    Last Post: - 31st January 2005, 22:25

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