User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
411
URXISEL1_U2STA_bit = 0; // 0x = Interrupt ag bit is set when a character is
received
U2RXIF_bit = 0; // ensure interrupt not pending
MVEC_bit = 1; // Interrupt controller congured for multi vectored mode
asm ei R0; // Enable all interrupts
U2RXIE_bit = 1; // enable intterupt
RS485Master_Send(dat,1,160);
while (1){
// upon completed valid message receiving
// data[4] is set to 255
cnt++;
if (dat[5]) { // if an error detected, signal it
PORTD = 0xAA; // by setting portd to 0xAA
}
if (dat[4]) { // if message received successfully
cnt = 0;
dat[4] = 0; // clear message received ag
j = dat[3];
for (i = 1; i <= dat[3]; i++) { // show data on PORTB
PORTB = dat[i-1];
} // increment received dat[0]
dat[0] = dat[0]+1; // send back to master
Delay_ms(1);
RS485Master_Send(dat,1,160);
}
if (cnt > 100000) {
PORTD ++;
cnt = 0;
RS485Master_Send(dat,1,160);
if (PORTD > 10) // if sending failed 10 times
RS485Master_Send(dat,1,50); // send message on broadcast address
}
}
}
RS485 Slave code:
Copy Code To Clipboard
char dat[9]; // buffer for receving/sending messages
char i, j;
sbit RS485_rxtx_pin at RF2_bit; // set transcieve pin
sbit RS485_rxtx_pin_direction at TRISF2_bit; // set transcieve pin direction
// Interrupt routine
void interrupt() iv IVT_UART_2 ilevel 7 ics ICS_SRS {