12f675 to 16f877


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2011
    Posts
    5

    Default 12f675 to 16f877

    Hello! I´m trying to send data from PIC12F675 to 16F877 via serout2.
    The 12F675 is generating the sequence:
    0,1,2,3,4,...,255

    And the 16F877 is receiving:
    128,129,130,131, ... , 157,158,159,128, 129,130,... Why?

    12F675 code:

    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    DEFINE OSC 4
    OPTION_REG.7 = 1 ' Disable pullups
    TRISIO = 101001
    CMCON = 7 ' Comparators OFF
    ANSEL = 0 ' A/D OFF -- Port pins all digital
    AL var byte

    TEMP var gpio.0 ' 1
    RELE1 var gpio.1 ' 0
    RELE2 var gpio.2 ' 0
    RES var gpio.3 ' 1
    TX var gpio.4 ' 0
    RX var gpio.5 ' 1
    al =0
    low RELE1
    low RELE2
    main:
    low tx
    serout2 TX,813,[AL]
    AL=AL+1
    pause 500
    goto main

    16F877 code:

    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    Define OSC 4
    ADCON1 = 7
    led var PORTC.0
    trim var PORTA.1
    rx var PORTB.5
    B0 var byte

    Main:
    serIN2 RX,813,[B0]
    LCDOUT $fe, 1,"b0 ", dec B0
    LCDOUT $fe,$c0, bin (B0)
    pause 100
    GoTo Main
    End


    Bit 7 is always set to 1, Why?

  2. #2
    Join Date
    Nov 2011
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    Any suggestion, please!

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    Remove PAUSE 100 on the receiver side.

    Cheers

    Al.
    All progress began with an idea

  4. #4
    Join Date
    Nov 2011
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    I removed the Pause 100, but no change.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    Did you set PORTB.5 as an input? (TRISB.5 = 1 in your 16f877)

    Your LCD DEFINES seems not corrected. Check them with the example given in page 95 of PBP manual.

    Al.
    Last edited by aratti; - 29th November 2011 at 20:17.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    On the 12F675, add this line ...
    Code:
    DEFINE OSCCAL_1K 1
    And, remove the LOW TX before the SEROUT2 statement.
    DT

  7. #7
    Join Date
    Nov 2011
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    Thank you for your comment. Its better, but still not work properly. This is my new code....
    ------------------------------
    '12F675 - TX


    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    DEFINE OSC 4
    OPTION_REG.7 = 1
    TRISIO = %00101001
    CMCON = 7
    ANSEL = 0
    AL var byte
    TX var gpio.4
    AL =0


    main:
    FOR ALl=0 to 200
    SERUOT2 TX,84,[AL]
    PAUSE 100
    NEXT AL
    GOTO main
    ---------------------------------
    '16F877 - RX


    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    Define OSC 4
    TRISB= %11111111
    ADCON1 = 7
    OPTION_REG.7 = 1
    RX var PORTB.5
    B0 var byte


    Main:
    SERIN2 RX,84,[B0]
    LCDOUT $fe, 1,"DEC= ", dec B0
    LCDOUT $fe,$c0,"BIN= ", bin (b0)
    GOTO Main

    End
    --------------------------------------
    Now, on display i have...
    1,2,3,4,133,6,7,8..... or
    1,2,3,132,133,6,7...or
    129,2,3,132,5,6...etc.
    With "DEFINE OSCCAL_1K 1" in TX i have...
    193,192,193,194,195,194,195,196....
    I am beginner, but this is simple code! I don't understand!
    Sorry for my bad English.

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


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    Check the spelling in the code
    SERUOT2 TX,84,[AL]
    Then..

    Add a dummy character to the TX
    Code:
    Synch    CON "~"
    SEROUT2 TX,84,[Synch,AL]
    For the RX
    Code:
    Synch    CON "~"
    SERIN2 RX,84,[WAIT(Synch),B0]
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Nov 2011
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: 12f675 to 16f877

    Problem solved! Thank You All...
    Now code works fine:

    '--------- TX
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF

    DEFINE OSC 4
    OPTION_REG.7 = 1
    TRISIO = 101001
    CMCON = 7
    ANSEL = 0
    AL var byte
    TX var gpio.4
    al =0

    main:
    for al=0 to 200
    SEROUT2 TX,813,["t","m","p",AL]
    pause 100
    next al
    goto main

    End

    '--------- RX
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    Define OSC 4
    TRISB= 111111
    ADCON1 = 7
    OPTION_REG.7 = 1
    RX var PORTB.5
    B0 var byte

    Main:
    low rx
    serIN2 RX,813,[WAIT("tmp"),B0]
    Lcdout $fe, 1,"DEC= ", dec B0
    LCDOUT $fe,$c0,"BIN= ", bin (b0)
    GoTo Main

    End

    Best regards






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