Connect with us

Linking 2 microcontrollers

Discussion in 'Electronic Basics' started by Maurine O., Dec 1, 2004.

Scroll to continue with content
  1. Maurine O.

    Maurine O. Guest

    Hi there, iam new to microcontrollers and need to link 2
    microcontrollers (Philips 89C668, 80C51: 8 Bit family) such that when
    a Switch on a breadboard (connected to the first microcontroller) is
    pressed, a corresponding LED (On a breadboard connected to the second
    microcontroller)Lights accordingly. i currenly have three sets of
    switches (On breadboard 1) and three LEDs (On breadboard 2).....a code
    to achieve the above task would be appreciated.....Thanks.
     
  2. peterken

    peterken Guest

    Using dual-port ram might be a good idea, using part of it as "mailbox"
    between both so data might be exchanged.
    In this mailbox a flag might be set/cleared whereby the master informs the
    slave it can take over.
    If using tri-state tranceivers then you might even connect busses, however
    take care one of them releases the common bus before the other takes over
     
  3. CBarn24050

    CBarn24050 Guest

    Subject: Linking 2 microcontrollers
    I not familiar with this part, I assume it has a uart. connect the tx of 1 to
    the rx of the other. Its trvial code to make it work after that.
     
  4. Wong

    Wong Guest

    I think that a trigger/interrupt may works as well.
     
  5. Rich Grise

    Rich Grise Guest

    Just use port pins and work out some kind of communications protocol.

    Hell, use twelve pins - you've got 32 to work with.
    At least according to the diagram at
    http://www.semiconductors.philips.com/acrobat_download/datasheets/P89C660_662_664_668_4.pdf
    page 5 has a pretty good block diagram.

    Use port 1, uC # A to output the button pattern.
    Use port 2, uC # A to tell uC #B that data is ready.
    On uC B, be sitting polling port 2. When it says port 1 data is ready,
    read it in from port one.
    Use port 3, uC #B to tell uC #A that data has been accepted.
    After uC #A has sent it's "Ready" signal on port 2, it waits and polls
    port 3 until uC #B says, "Got it!"

    With a little imagination, you could dramatically reduce the pin count,
    but the purpose of the design is just to find out where the teacher needs
    to start with the basics, right?

    Hope This Helps!
    Rich
     
  6. Guest




    Well the problem is the communications protocol, at the moment i can
    only read in a switch value After Moving some number to the Accumulator
    something like "MOV A, 07H", and masking any unused Bits. but from
    there i get stucked...a code to read in all three switches and enable
    them light their corresponding LEDs would be appreciated...Thanks
     
  7. Rich Grise

    Rich Grise Guest

    [nice treatise about interprocessor communications snipped]
    What you're talking about isn't a communications protocol at all, it's
    low-level programming.

    If you don't know how to move the data from a port to A, then I'm afraid
    my help will be useless until you've at least completed lesson 1 of
    microprocessor programming.

    Good Luck!
    Rich
     
  8. John Fields

    John Fields Guest

    ---
    The hardware, all switches SPSTNO:

    Vcc>------+-----+-----+
    | | |
    [10K] [10K] [10K]
    S3___ | | |
    +---O O--+ | |
    | S2___ | | |
    +---O O--------+ |
    | S1___ | | |
    +---O O--------------+
    | | | |
    GND +--+-----+-----+--+
    |PRTA2 PRTA1 PRTA0|
    | | TX
    |PRTA5 PRTA4 PRTA3| MC68XX
    +--+-----+-----+--+
    | | |
    . . .
    . . .
    . . .
    . . .
    . . . Vcc
    . . . |
    | | | +------+------+
    +--+-----+-----+--+ | | |
    |PRTA2 PRTA1 PRTA0| [150] [150] [150]
    | | RX |A |A |A
    |PRTA5 PRTA4 PRTA3| MC68XX [LED1] [LED2] [LED3]
    +--+-----+-----+--+ | | |
    | | | C | |
    | | +-------[2200]---B NPN | |
    | | E C |
    | +-------------[2200]----|-----B NPN |
    | | E C
    +-------------------[2200]----|------|-----B NPN
    | | E
    | | |
    +------+------+
    |
    GND


    One example of code in Motorola (Freescale) 6800 assembler for the
    transmitter:


    start: lda #$f8 ;1111 1000
    sta ddra ;set up the port a ddr
    lda #$07 ;0000 0111
    sta prta ;set up port a

    loopa: jsr t100ms ;100ms timer
    brclr 0,prta on1 ;branch if S1 is made
    bclr 3,prta ;else clear port a bit 3 (prta3)
    brclr 1,prta on2 ;branch if S2 is made
    bclr 4,prta ;else clear prta4
    brclr 2,prta on3 ;branch if S3 is made
    bclr 5,prta ;else clear prta5
    bra loopa ;loop back for another try

    on1: bset 3,prta ;set prta3
    bra loopa ;loop back for another try

    on2: bset 4,prta ;set prta4
    bra loopa ;loop back for another try

    on3: bset 5,prta ;set prta5
    bra loopa ;loop back for another try

    t100ms: code for timer ;generate 100 millisecond delay
    rts ;return



    And for the receiver:

    start: lda #$f8 ;1111 1000
    sta ddra ;set up the port a ddr
    clr prta ;set up port a

    loopa: brset 0,prta on1 ;branch if prta0 is set
    bclr 3,prta ;else clear prta3 to turn off LED1
    brset 1,prta on2 ;branch if prta1 is set
    bclr 3,prta ;else clear prta4 to turn off LED2
    brset 2,prta on3 ;branch if prta2 is set
    bclr 3,prta ;else clear prta5 to turn off LED2
    bra loopa ;loop back for another try

    on1: bset 3,prta ;set prta3 to turn on LED1
    bra loopa ;loop back for another try

    on2: bset 4,prta ;set prta4 to turn on LED2
    bra loopa ;loop back for another try

    on3: bset 5,prta ;set prta5 to turn on LED3
    bra loopa ;loop back for another try


    This code will only allow one LED at a time to be lit, and that LED
    will correspond to:


    S3 S2 S1 LED3 LED2 LED1
     
  9. John Fields

    John Fields Guest

    Oops... bclr 3,prta ;else clear prta4 to turn off LED2
    ^
    4
    Oops... bclr 3,prta ;else clear prta5 to turn off LED2
    ^
    5
     
  10. Maurine O.

    Maurine O. Guest

    What you're talking about isn't a communications protocol at all, it's
    Fair enough, any suggestions.? Like a "Complete Idiot's guide to
    microprocessor programming". or something like that..suggestions.?

    :)
     
  11. peterken

    peterken Guest

    try a high level programming language (C, C++, pascal, even things like
    basic....)
    and the datasheet of the processor of course to know at what addresses the
    ports are located
     
  12. Maurine O.

    Maurine O. Guest

    ---
    Thanks John that was Brilliant!!, but do you have a proper schematic
    (May be in Jpeg,gif or .doc), email it to the address above its still
    active.....thanks alot that was really helpful.

    M
     
  13. John Fields

    John Fields Guest

    ---
    You're welcome :)

    Sorry, I don't have a "proper" schematic, but if you'll post what you
    don't understand about the one above, either I'll explain it to you or
    someone else will if they get to it first.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-