Multiprocessor Communication Mode
Multiprocessor Communication Mode
Do Steps 1 to 4 below:
Step 2. Wire this circuit below (for the simulation in Step 3):
In Transmitter Code, interchange receiver address between ‘1’ and ‘2’ to select receiver,
build project and simulate in each case – observe display of transmitter PORTD (PD2 – PD7)
on selected receiver.
//Transmitter Code
/*
* MasterCode.c
*
* Created: 2021/08/09 13:06:03
* Author : SibandaA
*/
//Master code
int main(void)
{
DDRD = 0b00000011;
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 < UCSZ02);
UBRR0L = 103;
while(1)
{
while(!(UCSR0A & (1 << UDRE0))); //wait until UDR0 Empty flag
UCSR0B |= (1<<TXB80); //set 9th bit to send address
UDR0 = '1'; //send address to receivers
while(!(UCSR0A & (1 << UDRE0))); //wait until UDR0 Empty flag is set
UCSR0B &= ~(1<<TXB80); //clear 9thbit to send data
UDR0 = (PIND & 0xFC); //send data
}
return 0;
}
//Receiver 1 Code
/*
* MasterCode.c
*
* Created: 2021/08/09 13:06:03
* Author : SibandaA
*/
//Master code
int main(void)
{
DDRD = 0xFF;
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << UCSZ02);
UCSR0A |= (1 << MPCM0);
UBRR0L = 103;
unsigned ch;
PORTD = 0x00; //Turn OFF PORTD
while(1)
{
while(!(UCSR0A & (1 << RXC0))); //wait until character is received
ch = UDR0;
if(ch == '1') //if Receiver 1 address
{
UCSR0A &= ~(1 << MPCM0); //clear MPC mode on Receiver 1
while(!(UCSR0A & (1 << RXC0))); //wait until data is received
PORTD = UDR0; //display received data on PORTD
}
}
return 0;
}
//Receiver 2 Code
/*
* MasterCode.c
*
* Created: 2021/08/09 13:06:03
* Author : SibandaA
*/
//Master code
int main(void)
{
DDRD = 0xFF;
UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << UCSZ02);
UCSR0A |= (1 << MPCM0);
UBRR0L = 103;
unsigned ch;
PORTD = 0x00; //Turn OFF PORTD
while(1)
{
while(!(UCSR0A & (1 << RXC0))); //wait until character is received
ch = UDR0;
if(ch == '2') //if Receiver 2 address
{
UCSR0A &= ~(1 << MPCM0); //clear MPC mode on Receiver 2
while(!(UCSR0A & (1 << RXC0))); //wait until data is received
PORTD = UDR0; //display received data on PORTD
}
}
return 0;
}