Linking 2 microcontrollers

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.

Reply to
Maurine O.
Loading thread data ...

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

Reply to
Wong

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

Reply to
peterken

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.

Reply to
CBarn24050

microcontrollers

switches

achieve

formatting link

ready,

polls

count,

needs

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

Reply to
moukylove

--- 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

--------------------------------- 0 0 0 0 0 0 X X 1 0 0 1 X 1 0 0 1 0 1 0 0 1 0 0

-- John Fields

Reply to
John Fields

Oops... bclr 3,prta ;else clear prta4 to turn off LED2 ^ 4

Oops... bclr 3,prta ;else clear prta5 to turn off LED2 ^ 5

--
John Fields
Reply to
John Fields

Fair enough, any suggestions.? Like a "Complete Idiot's guide to microprocessor programming". or something like that..suggestions.?

:)

Reply to
Maurine O.

formatting link

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

Reply to
peterken

---

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
Reply to
Maurine O.

--
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.
Reply to
John Fields

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.