help for serial communication pic to pic


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2008
    Posts
    12

    Default help for serial communication pic to pic

    hello my friend

    please who can help me for sample code to create serial communication between 16f84A to 16f84A when using SEROUT/SERIN
    I want to send a decimal number (0000 to 9999) from one PIC to the other where it's display it on 7 segment display 4 digit as shown in pictur attached

    you can email my [email protected]
    and thankyou very much
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251

    Default

    Try serout for the first pic and serin for the second pic.
    How to use serout and serin is in the manual that came with the compiler.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,810

    Default

    Do you have the rest of the program set up? I mean the display is working?

    For the data just use something like:

    Serout portpin,speed,["#",word_variable]

    Serin portpin,speed,["#"],word_variable

    For the parameters, have a look at the manual. I'd recommend a low speed of T2400.

    Ioannis

  4. #4
    Join Date
    Dec 2008
    Posts
    12

    Default

    thanks all my friends

    I have this subroutine for display decimal number on 7 segement 4 digit
    for examlpe when I try to display 1230 in proteuse simulation is not work properly
    I have tow problem:
    1-correct subroutine for displaying decimal number
    2-and how I can include this subroutine with commands Serout serin in tow pic when first pic (transemetre) send decimal number the second pic (receiver) must receive it and display it on 7 segment 4 digit
    and thank you very much for your help


    subroutine to display decimal number
    w1 var word
    b0 var byte
    TRISA=%00000000
    TRISB=%00000000

    loop:
    w1=1230
    gosub disp
    goto loop
    disp:

    B0 = W1 / 1000 ' Find number of thousands
    W1 = W1 // 1000 ' Remove thousands from W1
    Gosub bin2seg ' Convert number to segments
    Poke PortB, B0 ' Send segments to LED
    Poke PortA, $17 ' Turn on fourth digit
    Pause 1 ' Leave it on 1 ms
    Poke PortA, $1F ' Turn off digit to prevent ghosting
    B0 = W1 / 100 ' Find number of hundreds
    W1 = W1 // 100 ' Remove hundreds from W1
    Gosub bin2seg ' Convert number to segments
    Poke PortB, B0 ' Send segments to LED
    Poke PortA, $1B ' Turn on third digit
    Pause 1 ' Leave it on 1 ms
    Poke PortA, $1F ' Turn off digit to prevent ghosting
    B0 = W1 / 10 ' Find number of tens
    W1 = W1 // 10 ' Remove tens from W1
    Gosub bin2seg ' Convert number to segments
    Poke PortB, B0 ' Send segments to LED
    Poke PortA, $1D ' Turn on second digit
    Pause 1 ' Leave it on 1 ms
    Poke PortA, $1F ' Turn off digit to prevent ghosting
    B0 = W1 ' Get number of ones
    Gosub bin2seg ' Convert number to segments
    Poke PortB, B0 ' Send segments to LED
    Poke PortA, $1E ' Turn on first digit
    Pause 1 ' Leave it on 1 ms
    Poke PortA, $1F ' Turn off digit to prevent ghosting
    Return ' Go back to caller

    ' Convert binary number in B0 to segments for LED
    bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18],B0
    Return

  5. #5
    Join Date
    Dec 2008
    Posts
    12

    Default

    I wait for your help ........

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Hello jasm700,
    You want to look at the manual sect 4.17.7 it explains how to use the DIG command to get your digit.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Dec 2008
    Posts
    12

    Default

    ok thanks all my friend i will try your suggetions

  8. #8
    Join Date
    Dec 2006
    Location
    WADSWORTH OHIO USA
    Posts
    37

    Default this works for me

    This is what i use to drive my 8 digit dual display

    Hope it helps.
    By adjusting f & f2 you can adjust the brightness...

    'REV 071408 * #disdrive9.01 DISPLAY LED DRIVER
    DEFINE OSC 20
    DEFINE SER2_BITS 8
    A VAR BYTE
    B VAR BYTE
    C VAR BYTE
    F VAR BYTE
    F2 VAR BYTE
    DCP VAR BYTE
    AMP VAR WORD
    TIME VAR WORD
    COUNTA VAR WORD
    COUNTB VAR WORD
    COUNTC VAR WORD
    SNO1 VAR WORD
    SNO2 VAR WORD

    FLOW7 VAR PORTA.0
    DAT7 VAR PORTA.1
    SPF10 VAR PORTA.2
    BURN VAR PORTA.3
    SPF02 VAR PORTA.4
    SPF03 VAR PORTA.5
    SEGMENT VAR PORTB
    DIGIT VAR PORTC

    TRISA = %11111111
    TRISB = %00000000
    TRISC = %00000000
    ADCON0 = %00000000
    ADCON1 = %00000111
    A = 0
    C = 0
    B = 0
    F = 100
    F2 = 3
    DCP = 0
    PAUSE 20
    TIME = 1234
    AMP = 5678

    EEPROM 0,[129,243,73,97,51,37,5,241,1,49,254,253,251,247,239 ,223,191,253]
    GOSUB BSEQ
    LOOP: ' AND NOW THE MAIN EVENT
    IF FLOW7 = 1 THEN
    SerIN2 PORTA.1,84,[TIME.highbyte,TIME.lowbyte,AMP.highbyte,AMP.lowbyt e,DCP]
    ENDIF
    IF DCP = 9 THEN
    GOSUB BSEQ
    ENDIF
    FOR C = 0 TO 4
    READ TIME DIG C,SEGMENT
    LOOKUP C,[$BF,$7F,$DF,$EF],DIGIT
    IF C = 4 THEN
    PORTB = %11111110
    IF DCP = 1 THEN DIGIT = $EF
    IF DCP = 2 THEN DIGIT = $DF
    IF DCP = 3 THEN DIGIT = $7F
    IF DCP = 4 THEN DIGIT = $BF
    ENDIF
    PAUSEUS f
    PORTB = $FF
    PORTC = $FF
    PAUSEUS F2
    NEXT C
    FOR B = 0 TO 4
    READ AMP DIG B,SEGMENT
    LOOKUP B,[$FE,$FD,$FB,$F7],DIGIT
    IF B = 4 THEN
    PORTB = %11111110
    IF DCP = 5 THEN DIGIT = $FE
    IF DCP = 6 THEN DIGIT = $FD
    IF DCP = 7 THEN DIGIT = $FB
    IF DCP = 8 THEN DIGIT = $F7
    ENDIF
    PAUSEUS f
    PORTB = $FF
    PORTC = $FF
    PAUSEUS F2
    NEXT B
    GOTO LOOP
    BSEQ: FOR A=0 TO 3
    FOR C = 0 TO 6
    READ C+11,SEGMENT
    LOOKUP A,[$EF,$DF,$7F,$BF],DIGIT
    PAUSEUS 1000
    PORTB = $FF
    PORTC = $FF
    PAUSE 10
    NEXT C
    PAUSE 2
    NEXT A
    FOR A=0 TO 3
    FOR B = 6 TO 0 STEP -1
    READ B+11,SEGMENT
    LOOKUP A,[$FE,$FD,$FB,$F7],DIGIT
    PAUSEUS 1000
    PORTB = $FF
    PORTC = $FF
    PAUSE 10
    NEXT B
    PAUSE 2
    NEXT A
    DCP = 1
    RETURN
    Thanks !
    SOMRU
    TWE/TFP/EE

Similar Threads

  1. 2 PIC, serial communication
    By lightgreen in forum Serial
    Replies: 6
    Last Post: - 21st November 2009, 15:20
  2. 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
  3. PIC 2 PIC communication
    By Mario in forum Forum Requests
    Replies: 16
    Last Post: - 28th April 2006, 01:56
  4. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 15:45
  5. Pic to Pic communication?
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th April 2004, 19:41

Members who have read this thread : 2

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